2 ** Copyright 1998 - 2004 Double Precision, Inc. See COPYING for
3 ** distribution information.
7 #include "courier_auth_config.h"
19 #include "authstaticlist.h"
20 #include "courierauthdebug.h"
22 #include "libhmac/hmac.h"
23 #include "userdb/userdb.h"
25 static const char rcsid
[]="$Id: authuserdb.c,v 1.24 2006/10/28 19:22:52 mrsam Exp $";
27 extern void auth_userdb_enumerate( void(*cb_func
)(const char *name
,
36 extern int auth_userdb_pre_common(const char *, const char *, int,
37 int (*callback
)(struct authinfo
*, void *),
40 extern void auth_userdb_cleanup();
42 struct callback_info
{
44 int (*callback_func
)(struct authinfo
*, void *);
48 static int callback_userdb(struct authinfo
*a
, void *p
)
50 struct callback_info
*i
=(struct callback_info
*)p
;
54 DPRINTF("no password available to compare\n");
59 if (authcheckpassword(i
->pass
, a
->passwd
))
62 a
->clearpasswd
=i
->pass
;
63 return (*i
->callback_func
)(a
, i
->callback_arg
);
67 static int auth_cram(const char *service
, const char *authtype
, char *authdata
,
68 int (*callback_func
)(struct authinfo
*, void *),
76 struct cram_callback_info cci
;
81 if (auth_get_cram(authtype
, authdata
, &cci
))
84 userdb_set_debug(courier_authdebug_login_level
);
85 userdb_init(USERDB
".dat");
86 if ( (u
=userdb(cci
.user
)) == 0)
92 if ( (udbs
=userdbshadow(USERDB
"shadow.dat", cci
.user
)) == 0)
99 if ((services
=malloc(strlen(service
)+strlen(cci
.h
->hh_name
)
100 +sizeof("-hmac-pw"))) == 0)
106 return (1); /* tempfail */
109 strcat(strcat(strcat(strcpy(services
, service
), "-hmac-"),
110 cci
.h
->hh_name
), "pw");
112 passwords
=userdb_gets(udbs
, services
);
115 strcat(strcat(strcpy(services
, "hmac-"),
116 cci
.h
->hh_name
), "pw");
117 passwords
=userdb_gets(udbs
, services
);
121 DPRINTF("authcram: no %s-%s or %s value found",
122 service
, services
, services
);
134 if (auth_verify_cram(cci
.h
, cci
.challenge
, cci
.response
,
146 if ((udb
=userdb_creates(u
)) == 0)
154 memset(&aa
, 0, sizeof(aa
));
156 /*aa.sysusername=user;*/
157 aa
.sysuserid
= &udb
->udb_uid
;
158 aa
.sysgroupid
= udb
->udb_gid
;
159 aa
.homedir
=udb
->udb_dir
;
161 aa
.maildir
=udb
->udb_mailbox
;
162 aa
.options
=udb
->udb_options
;
163 rc
=(*callback_func
)(&aa
, callback_arg
);
172 int auth_userdb(const char *service
, const char *authtype
, char *authdata
,
173 int (*callback_func
)(struct authinfo
*, void *),
176 const char *user
, *pass
;
177 struct callback_info ci
;
179 if (strcmp(authtype
, AUTHTYPE_LOGIN
) ||
180 (user
=strtok(authdata
, "\n")) == 0 ||
181 (pass
=strtok(0, "\n")) == 0)
182 return auth_cram(service
, authtype
, authdata
,
183 callback_func
, callback_arg
);
186 ci
.callback_func
=callback_func
;
187 ci
.callback_arg
=callback_arg
;
188 return auth_userdb_pre_common(user
, service
, 1, &callback_userdb
, &ci
);
191 extern int auth_userdb_pre(const char *userid
, const char *service
,
192 int (*callback
)(struct authinfo
*, void *),
195 extern int auth_userdb_passwd(const char *service
,
197 const char *opwd_buf
,
198 const char *npwd_buf
);
200 static struct authstaticinfo authuserdb_info
={
207 auth_userdb_enumerate
};
210 struct authstaticinfo
*courier_authuserdb_init()
212 return &authuserdb_info
;