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 *),
77 struct cram_callback_info cci
;
82 if (auth_get_cram(authtype
, authdata
, &cci
))
85 userdb_set_debug(courier_authdebug_login_level
);
86 userdb_init(USERDB
".dat");
87 if ( (u
=userdb(cci
.user
)) == 0)
93 if ( (udbs
=userdbshadow(USERDB
"shadow.dat", cci
.user
)) == 0)
100 if ((services
=malloc(strlen(service
)+strlen(cci
.h
->hh_name
)
101 +sizeof("-hmac-pw"))) == 0)
107 return (1); /* tempfail */
110 strcat(strcat(strcat(strcpy(services
, service
), "-hmac-"),
111 cci
.h
->hh_name
), "pw");
113 passwords
=userdb_gets(udbs
, services
);
116 strcat(strcat(strcpy(services
, "hmac-"),
117 cci
.h
->hh_name
), "pw");
118 passwords
=userdb_gets(udbs
, services
);
122 DPRINTF("authcram: no %s-%s or %s value found",
123 service
, services
, services
);
135 if (auth_verify_cram(cci
.h
, cci
.challenge
, cci
.response
,
147 if ((udb
=userdb_creates(u
)) == 0)
155 memset(&aa
, 0, sizeof(aa
));
157 /*aa.sysusername=user;*/
158 aa
.sysuserid
= &udb
->udb_uid
;
159 aa
.sysgroupid
= udb
->udb_gid
;
160 aa
.homedir
=udb
->udb_dir
;
162 aa
.maildir
=udb
->udb_mailbox
;
163 aa
.options
=udb
->udb_options
;
165 /* Get tokens for AFS */
166 { char uidstr
[32] = "<null>";
170 snprintf(uidstr
, sizeof(uidstr
), "%ld", (long)*aa
.sysuserid
);
171 if ((token_cmd
=malloc(sizeof(TOKEN_CMD
)+strlen(uidstr
))))
173 strcat(strcpy(token_cmd
, TOKEN_CMD
),uidstr
);
180 rc
=(*callback_func
)(&aa
, callback_arg
);
189 int auth_userdb(const char *service
, const char *authtype
, char *authdata
,
190 int (*callback_func
)(struct authinfo
*, void *),
193 const char *user
, *pass
;
194 struct callback_info ci
;
196 if (strcmp(authtype
, AUTHTYPE_LOGIN
) ||
197 (user
=strtok(authdata
, "\n")) == 0 ||
198 (pass
=strtok(0, "\n")) == 0)
199 return auth_cram(service
, authtype
, authdata
,
200 callback_func
, callback_arg
);
203 ci
.callback_func
=callback_func
;
204 ci
.callback_arg
=callback_arg
;
205 return auth_userdb_pre_common(user
, service
, 1, &callback_userdb
, &ci
);
208 extern int auth_userdb_pre(const char *userid
, const char *service
,
209 int (*callback
)(struct authinfo
*, void *),
212 extern int auth_userdb_passwd(const char *service
,
214 const char *opwd_buf
,
215 const char *npwd_buf
);
217 static struct authstaticinfo authuserdb_info
={
224 auth_userdb_enumerate
};
227 struct authstaticinfo
*courier_authuserdb_init()
229 return &authuserdb_info
;