2 ** Copyright 2000-2005 Double Precision, Inc. See COPYING for
3 ** distribution information.
6 #include "courier_auth_config.h"
18 #include "authpgsql.h"
19 #include "authstaticlist.h"
20 #include "courierauthdebug.h"
22 static const char rcsid
[]="$Id: authpgsql.c,v 1.13 2006/10/28 19:22:52 mrsam Exp $";
24 extern void auth_pgsql_enumerate( void(*cb_func
)(const char *name
,
33 static int auth_pgsql_login(const char *service
, char *authdata
,
34 int (*callback_func
)(struct authinfo
*, void *),
38 struct authpgsqluserinfo
*authinfo
;
41 if ((user
=strtok(authdata
, "\n")) == 0 ||
42 (pass
=strtok(0, "\n")) == 0)
48 authinfo
=auth_pgsql_getuserinfo(user
, service
);
50 if (!authinfo
) /* Fatal error - such as PgSQL being down */
56 if (authinfo
->cryptpw
)
58 if (authcheckpassword(pass
,authinfo
->cryptpw
))
61 return (-1); /* User/Password not found. */
64 else if (authinfo
->clearpw
)
66 if (strcmp(pass
, authinfo
->clearpw
))
68 if (courier_authdebug_login_level
>= 2)
70 DPRINTF("supplied password '%s' does not match clearpasswd '%s'",
71 pass
, authinfo
->clearpw
);
75 DPRINTF("supplied password does not match clearpasswd");
83 DPRINTF("no password available to compare");
85 return (-1); /* Username not found */
89 memset(&aa
, 0, sizeof(aa
));
91 /*aa.sysusername=user;*/
92 aa
.sysuserid
= &authinfo
->uid
;
93 aa
.sysgroupid
= authinfo
->gid
;
94 aa
.homedir
=authinfo
->home
;
95 aa
.maildir
=authinfo
->maildir
&& authinfo
->maildir
[0] ?
97 aa
.address
=authinfo
->username
;
98 aa
.quota
=authinfo
->quota
&& authinfo
->quota
[0] ?
100 aa
.fullname
=authinfo
->fullname
;
101 aa
.options
=authinfo
->options
;
102 aa
.passwd
=authinfo
->cryptpw
;
104 courier_authdebug_authinfo("DEBUG: authpgsql: ", &aa
,
105 authinfo
->clearpw
, authinfo
->cryptpw
);
106 return (*callback_func
)(&aa
, callback_arg
);
109 static int auth_pgsql_changepw(const char *service
, const char *user
,
113 struct authpgsqluserinfo
*authinfo
;
115 authinfo
=auth_pgsql_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_pgsql_setpass(user
, newpass
, authinfo
->cryptpw
))
155 #include "libhmac/hmac.h"
158 static int auth_pgsql_cram(const char *service
,
159 const char *authtype
, char *authdata
,
160 int (*callback_func
)(struct authinfo
*, void *),
163 struct cram_callback_info cci
;
165 if (auth_get_cram(authtype
, authdata
, &cci
))
168 cci
.callback_func
=callback_func
;
169 cci
.callback_arg
=callback_arg
;
171 return auth_pgsql_pre(cci
.user
, service
, &auth_cram_callback
, &cci
);
175 int auth_pgsql(const char *service
, const char *authtype
, char *authdata
,
176 int (*callback_func
)(struct authinfo
*, void *),
179 if (strcmp(authtype
, AUTHTYPE_LOGIN
) == 0)
180 return (auth_pgsql_login(service
, authdata
,
181 callback_func
, callback_arg
));
184 return (auth_pgsql_cram(service
, authtype
, authdata
,
185 callback_func
, callback_arg
));
192 extern int auth_pgsql_pre(const char *user
, const char *service
,
193 int (*callback
)(struct authinfo
*, void *),
196 static struct authstaticinfo authpgsql_info
={
203 auth_pgsql_enumerate
};
205 struct authstaticinfo
*courier_authpgsql_init()
207 return &authpgsql_info
;