#include #include "mysql_queries.h" #include "scan.h" #include "stralloc.h" stralloc tmpname = { 0 }; stralloc tmphome = { 0 }; stralloc tmpshell = { 0 }; extern MYSQL_RES *result; extern int make_query(stralloc *query, char *username); extern int do_query(stralloc *query, MYSQL_ROW *row); /* get a pw entry from the database */ int getpw_mysql(char *username, int *uid, int *gid) { MYSQL_ROW row; int num, len, rows; stralloc qmail_mysql_query = { 0 }; if (! make_query(&qmail_mysql_query, username)) return -1; rows = do_query(&qmail_mysql_query, &row); if (rows < 1) return rows; if (! stralloc_ready(&tmpname, str_len(username))) return -1; if (! stralloc_copys(&tmpname, username)) return -1; if (! stralloc_0(&tmpname)) return -1; if (! stralloc_ready(&tmphome, str_len(row[2]))) return -1; if (! stralloc_copys(&tmphome, row[2])) return -1; if (! stralloc_0(&tmphome)) return -1; if (! stralloc_ready(&tmpshell, str_len(row[3]))) return -1; if (! stralloc_copys(&tmpshell, row[3])) return -1; if (! stralloc_0(&tmpshell)) return -1; /* OK so we're assuming the database really does return ints */ len = scan_ulong(row[0], uid); if (! len || (row[0])[len]) { log3("MySQL misconfiguration: uid should be a number for user ", username , "!\n"); mysql_free_result(result); return -1; } len = scan_ulong(row[1], gid); if (! len || (row[1])[len]) { log3("MySQL misconfiguration: gid should be a number for user ", username, "!\n"); mysql_free_result(result); return -1; } return 1; }