2 ** Copyright 2000-2008 Double Precision, Inc. See COPYING for
3 ** distribution information.
7 #include "courierauthstaticlist.h"
8 #include "courierauthsasl.h"
10 #include "courierauthdebug.h"
18 #include <sys/select.h>
19 #include "numlib/numlib.h"
22 extern int authdaemondo(const char *authreq
,
23 int (*func
)(struct authinfo
*, void *), void *arg
);
25 extern void auth_daemon_enumerate( void(*cb_func
)(const char *name
,
35 int auth_generic(const char *service
,
38 int (*callback_func
)(struct authinfo
*, void *),
41 char tbuf
[NUMBUFSIZE
];
42 size_t l
=strlen(service
)+strlen(authtype
)+strlen(authdata
)+2;
43 char *n
=libmail_str_size_t(l
, tbuf
);
44 char *buf
=malloc(strlen(n
)+l
+20);
47 courier_authdebug_login_init();
52 strcat(strcat(strcpy(buf
, "AUTH "), n
), "\n");
53 strcat(strcat(buf
, service
), "\n");
54 strcat(strcat(buf
, authtype
), "\n");
55 strcat(buf
, authdata
);
57 rc
=strcmp(authtype
, "EXTERNAL") == 0
58 ? auth_getuserinfo(service
, authdata
, callback_func
,
60 : authdaemondo(buf
, callback_func
, callback_arg
);
63 if (courier_authdebug_login_level
)
67 /* short delay to try and allow authdaemond's courierlogger
68 to finish writing; otherwise items can appear out of order */
71 select(0, 0, 0, 0, &t
);
77 int auth_callback_default(struct authinfo
*ainfo
)
79 if (ainfo
->address
== NULL
)
81 fprintf(stderr
, "WARN: No address!!\n");
85 if (ainfo
->sysusername
)
86 libmail_changeusername(ainfo
->sysusername
,
88 else if (ainfo
->sysuserid
)
89 libmail_changeuidgid(*ainfo
->sysuserid
,
93 fprintf(stderr
, "WARN: %s: No UID/GID!!\n", ainfo
->address
);
100 fprintf(stderr
, "WARN: %s: No homedir!!\n", ainfo
->address
);
104 if (chdir(ainfo
->homedir
))
106 fprintf(stderr
, "WARN: %s: chdir(%s) failed!!\n",
107 ainfo
->address
, ainfo
->homedir
);
108 perror("WARN: error");