s/qmail 4.2.29a
Next generation secure email transport
Loading...
Searching...
No Matches
qmail-vmailuser.c
Go to the documentation of this file.
1#include <sys/types.h>
2#include <sys/stat.h>
3#include <unistd.h>
4#include "global.h"
5#include "auto_qmail.h"
6#include "stralloc.h"
7#include "case.h"
8#include "control.h"
9#include "constmap.h"
10#include "direntry.h"
11#include "error.h"
12#include "str.h"
13#include "fmt.h"
14#include "open.h"
15#include "byte.h"
16#include "scan.h"
17#include "str.h"
18
19#define FDAUTH 3
20#define RESPECT_CASE "-C"
21#define BUFFER_SIZE 128
22
33stralloc vdoms = {0};
34stralloc vdomdir = {0};
35stralloc vuser = {0};
36stralloc vuserdir = {0};
37
38void pam_exit(int fail)
39{
40 int i;
41
42 close(FDAUTH);
43 for (i = 0; i < sizeof(inputbuf); ++i) inputbuf[i] = 0;
44 _exit(fail);
45}
46
47int main(int argc,char **argv)
48{
49 DIR *dir;
50 char *vdomuser;
51 char *domain = 0;
52 int buflen = 0;
53 int domlen = 0;
54 int flagrespect = 0;
55 int i, r;
56 char ch;
57 char *homedir = "/home";
58
59 if (argv[1])
60 if (!case_diffs(argv[1],RESPECT_CASE)) {
61 flagrespect = 1;
62 } else {
63 homedir = argv[1];
64 dir = opendir(homedir);
65 if (!dir) pam_exit(2);
66 }
67
68 if (argv[2])
69 if (!case_diffs(argv[2],RESPECT_CASE)) flagrespect = 1;
70
71 if (chdir(auto_qmail) == -1) pam_exit(110);
72
73 switch (control_readfile(&vdoms,"control/virtualdomains",0)) {
74 case -1: pam_exit(110);
75 case 0: if (!constmap_init(&mapvdoms,"",0,1)) pam_exit(111);
76 case 1: if (!constmap_init(&mapvdoms,vdoms.s,vdoms.len,1)) pam_exit(111);
77 }
78
79 for (;;) { /* read input */
80 do
81 r = read(FDAUTH,inputbuf + buflen,sizeof(inputbuf) - buflen);
82 while ((r == -1) && (errno == EINTR));
83 if (r == -1) pam_exit(111);
84 if (r == 0) break;
85 buflen += r;
86 if (buflen >= sizeof(inputbuf)) pam_exit(2);
87 }
88 close(FDAUTH);
89
90 if ((r = byte_rchr(inputbuf,buflen,'@'))) /* @domain */
91 if (r < buflen && inputbuf[r] == '@') {
92 domain = inputbuf + r + 1;
93 domlen = str_len(domain);
94 if (!flagrespect)
95 case_lowerb(inputbuf,buflen);
96 else
97 case_lowerb(domain,domlen);
98 }
99 vdomuser = constmap(&mapvdoms,domain,domlen);
100 if (!vdomuser) pam_exit(1);
101
102 if (!stralloc_copys(&vuser,"")) pam_exit(111); /* user */
103 for (i = 0; i < r; ++i) {
104 ch = inputbuf[i];
105 if (ch == '.') ch = ':';
106 if (!stralloc_append(&vuser,&ch)) pam_exit(111);
107 }
108 if (!stralloc_0(&vuser)) pam_exit(111);
109
110 if (!stralloc_copys(&vdomdir,homedir)) pam_exit(111); /* vpopmail */
111 if (!stralloc_cats(&vdomdir,"/")) pam_exit(111);
112 if (!stralloc_cats(&vdomdir,"vpopmail")) pam_exit(111);
113 if (!stralloc_copy(&vuserdir,&vdomdir)) pam_exit(111);
114 if (!stralloc_cats(&vuserdir,"/domains/")) pam_exit(111);
115 if (!stralloc_cats(&vuserdir,vdomuser)) pam_exit(111);
116 if (!stralloc_copy(&vdomdir,&vuserdir)) pam_exit(111);
117 if (!stralloc_0(&vdomdir)) pam_exit(111);
118
119 dir = opendir(vdomdir.s);
120 if (dir) {
121 if (!stralloc_cats(&vuserdir,"/")) pam_exit(111);
122 if (!stralloc_cat(&vuserdir,&vuser)) pam_exit(111);
123 if (!stralloc_0(&vuserdir)) pam_exit(111);
124
125 dir = opendir(vuserdir.s);
126 if (dir) pam_exit(0);
127 }
128
129 if (!stralloc_copys(&vdomdir,homedir)) pam_exit(111); /* vmailmgr */
130 if (!stralloc_cats(&vdomdir,"/")) pam_exit(111);
131 if (!stralloc_copy(&vuserdir,&vdomdir)) pam_exit(111);
132 if (!stralloc_cats(&vuserdir,vdomuser)) pam_exit(111);
133 if (!stralloc_cats(&vuserdir,"/users")) pam_exit(111);
134 if (!stralloc_copy(&vdomdir,&vuserdir)) pam_exit(111);
135 if (!stralloc_0(&vdomdir)) pam_exit(111);
136
137 dir = opendir(vdomdir.s);
138 if (dir) {
139 if (!stralloc_cats(&vuserdir,"/")) pam_exit(111);
140 if (!stralloc_cat(&vuserdir,&vuser)) pam_exit(111);
141 if (!stralloc_0(&vuserdir)) pam_exit(111);
142
143 dir = opendir(vuserdir.s);
144 if (dir) pam_exit(0);
145 }
146
147 pam_exit(1);
148}
char auto_qmail[]
int main()
Definition: chkshsgr.c:6
int constmap_init(struct constmap *cm, char *s, int len, int flagcolon)
Definition: constmap.c:35
int control_readfile(stralloc *sa, char *fn, int flagme)
Definition: control.c:86
int stralloc_copys(stralloc *, char const *)
void _exit()
stralloc homedir
stralloc vdomdir
stralloc vdoms
stralloc vuser
void pam_exit(int fail)
#define BUFFER_SIZE
stralloc vuserdir
#define FDAUTH
#define RESPECT_CASE
char inputbuf[BUFFER_SIZE]
struct constmap mapvdoms
stralloc domain
Definition: spf.c:34