2 ** Copyright 2000-2008 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.18 2008/06/29 16:39:24 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
=strcmp(authtype
, "EXTERNAL") == 0
59 ? auth_getuserinfo(service
, authdata
, callback_func
,
61 : authdaemondo(buf
, callback_func
, callback_arg
);
64 if (courier_authdebug_login_level
)
68 /* short delay to try and allow authdaemond's courierlogger
69 to finish writing; otherwise items can appear out of order */
72 select(0, 0, 0, 0, &t
);
78 int auth_callback_default(struct authinfo
*ainfo
)
80 if (ainfo
->address
== NULL
)
82 fprintf(stderr
, "WARN: No address!!\n");
86 if (ainfo
->sysusername
)
87 libmail_changeusername(ainfo
->sysusername
,
89 else if (ainfo
->sysuserid
)
90 libmail_changeuidgid(*ainfo
->sysuserid
,
94 fprintf(stderr
, "WARN: %s: No UID/GID!!\n", ainfo
->address
);
101 fprintf(stderr
, "WARN: %s: No homedir!!\n", ainfo
->address
);
105 if (chdir(ainfo
->homedir
))
107 fprintf(stderr
, "WARN: %s: chdir(%s) failed!!\n",
108 ainfo
->address
, ainfo
->homedir
);
109 perror("WARN: error");