22 |
#ifdef HAVE_PGSQL |
#ifdef HAVE_PGSQL |
23 |
#include <sql.h> |
#include <sql.h> |
24 |
#include <libpq-fe.h> |
#include <libpq-fe.h> |
25 |
|
#include <ctype.h> |
26 |
|
|
27 |
static PGconn * |
static PGconn * |
28 |
pg_connect () |
pg_connect () |
82 |
|
|
83 |
ntuples = PQntuples (res); |
ntuples = PQntuples (res); |
84 |
nfields = PQnfields (res); |
nfields = PQnfields (res); |
85 |
if (ntuples > 1 && nfields) |
if ((ntuples > 1 && nfields) || ntuples == 0) |
86 |
{ |
{ |
87 |
mu_error (ngettext("query returned %d tuple: %s", |
mu_error (ngettext("query returned %d tuple: %s", |
88 |
"query returned %d tuples: %s", |
"query returned %d tuples: %s", |
89 |
ntuples), |
ntuples), |
90 |
ntuples, query_str); |
ntuples, query_str); |
91 |
|
if (ntuples == 0) |
92 |
|
return 1; |
93 |
} |
} |
94 |
|
|
95 |
if (nfields < 6) |
if (nfields < 6) |
108 |
homedir = chop (PQgetvalue (res, 0, 4)); |
homedir = chop (PQgetvalue (res, 0, 4)); |
109 |
shell = chop (PQgetvalue (res, 0, 5)); |
shell = chop (PQgetvalue (res, 0, 5)); |
110 |
|
|
111 |
if (ntuples == 7) |
if (nfields == 7) |
112 |
{ |
{ |
113 |
mailbox_name = strdup (chop (PQgetvalue (res, 0, 6))); |
mailbox_name = strdup (chop (PQgetvalue (res, 0, 6))); |
114 |
} |
} |
136 |
} |
} |
137 |
|
|
138 |
int |
int |
139 |
pg_auth_sql_by_name (void *return_data, void *key, |
pg_auth_sql_by_name (struct mu_auth_data **return_data, void *key, |
140 |
void *func_data ARG_UNUSED, |
void *func_data ARG_UNUSED, |
141 |
void *call_data ARG_UNUSED) |
void *call_data ARG_UNUSED) |
142 |
{ |
{ |
174 |
} |
} |
175 |
else |
else |
176 |
{ |
{ |
177 |
rc = pg_auth_common (res, query_str, |
rc = pg_auth_common (res, query_str, return_data); |
|
(struct mu_auth_data **)return_data); |
|
178 |
PQclear(res); |
PQclear(res); |
179 |
} |
} |
180 |
|
|
185 |
} |
} |
186 |
|
|
187 |
int |
int |
188 |
pg_auth_sql_by_uid (void *return_data, void *key, |
pg_auth_sql_by_uid (struct mu_auth_data **return_data, void *key, |
189 |
void *func_data ARG_UNUSED, |
void *func_data ARG_UNUSED, |
190 |
void *call_data ARG_UNUSED) |
void *call_data ARG_UNUSED) |
191 |
{ |
{ |
224 |
} |
} |
225 |
else |
else |
226 |
{ |
{ |
227 |
rc = pg_auth_common (res, query_str, |
rc = pg_auth_common (res, query_str, return_data); |
|
(struct mu_auth_data **)return_data); |
|
228 |
PQclear(res); |
PQclear(res); |
229 |
} |
} |
230 |
|
|
235 |
} |
} |
236 |
|
|
237 |
int |
int |
238 |
pg_sql_authenticate (void *return_data ARG_UNUSED, void *key, |
pg_sql_authenticate (struct mu_auth_data **return_data ARG_UNUSED, void *key, |
239 |
void *func_data ARG_UNUSED, void *call_data) |
void *func_data ARG_UNUSED, void *call_data) |
240 |
{ |
{ |
241 |
PGconn *conn; |
PGconn *conn; |
279 |
char *p; |
char *p; |
280 |
int ntuples = PQntuples (res); |
int ntuples = PQntuples (res); |
281 |
int nfields = PQnfields (res); |
int nfields = PQnfields (res); |
282 |
if (ntuples > 1 && nfields) |
if ((ntuples > 1 && nfields) || ntuples == 0) |
283 |
{ |
{ |
284 |
mu_error (ngettext("query returned %d tuple: %s", |
mu_error (ngettext("query returned %d tuple: %s", |
285 |
"query returned %d tuples: %s", |
"query returned %d tuples: %s", |
286 |
ntuples), |
ntuples), |
287 |
ntuples, query_str); |
ntuples, query_str); |
288 |
|
if (ntuples == 0) |
289 |
|
return 1; |
290 |
} |
} |
291 |
|
|
292 |
if (nfields > 1) |
if (nfields > 1) |