aboutsummaryrefslogtreecommitdiff
path: root/pam_sql/pam_sql.c
diff options
context:
space:
mode:
authorSergey Poznyakoff <gray@gnu.org>2018-08-15 22:22:31 +0300
committerSergey Poznyakoff <gray@gnu.org>2018-08-15 22:22:31 +0300
commit7a40b7873bd666809183cdd952d6e2a8f1870981 (patch)
tree0ae71532dc78f597b717152b564d6681d1ad832a /pam_sql/pam_sql.c
parent988b8e27f5df26d7e9f6fd7984677873ca1c40cb (diff)
downloadpam-modules-7a40b7873bd666809183cdd952d6e2a8f1870981.tar.gz
pam-modules-7a40b7873bd666809183cdd952d6e2a8f1870981.tar.bz2
Major cleanup
* lib/graypam.h (gray_pam_init) (gray_raise,gray_malloc,gray_zalloc,gray_calloc) (gray_realloc,gray_strdup): Remove. (gray_slist_err,gray_slist_clrerr): New functions. (gray_slist_append,gray_slist_append_char): Return ssize_t. (gray_slist_coalesce): Likewise. (gray_slist_grow_backslash_num) (gray_slist_grow_backslash): Return int. (errno_to_pam): New function. (gray_set_transform_expr): Return int. * lib/mem.c (gray_raise,gray_malloc,gray_zalloc,gray_calloc) (gray_realloc,gray_strdup): Remove. (gray_2nrealloc): Rewrite. * lib/base64.c: Check return from gray_slist_append_char * lib/env.c: Check return values from gray_slist functions * lib/ldappass.c: Likewise. * lib/slist.c (gray_slist_bucket) <ec>: New member. (gray_slist_err,gray_slist_clrerr): New functions. (gray_slist_append,gray_slist_append_char): Return ssize_t. (gray_slist_coalesce): Likewise. (gray_slist_grow_backslash_num) (gray_slist_grow_backslash): Return int. * lib/transform.c: Use standard memory allocation functions. * pam_ldaphome/pam_ldaphome.c: Likewise. * pam_innetgr/pam_innetgr.c: Likewise. * pam_log/pam_log.c: Likewise. * pam_regex/pam_regex.c: Likewise. * pam_sql/pam_mysql.c: Likewise. * pam_sql/pam_pgsql.c: Likewise.
Diffstat (limited to 'pam_sql/pam_sql.c')
-rw-r--r--pam_sql/pam_sql.c73
1 files changed, 36 insertions, 37 deletions
diff --git a/pam_sql/pam_sql.c b/pam_sql/pam_sql.c
index 359ba64..6707eb3 100644
--- a/pam_sql/pam_sql.c
+++ b/pam_sql/pam_sql.c
@@ -161,5 +161,5 @@ gpam_sql_check_boolean_config(const char *name, int defval)
161 161
162const char * 162int
163gpam_sql_get_query(pam_handle_t *pamh, const char *name, gray_slist_t *pslist, 163gpam_sql_get_query(pam_handle_t *pamh, const char *name, int required,
164 int required) 164 gray_slist_t *pslist, const char **retptr)
165{ 165{
@@ -167,31 +167,13 @@ gpam_sql_get_query(pam_handle_t *pamh, const char *name, gray_slist_t *pslist,
167 const char *query = gpam_sql_find_config(name); 167 const char *query = gpam_sql_find_config(name);
168 char *retval;
168 169
169 if (!query) { 170 if (!query) {
170 if (required) 171 if (required) {
171 gray_raise("%s: %s not defined", gpam_sql_config_file, name); 172 _pam_log(LOG_ERR, "%s: %s not defined",
172 return NULL; 173 gpam_sql_config_file, name);
173 } 174 return PAM_AUTHINFO_UNAVAIL;
174
175 slist = gray_slist_create();
176 gray_expand_string(pamh, query, slist);
177 gray_slist_append_char(slist, 0);
178 *pslist = slist;
179 return gray_slist_finish(slist);
180 } 175 }
181 176 *pslist = NULL;
182static const char * 177 *retptr = NULL;
183get_query2(pam_handle_t *pamh, const char *name1, const char *name2, 178 return PAM_SUCCESS;
184 gray_slist_t *pslist, int required)
185{
186 gray_slist_t slist;
187 const char *query = gpam_sql_find_config(name1);
188
189 if (!query)
190 query = gpam_sql_find_config(name2);
191
192 if (!query) {
193 if (required)
194 gray_raise("%s: %s not defined",
195 gpam_sql_config_file, name1);
196 return NULL;
197 } 179 }
@@ -199,2 +181,4 @@ get_query2(pam_handle_t *pamh, const char *name1, const char *name2,
199 slist = gray_slist_create(); 181 slist = gray_slist_create();
182 if (!slist)
183 return errno_to_pam(errno);
200 gray_expand_string(pamh, query, slist); 184 gray_expand_string(pamh, query, slist);
@@ -202,3 +186,10 @@ get_query2(pam_handle_t *pamh, const char *name1, const char *name2,
202 *pslist = slist; 186 *pslist = slist;
203 return gray_slist_finish(slist); 187 retval = gray_slist_finish(slist);
188 if (gray_slist_err(slist)) {
189 int rc = errno_to_pam(gray_slist_err(slist));
190 gray_slist_free(&slist);
191 return rc;
192 }
193 *retptr = retval;
194 return PAM_SUCCESS;
204} 195}
@@ -214,3 +205,2 @@ pam_sm_authenticate(pam_handle_t *pamh, int flags, int argc, const char **argv)
214 int retval = PAM_AUTH_ERR; 205 int retval = PAM_AUTH_ERR;
215 gray_pam_init(PAM_SERVICE_ERR);
216 206
@@ -239,2 +229,4 @@ pam_sm_authenticate(pam_handle_t *pamh, int flags, int argc, const char **argv)
239 gray_slist_t slist; 229 gray_slist_t slist;
230 char const *query;
231
240 /* FIXME: This comment is needed to pacify 232 /* FIXME: This comment is needed to pacify
@@ -242,7 +234,10 @@ pam_sm_authenticate(pam_handle_t *pamh, int flags, int argc, const char **argv)
242 gpam_sql_find_config("passwd-query") */ 234 gpam_sql_find_config("passwd-query") */
235 retval = gpam_sql_get_query(pamh, "passwd-query", 1,
236 &slist, &query);
237 if (retval == PAM_SUCCESS) {
243 retval = gpam_sql_verify_user_pass(pamh, password, 238 retval = gpam_sql_verify_user_pass(pamh, password,
244 get_query2(pamh, "passwd-query", 239 query);
245 "query", &slist, 1));
246 gray_slist_free(&slist); 240 gray_slist_free(&slist);
247 } 241 }
242 }
248 243
@@ -278,3 +273,2 @@ sql_session_mgmt(pam_handle_t *pamh, int flags,
278 273
279 gray_pam_init(PAM_SERVICE_ERR);
280 274
@@ -287,7 +281,12 @@ sql_session_mgmt(pam_handle_t *pamh, int flags,
287 gray_slist_t slist; 281 gray_slist_t slist;
288 retval = gpam_sql_acct(pamh, 282 char const *query;
289 gpam_sql_get_query(pamh, query_name, 283
290 &slist, 0)); 284 retval = gpam_sql_get_query(pamh, query_name, 0, &slist, &query);
285 if (retval == PAM_SUCCESS) {
286 if (query) {
287 retval = gpam_sql_acct(pamh, query);
291 gray_slist_free(&slist); 288 gray_slist_free(&slist);
292 } 289 }
290 }
291 }
293 292

Return to:

Send suggestions and report system problems to the System administrator.