2 ** Copyright 2000-2005 Double Precision, Inc. See COPYING for
3 ** distribution information.
7 #include "authstaticlist.h"
8 #include "courierauthsasl.h"
10 #include "courierauthdebug.h"
18 #include <sys/select.h>
19 #include "numlib/numlib.h"
21 static const char rcsid
[]="$Id: authdaemon.c,v 1.17 2005/06/30 16:16:07 mrsam Exp $";
23 extern int authdaemondo(const char *authreq
,
24 int (*func
)(struct authinfo
*, void *), void *arg
);
26 extern void auth_daemon_enumerate( void(*cb_func
)(const char *name
,
36 int auth_generic(const char *service
,
39 int (*callback_func
)(struct authinfo
*, void *),
42 char tbuf
[NUMBUFSIZE
];
43 size_t l
=strlen(service
)+strlen(authtype
)+strlen(authdata
)+2;
44 char *n
=libmail_str_size_t(l
, tbuf
);
45 char *buf
=malloc(strlen(n
)+l
+20);
48 courier_authdebug_login_init();
53 strcat(strcat(strcpy(buf
, "AUTH "), n
), "\n");
54 strcat(strcat(buf
, service
), "\n");
55 strcat(strcat(buf
, authtype
), "\n");
56 strcat(buf
, authdata
);
58 rc
=authdaemondo(buf
, callback_func
, callback_arg
);
61 if (courier_authdebug_login_level
)
65 /* short delay to try and allow authdaemond's courierlogger
66 to finish writing; otherwise items can appear out of order */
69 select(0, 0, 0, 0, &t
);
75 int auth_callback_default(struct authinfo
*ainfo
)
77 if (ainfo
->address
== NULL
)
79 fprintf(stderr
, "WARN: No address!!\n");
83 if (ainfo
->sysusername
)
84 libmail_changeusername(ainfo
->sysusername
,
86 else if (ainfo
->sysuserid
)
87 libmail_changeuidgid(*ainfo
->sysuserid
,
91 fprintf(stderr
, "WARN: %s: No UID/GID!!\n", ainfo
->address
);
98 fprintf(stderr
, "WARN: %s: No homedir!!\n", ainfo
->address
);
102 if (chdir(ainfo
->homedir
))
104 fprintf(stderr
, "WARN: %s: chdir(%s) failed!!\n",
105 ainfo
->address
, ainfo
->homedir
);
106 perror("WARN: error");