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"
22 static const char rcsid
[]="$Id: preauthuserdbcommon.c,v 1.21 2006/10/28 19:22:52 mrsam Exp $";
24 #define TOKEN_CMD "/etc/courier/get-token "
26 int auth_userdb_pre_common(const char *userid
, const char *service
,
28 int (*callback
)(struct authinfo
*, void *),
39 userdb_set_debug(courier_authdebug_login_level
);
40 userdb_init(USERDB
".dat");
41 /* We rely on DPRINTF doing 'safe' printing */
42 DPRINTF("userdb: looking up '%s'", userid
);
43 if ( (u
=userdb(userid
)) == 0)
50 if ((udb
=userdb_creates(u
)) == 0)
57 memset(&auth
, 0, sizeof(auth
));
59 auth
.sysuserid
= &udb
->udb_uid
;
60 auth
.sysgroupid
=udb
->udb_gid
;
61 auth
.homedir
=udb
->udb_dir
;
63 auth
.fullname
=udb
->udb_gecos
;
64 auth
.options
=udb
->udb_options
;
68 udbs
=userdbshadow(USERDB
"shadow.dat", userid
);
72 if ((services
=malloc(strlen(service
)+sizeof("pw"))) == 0)
80 strcat(strcpy(services
, service
), "pw");
82 passwords
=userdb_gets(udbs
, services
);
86 DPRINTF("found %s in userdbshadow", services
);
90 passwords
=userdb_gets(udbs
, "systempw");
93 DPRINTF("found systempw in userdbshadow");
97 DPRINTF("no %s or systempw value in userdbshadow for %s",
105 auth
.passwd
=passwords
;
108 auth
.maildir
=udb
->udb_mailbox
;
109 auth
.quota
=udb
->udb_quota
;
111 /* Get tokens for AFS */
112 { char uidstr
[32] = "<null>";
116 snprintf(uidstr
, sizeof(uidstr
), "%ld", (long)*auth
.sysuserid
);
117 if ((token_cmd
=malloc(sizeof(TOKEN_CMD
)+strlen(uidstr
))))
119 strcat(strcpy(token_cmd
, TOKEN_CMD
),uidstr
);
126 courier_authdebug_authinfo("DEBUG: authuserdb: ", &auth
, 0, passwords
);
127 rc
= (*callback
)(&auth
, arg
);
128 if (passwords
) free(passwords
);
133 void auth_userdb_cleanup()
138 void auth_userdb_enumerate( void(*cb_func
)(const char *name
,
149 userdb_init(USERDB
".dat");
151 for (u
=userdb_enum_first(); u
; u
=userdb_enum_next())
153 (*cb_func
)(u
->udb_name
,
162 (*cb_func
)(NULL
, 0, 0, NULL
, NULL
, NULL
, void_arg
);