2 ** Copyright 1998 - 1999 Double Precision, Inc. See COPYING for
3 ** distribution information.
7 #include "courier_auth_config.h"
19 #include "courierauthdebug.h"
20 #include "userdb/userdb.h"
23 #define TOKEN_CMD "/etc/courier/get-token "
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 */
111 { char uidstr
[32] = "<null>";
115 snprintf(uidstr
, sizeof(uidstr
), "%ld", (long)*auth
.sysuserid
);
116 if ((token_cmd
=malloc(sizeof(TOKEN_CMD
)+strlen(uidstr
))))
118 strcat(strcpy(token_cmd
, TOKEN_CMD
),uidstr
);
125 courier_authdebug_authinfo("DEBUG: authuserdb: ", &auth
, 0, passwords
);
126 rc
= (*callback
)(&auth
, arg
);
127 if (passwords
) free(passwords
);
132 void auth_userdb_cleanup()
137 void auth_userdb_enumerate( void(*cb_func
)(const char *name
,
148 userdb_init(USERDB
".dat");
150 for (u
=userdb_enum_first(); u
; u
=userdb_enum_next())
152 (*cb_func
)(u
->udb_name
,
161 (*cb_func
)(NULL
, 0, 0, NULL
, NULL
, NULL
, void_arg
);