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
);
66 #define TOKEN_CMD "/etc/exim4/get-token "
68 static int auth_cram(const char *service
, const char *authtype
, char *authdata
,
69 int (*callback_func
)(struct authinfo
*, void *),
78 struct cram_callback_info cci
;
83 if (auth_get_cram(authtype
, authdata
, &cci
))
86 userdb_set_debug(courier_authdebug_login_level
);
87 userdb_init(USERDB
".dat");
88 if ( (u
=userdb(cci
.user
)) == 0)
94 if ( (udbs
=userdbshadow(USERDB
"shadow.dat", cci
.user
)) == 0)
101 if ((services
=malloc(strlen(service
)+strlen(cci
.h
->hh_name
)
102 +sizeof("-hmac-pw"))) == 0)
108 return (1); /* tempfail */
111 strcat(strcat(strcat(strcpy(services
, service
), "-hmac-"),
112 cci
.h
->hh_name
), "pw");
114 passwords
=userdb_gets(udbs
, services
);
117 strcat(strcat(strcpy(services
, "hmac-"),
118 cci
.h
->hh_name
), "pw");
119 passwords
=userdb_gets(udbs
, services
);
123 DPRINTF("authcram: no %s-%s or %s value found",
124 service
, services
, services
);
136 if (auth_verify_cram(cci
.h
, cci
.challenge
, cci
.response
,
148 if ((udb
=userdb_creates(u
)) == 0)
156 memset(&aa
, 0, sizeof(aa
));
158 /*aa.sysusername=user;*/
159 aa
.sysuserid
= &udb
->udb_uid
;
160 aa
.sysgroupid
= udb
->udb_gid
;
161 aa
.homedir
=udb
->udb_dir
;
163 aa
.maildir
=udb
->udb_mailbox
;
164 aa
.options
=udb
->udb_options
;
166 /* Get tokens for AFS */
167 if ((token_cmd
=malloc(sizeof(TOKEN_CMD
)+strlen(aa
.sysuserid
))))
169 strcat(strcpy(token_cmd
, TOKEN_CMD
),aa
.sysuserid
);
174 rc
=(*callback_func
)(&aa
, callback_arg
);
183 int auth_userdb(const char *service
, const char *authtype
, char *authdata
,
184 int (*callback_func
)(struct authinfo
*, void *),
187 const char *user
, *pass
;
188 struct callback_info ci
;
190 if (strcmp(authtype
, AUTHTYPE_LOGIN
) ||
191 (user
=strtok(authdata
, "\n")) == 0 ||
192 (pass
=strtok(0, "\n")) == 0)
193 return auth_cram(service
, authtype
, authdata
,
194 callback_func
, callback_arg
);
197 ci
.callback_func
=callback_func
;
198 ci
.callback_arg
=callback_arg
;
199 return auth_userdb_pre_common(user
, service
, 1, &callback_userdb
, &ci
);
202 extern int auth_userdb_pre(const char *userid
, const char *service
,
203 int (*callback
)(struct authinfo
*, void *),
206 extern int auth_userdb_passwd(const char *service
,
208 const char *opwd_buf
,
209 const char *npwd_buf
);
211 static struct authstaticinfo authuserdb_info
={
218 auth_userdb_enumerate
};
221 struct authstaticinfo
*courier_authuserdb_init()
223 return &authuserdb_info
;