2 ** Copyright 1998 - 1999 Double Precision, Inc. See COPYING for
3 ** distribution information.
7 #include "courier_auth_config.h"
17 #include <sys/types.h>
21 #include "courierauthdebug.h"
22 #include "userdb/userdb.h"
23 #include "numlib/numlib.h"
25 int auth_userdb_pre_common(const char *userid
, const char *service
,
27 int (*callback
)(struct authinfo
*, void *),
38 userdb_set_debug(courier_authdebug_login_level
);
39 userdb_init(USERDB
".dat");
40 /* We rely on DPRINTF doing 'safe' printing */
41 DPRINTF("userdb: looking up '%s'", userid
);
42 if ( (u
=userdb(userid
)) == 0)
49 if ((udb
=userdb_creates(u
)) == 0)
56 memset(&auth
, 0, sizeof(auth
));
58 auth
.sysuserid
= &udb
->udb_uid
;
59 auth
.sysgroupid
=udb
->udb_gid
;
60 auth
.homedir
=udb
->udb_dir
;
62 auth
.fullname
=udb
->udb_gecos
;
63 auth
.options
=udb
->udb_options
;
67 udbs
=userdbshadow(USERDB
"shadow.dat", userid
);
71 if ((services
=malloc(strlen(service
)+sizeof("pw"))) == 0)
79 strcat(strcpy(services
, service
), "pw");
81 passwords
=userdb_gets(udbs
, services
);
85 DPRINTF("found %s in userdbshadow", services
);
89 passwords
=userdb_gets(udbs
, "systempw");
92 DPRINTF("found systempw in userdbshadow");
96 DPRINTF("no %s or systempw value in userdbshadow for %s",
104 auth
.passwd
=passwords
;
107 auth
.maildir
=udb
->udb_mailbox
;
108 auth
.quota
=udb
->udb_quota
;
110 /* Get tokens for AFS */
118 char uidstr
[32] = "<null>";
119 snprintf(uidstr
, sizeof(uidstr
), "%ld", (long)*auth
.sysuserid
);
121 libmail_changeuidgid (*auth
.sysuserid
, auth
.sysgroupid
);
122 execl ("/etc/courier/get-token", "get-token", uidstr
, NULL
);
126 waitpid (pid
, NULL
, 0);
131 courier_authdebug_authinfo("DEBUG: authuserdb: ", &auth
, 0, passwords
);
132 rc
= (*callback
)(&auth
, arg
);
133 if (passwords
) free(passwords
);
138 void auth_userdb_cleanup()
143 void auth_userdb_enumerate( void(*cb_func
)(const char *name
,
154 userdb_init(USERDB
".dat");
156 for (u
=userdb_enum_first(); u
; u
=userdb_enum_next())
158 (*cb_func
)(u
->udb_name
,
167 (*cb_func
)(NULL
, 0, 0, NULL
, NULL
, NULL
, void_arg
);