2 ** Copyright 2000-2004 Double Precision, Inc. See COPYING for
3 ** distribution information.
6 #include "courier_auth_config.h"
18 #include "authmysql.h"
19 #include "authstaticlist.h"
20 #include "courierauthdebug.h"
22 static const char rcsid
[]="$Id: authmysql.c,v 1.23 2006/10/28 19:22:52 mrsam Exp $";
24 extern void auth_mysql_enumerate( void(*cb_func
)(const char *name
,
33 static int auth_mysql_login(const char *service
, char *authdata
,
34 int (*callback_func
)(struct authinfo
*, void *),
38 struct authmysqluserinfo
*authinfo
;
42 if ((user
=strtok(authdata
, "\n")) == 0 ||
43 (pass
=strtok(0, "\n")) == 0)
49 authinfo
=auth_mysql_getuserinfo(user
, service
);
51 if (!authinfo
) /* Fatal error - such as MySQL being down */
57 if (authinfo
->cryptpw
)
59 if (authcheckpassword(pass
,authinfo
->cryptpw
))
62 return (-1); /* User/Password not found. */
65 else if (authinfo
->clearpw
)
67 if (strcmp(pass
, authinfo
->clearpw
))
69 if (courier_authdebug_login_level
>= 2)
71 DPRINTF("supplied password '%s' does not match clearpasswd '%s'",
72 pass
, authinfo
->clearpw
);
76 DPRINTF("supplied password does not match clearpasswd");
84 DPRINTF("no password available to compare");
86 return (-1); /* Username not found */
89 memset(&aa
, 0, sizeof(aa
));
91 aa
.sysuserid
= &authinfo
->uid
;
92 aa
.sysgroupid
= authinfo
->gid
;
93 aa
.homedir
=authinfo
->home
;
94 aa
.maildir
=authinfo
->maildir
&& authinfo
->maildir
[0] ?
96 aa
.address
=authinfo
->username
;
97 aa
.quota
=authinfo
->quota
&& authinfo
->quota
[0] ?
99 aa
.fullname
=authinfo
->fullname
;
100 aa
.options
=authinfo
->options
;
102 aa
.passwd
=authinfo
->cryptpw
;
103 courier_authdebug_authinfo("DEBUG: authmysql: ", &aa
,
104 authinfo
->clearpw
, authinfo
->cryptpw
);
106 return (*callback_func
)(&aa
, callback_arg
);
109 static int auth_mysql_changepw(const char *service
, const char *user
,
113 struct authmysqluserinfo
*authinfo
;
115 authinfo
=auth_mysql_getuserinfo(user
, service
);
123 if (authinfo
->cryptpw
)
125 if (authcheckpassword(pass
,authinfo
->cryptpw
))
128 return (-1); /* User/Password not found. */
131 else if (authinfo
->clearpw
)
133 if (strcmp(pass
, authinfo
->clearpw
))
145 if (auth_mysql_setpass(user
, newpass
, authinfo
->cryptpw
))
155 #include "libhmac/hmac.h"
159 static int auth_mysql_cram(const char *service
,
160 const char *authtype
, char *authdata
,
161 int (*callback_func
)(struct authinfo
*, void *),
164 struct cram_callback_info cci
;
166 if (auth_get_cram(authtype
, authdata
, &cci
))
169 cci
.callback_func
=callback_func
;
170 cci
.callback_arg
=callback_arg
;
172 return auth_mysql_pre(cci
.user
, service
, &auth_cram_callback
, &cci
);
176 int auth_mysql(const char *service
, const char *authtype
, char *authdata
,
177 int (*callback_func
)(struct authinfo
*, void *),
180 if (strcmp(authtype
, AUTHTYPE_LOGIN
) == 0)
181 return (auth_mysql_login(service
, authdata
,
182 callback_func
, callback_arg
));
185 return (auth_mysql_cram(service
, authtype
, authdata
,
186 callback_func
, callback_arg
));
193 extern int auth_mysql_pre(const char *user
, const char *service
,
194 int (*callback
)(struct authinfo
*, void *),
197 static struct authstaticinfo authmysql_info
={
204 auth_mysql_enumerate
};
207 struct authstaticinfo
*courier_authmysql_init()
209 return &authmysql_info
;