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 int auth_userdb_pre_common(const char *userid
, const char *service
,
25 int (*callback
)(struct authinfo
*, void *),
36 userdb_set_debug(courier_authdebug_login_level
);
37 userdb_init(USERDB
".dat");
38 /* We rely on DPRINTF doing 'safe' printing */
39 DPRINTF("userdb: looking up '%s'", userid
);
40 if ( (u
=userdb(userid
)) == 0)
47 if ((udb
=userdb_creates(u
)) == 0)
54 memset(&auth
, 0, sizeof(auth
));
56 auth
.sysuserid
= &udb
->udb_uid
;
57 auth
.sysgroupid
=udb
->udb_gid
;
58 auth
.homedir
=udb
->udb_dir
;
60 auth
.fullname
=udb
->udb_gecos
;
61 auth
.options
=udb
->udb_options
;
65 udbs
=userdbshadow(USERDB
"shadow.dat", userid
);
69 if ((services
=malloc(strlen(service
)+sizeof("pw"))) == 0)
77 strcat(strcpy(services
, service
), "pw");
79 passwords
=userdb_gets(udbs
, services
);
83 DPRINTF("found %s in userdbshadow", services
);
87 passwords
=userdb_gets(udbs
, "systempw");
90 DPRINTF("found systempw in userdbshadow");
94 DPRINTF("no %s or systempw value in userdbshadow for %s",
102 auth
.passwd
=passwords
;
105 auth
.maildir
=udb
->udb_mailbox
;
106 auth
.quota
=udb
->udb_quota
;
108 courier_authdebug_authinfo("DEBUG: authuserdb: ", &auth
, 0, passwords
);
109 rc
= (*callback
)(&auth
, arg
);
110 if (passwords
) free(passwords
);
115 void auth_userdb_cleanup()
120 void auth_userdb_enumerate( void(*cb_func
)(const char *name
,
131 userdb_init(USERDB
".dat");
133 for (u
=userdb_enum_first(); u
; u
=userdb_enum_next())
135 (*cb_func
)(u
->udb_name
,
144 (*cb_func
)(NULL
, 0, 0, NULL
, NULL
, NULL
, void_arg
);