2 ** Copyright 2000-2008 Double Precision, Inc. See COPYING for
3 ** distribution information.
6 #include "courier_auth_config.h"
18 #include "authpgsql.h"
19 #include "courierauthstaticlist.h"
20 #include "courierauthdebug.h"
21 #include "libhmac/hmac.h"
25 extern void auth_pgsql_enumerate( void(*cb_func
)(const char *name
,
34 static int auth_pgsql_login(const char *service
, char *authdata
,
35 int (*callback_func
)(struct authinfo
*, void *),
39 struct authpgsqluserinfo
*authinfo
;
42 if ((user
=strtok(authdata
, "\n")) == 0 ||
43 (pass
=strtok(0, "\n")) == 0)
49 authinfo
=auth_pgsql_getuserinfo(user
, service
);
51 if (!authinfo
) /* Fatal error - such as PgSQL 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 */
90 memset(&aa
, 0, sizeof(aa
));
92 /*aa.sysusername=user;*/
93 aa
.sysuserid
= &authinfo
->uid
;
94 aa
.sysgroupid
= authinfo
->gid
;
95 aa
.homedir
=authinfo
->home
;
96 aa
.maildir
=authinfo
->maildir
&& authinfo
->maildir
[0] ?
98 aa
.address
=authinfo
->username
;
99 aa
.quota
=authinfo
->quota
&& authinfo
->quota
[0] ?
101 aa
.fullname
=authinfo
->fullname
;
102 aa
.options
=authinfo
->options
;
103 aa
.passwd
=authinfo
->cryptpw
;
105 courier_authdebug_authinfo("DEBUG: authpgsql: ", &aa
,
106 authinfo
->clearpw
, authinfo
->cryptpw
);
107 return (*callback_func
)(&aa
, callback_arg
);
110 static int auth_pgsql_changepw(const char *service
, const char *user
,
114 struct authpgsqluserinfo
*authinfo
;
116 authinfo
=auth_pgsql_getuserinfo(user
, service
);
124 if (authinfo
->cryptpw
)
126 if (authcheckpassword(pass
,authinfo
->cryptpw
))
129 return (-1); /* User/Password not found. */
132 else if (authinfo
->clearpw
)
134 if (strcmp(pass
, authinfo
->clearpw
))
146 if (auth_pgsql_setpass(user
, newpass
, authinfo
->cryptpw
))
154 static int auth_pgsql_cram(const char *service
,
155 const char *authtype
, char *authdata
,
156 int (*callback_func
)(struct authinfo
*, void *),
159 struct cram_callback_info cci
;
161 if (auth_get_cram(authtype
, authdata
, &cci
))
164 cci
.callback_func
=callback_func
;
165 cci
.callback_arg
=callback_arg
;
167 return auth_pgsql_pre(cci
.user
, service
, &auth_cram_callback
, &cci
);
170 int auth_pgsql(const char *service
, const char *authtype
, char *authdata
,
171 int (*callback_func
)(struct authinfo
*, void *),
174 if (strcmp(authtype
, AUTHTYPE_LOGIN
) == 0)
175 return (auth_pgsql_login(service
, authdata
,
176 callback_func
, callback_arg
));
178 return (auth_pgsql_cram(service
, authtype
, authdata
,
179 callback_func
, callback_arg
));
182 extern int auth_pgsql_pre(const char *user
, const char *service
,
183 int (*callback
)(struct authinfo
*, void *),
186 static struct authstaticinfo authpgsql_info
={
193 auth_pgsql_enumerate
};
195 struct authstaticinfo
*courier_authpgsql_init()
197 return &authpgsql_info
;