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 int auth_userdb_pre_common(const char *userid
, const char *service
,
26 int (*callback
)(struct authinfo
*, void *),
37 userdb_set_debug(courier_authdebug_login_level
);
38 userdb_init(USERDB
".dat");
39 /* We rely on DPRINTF doing 'safe' printing */
40 DPRINTF("userdb: looking up '%s'", userid
);
41 if ( (u
=userdb(userid
)) == 0)
48 if ((udb
=userdb_creates(u
)) == 0)
55 memset(&auth
, 0, sizeof(auth
));
57 auth
.sysuserid
= &udb
->udb_uid
;
58 auth
.sysgroupid
=udb
->udb_gid
;
59 auth
.homedir
=udb
->udb_dir
;
61 auth
.fullname
=udb
->udb_gecos
;
62 auth
.options
=udb
->udb_options
;
66 udbs
=userdbshadow(USERDB
"shadow.dat", userid
);
70 if ((services
=malloc(strlen(service
)+sizeof("pw"))) == 0)
78 strcat(strcpy(services
, service
), "pw");
80 passwords
=userdb_gets(udbs
, services
);
84 DPRINTF("found %s in userdbshadow", services
);
88 passwords
=userdb_gets(udbs
, "systempw");
91 DPRINTF("found systempw in userdbshadow");
95 DPRINTF("no %s or systempw value in userdbshadow for %s",
103 auth
.passwd
=passwords
;
106 auth
.maildir
=udb
->udb_mailbox
;
107 auth
.quota
=udb
->udb_quota
;
109 courier_authdebug_authinfo("DEBUG: authuserdb: ", &auth
, 0, passwords
);
110 rc
= (*callback
)(&auth
, arg
);
111 if (passwords
) free(passwords
);
116 void auth_userdb_cleanup()
121 void auth_userdb_enumerate( void(*cb_func
)(const char *name
,
132 userdb_init(USERDB
".dat");
134 for (u
=userdb_enum_first(); u
; u
=userdb_enum_next())
136 (*cb_func
)(u
->udb_name
,
145 (*cb_func
)(NULL
, 0, 0, NULL
, NULL
, NULL
, void_arg
);