2 ** Copyright 1998 - 2004 Double Precision, Inc. See COPYING for
3 ** distribution information.
7 #include "courier_auth_config.h"
19 #include "courierauthstaticlist.h"
20 #include "courierauthdebug.h"
22 #include "libhmac/hmac.h"
23 #include "userdb/userdb.h"
26 extern void auth_userdb_enumerate( void(*cb_func
)(const char *name
,
35 extern int auth_userdb_pre_common(const char *, const char *, int,
36 int (*callback
)(struct authinfo
*, void *),
39 extern void auth_userdb_cleanup();
41 struct callback_info
{
43 int (*callback_func
)(struct authinfo
*, void *);
47 static int callback_userdb(struct authinfo
*a
, void *p
)
49 struct callback_info
*i
=(struct callback_info
*)p
;
53 DPRINTF("no password available to compare\n");
58 if (authcheckpassword(i
->pass
, a
->passwd
))
61 a
->clearpasswd
=i
->pass
;
62 return (*i
->callback_func
)(a
, i
->callback_arg
);
66 static int auth_cram(const char *service
, const char *authtype
, char *authdata
,
67 int (*callback_func
)(struct authinfo
*, void *),
75 struct cram_callback_info cci
;
80 if (auth_get_cram(authtype
, authdata
, &cci
))
83 userdb_set_debug(courier_authdebug_login_level
);
84 userdb_init(USERDB
".dat");
85 if ( (u
=userdb(cci
.user
)) == 0)
91 if ( (udbs
=userdbshadow(USERDB
"shadow.dat", cci
.user
)) == 0)
98 if ((services
=malloc(strlen(service
)+strlen(cci
.h
->hh_name
)
99 +sizeof("-hmac-pw"))) == 0)
105 return (1); /* tempfail */
108 strcat(strcat(strcat(strcpy(services
, service
), "-hmac-"),
109 cci
.h
->hh_name
), "pw");
111 passwords
=userdb_gets(udbs
, services
);
114 strcat(strcat(strcpy(services
, "hmac-"),
115 cci
.h
->hh_name
), "pw");
116 passwords
=userdb_gets(udbs
, services
);
120 DPRINTF("authcram: no %s-%s or %s value found",
121 service
, services
, services
);
133 if (auth_verify_cram(cci
.h
, cci
.challenge
, cci
.response
,
145 if ((udb
=userdb_creates(u
)) == 0)
153 memset(&aa
, 0, sizeof(aa
));
155 /*aa.sysusername=user;*/
156 aa
.sysuserid
= &udb
->udb_uid
;
157 aa
.sysgroupid
= udb
->udb_gid
;
158 aa
.homedir
=udb
->udb_dir
;
160 aa
.maildir
=udb
->udb_mailbox
;
161 aa
.options
=udb
->udb_options
;
162 rc
=(*callback_func
)(&aa
, callback_arg
);
171 int auth_userdb(const char *service
, const char *authtype
, char *authdata
,
172 int (*callback_func
)(struct authinfo
*, void *),
175 const char *user
, *pass
;
176 struct callback_info ci
;
178 if (strcmp(authtype
, AUTHTYPE_LOGIN
) ||
179 (user
=strtok(authdata
, "\n")) == 0 ||
180 (pass
=strtok(0, "\n")) == 0)
181 return auth_cram(service
, authtype
, authdata
,
182 callback_func
, callback_arg
);
185 ci
.callback_func
=callback_func
;
186 ci
.callback_arg
=callback_arg
;
187 return auth_userdb_pre_common(user
, service
, 1, &callback_userdb
, &ci
);
190 extern int auth_userdb_pre(const char *userid
, const char *service
,
191 int (*callback
)(struct authinfo
*, void *),
194 extern int auth_userdb_passwd(const char *service
,
196 const char *opwd_buf
,
197 const char *npwd_buf
);
199 static struct authstaticinfo authuserdb_info
={
206 auth_userdb_enumerate
};
209 struct authstaticinfo
*courier_authuserdb_init()
211 return &authuserdb_info
;