1#define LDAP_DEPRECATE 1
25#define WHO "qmail-ldapam"
27#define LDAP_SCOPE LDAP_SCOPE_SUBTREE
29#define MAIL_ACCOUNT_NAME "mail"
30#define MAIL_ACCOUNT_UID 8
31#define MAIL_ACCOUNT_GID 12
67 logmsg(
WHO,110,FATAL,
"out of memory");
84 logmsg(
WHO,111,ERROR,
"unable to read password");
90static int ldap_lookup(
char *
host,
int port,
char *
user,
char *pwd)
92 char *attrs[] = { NULL };
95 LDAPMessage *res, *entry;
98 if ((ld = ldap_init(
host,
port)) == 0)
99 logmsg(
WHO,110,ERROR,
"Unable to initialise LDAP connection");
106 if (r) logmsg(
WHO,110,ERROR,
"can't bind with LDAP server");
109 if (r) logmsg(
WHO,1,ERROR,B(
"search failed:",ldap_err2string(r)));
111 entry = ldap_first_entry(ld,res);
112 if (!entry)
return 1;
114 dn = ldap_get_dn(ld,res);
116 r = ldap_simple_bind_s(ld,dn,pwd);
125static int ldap_userhome(
char *
host,
int port,
char *
user,
char *pwd,
char *
mbox)
127 char *attrs[] = { NULL };
130 LDAPMessage *res, *entry;
133 if ((ld = ldap_init(
host,
port) == 0))
134 logmsg(
WHO,110,ERROR,
"Unable to setup connection");
137 if (r) logmsg(
WHO,110,ERROR,
"can't bind to LDAP server");
140 if (r) logmsg(
WHO,1,ERROR,B(
"search failed: ",ldap_err2string(r)));
142 entry = ldap_first_entry(ld,res);
143 if (!entry)
return 1;
145 values = ldap_get_values(ld,entry,
mbox);
146 if (values && values[0]) {
158static stralloc
cafile = {0};
159static stralloc
cadir = {0};
162static stralloc certpwd = {0};
164int main (
int argc,
char **argv)
177 int f,
h,
j,
k,
p,
c, r, t, w;
180 if (!argv[1]) logmsg(
WHO,100,USAGE,
" [-d|-m] prog");
181 if (!case_diffs(argv[1],
FLAG_DIR)) {
182 if (!argv[2]) logmsg(
WHO,100,USAGE,
" [-d|-m] prog");
186 if (!argv[2]) logmsg(
WHO,100,USAGE,
" [-d|-m] prog");
194 while ((rc == -1) && (errno == EINTR));
195 if (r == -1)
exit(111);
203 if (i == buflen)
exit(2);
205 if (i == buflen)
exit(2);
207 if (i == buflen)
exit(2);
209 authlen = str_len(authuser);
212 if ((i = byte_rchr(authuser,authlen,
'@')))
213 if (i < authlen && authuser[i] ==
'@') {
216 case_lowerb(
domain,domlen);
245 if (!ldaparam && domlen)
250 if (!ldaparam)
exit(1);
258 i = str_chr(ldaparam,
'|');
259 if (ldaparam[i] ==
'|') {
262 j = str_chr(ldaparam + i,
'|');
263 if (ldaparam[i +
j + 1] ==
'|') {
264 ldaparam[i +
j + 1] = 0;
266 k = str_chr(ldaparam + i +
j + 2,
'|');
267 if (ldaparam[i +
j +
k + 2] ==
'|') {
268 ldaparam[i +
j +
k + 2] = 0;
271 p = str_chr(ldaparam + i +
j +
k + 3,
';');
272 if (ldaparam[i +
j +
k +
p + 3] ==
';') {
273 ldaparam[i +
j +
k +
p + 2] = 0;
274 if (
p > 0) scan_ulong(ldaparam + i +
j +
k +
p + 4,&
port);
277 t = str_chr(ldaparam + i +
j +
k + 3,
'|');
278 if (ldaparam[i +
j +
k + t + 3] ==
'|') {
279 ldaparam[i +
j +
k + t + 3] = 0;
280 if (ldaparam[i +
j +
k + t + 2] ==
'/') {
288 w = str_chr(ldaparam + i +
j +
k + t + 4,
':');
289 if (ldaparam[i +
j +
k + t + w + 4] ==
':') {
290 ldaparam[i +
j +
k + t + w + 4] = 0;
293 f = str_chr(ldaparam + i +
j +
k + t + w + 5,
':');
294 if (ldaparam[i +
j +
k + t + w + 4] ==
'|') {
295 ldaparam[i +
j +
k + t + w + 4] = 0;
298 h = str_chr(ldaparam + i +
j +
k + 3,
'|');
299 if (ldaparam[i +
j +
k +
h + 3] ==
'|') {
300 ldaparam[i +
j +
k + t + 3] = 0;
332 if (!str_diff(
bindpw.s,
"*")) {
335 for (i = 0; i <
bindpwds.len; i++) {
340 if (!ldap_lookup(
host,
port,authuser,password))
break;
345 logmsg(
WHO,110,ERROR,B(
"can't bind to LDAP host: ",
host));
347 if (ldap_lookup(
host,
port,authuser,password))
348 logmsg(
WHO,110,ERROR,B(
"can't bind to LDAP host: ",
host));
356 logmsg(
WHO,107,ERROR,B(
"Unable to set supplementary groups: ",strerror(errno)));
358 logmsg(
WHO,106,ERROR,B(
"Unable to set gid: ",strerror(errno)));
360 logmsg(
WHO,105,ERROR,B(
"Unable to set uid: ",strerror(errno)));
362 logmsg(
WHO,108,ERROR,B(
"Unable to change to home dir: ",
homeparam.s,strerror(errno)));
367 if (flaghome || flagmail) pathexec(argv + 2);
368 else pathexec(argv + 1);
int constmap_init(struct constmap *cm, char *s, int len, int flagcolon)
int control_readfile(stralloc *sa, char *fn, int flagme)
int stralloc_copys(stralloc *, char const *)
void h(char *, char *, int, int, int)
void c(char *, char *, char *, int, int, int)
void p(char *, char *, int, int, int)
char authbuf[BUFSIZE_AUTH]
struct constmap mapldapauth
#define MAIL_ACCOUNT_NAME