Another update to the vpgsql.c file so that we can also have the "--enable-onchange-script" option with PostgreSQL as the auth module.
Updated patch is attached. Again, please double check the patch, i have not done any testing against it. Thanks Bruce Bruce McAlister wrote: > Bruce McAlister wrote: >> Hold on this for a sec, I found a problem.. I diff'ed a different vpgsql >> ..c file than the one i wanted :/ >> > > Attached is the correct patch :0 > > Sorry about that :/ > > > > !DSPAM:4741926532001880510646!
--- ./vpgsql.c 2007-11-19 12:17:51.734995480 +0000 +++ ./vpgsql.c_new 2007-11-19 13:33:09.201343503 +0000 @@ -390,10 +390,10 @@ #endif #ifdef ENABLE_SQL_LOGGING - qnprintf( sqlBufUpdate, SQL_BUF_SIZE, + qnprintf( SqlBufUpdate, SQL_BUF_SIZE, "delete from vlog where domain = '%s'", domain ); pgres=PQexec(pgc, SqlBufUpdate); - if( !pgres || PGresultStatus(pgres)!=PGRES_COMMAND_OK) { + if( !pgres || PQresultStatus(pgres)!=PGRES_COMMAND_OK) { return(-1); } #endif @@ -443,11 +443,11 @@ #endif #ifdef ENABLE_SQL_LOGGING - qnprintf( sqlBufUpdate, SQL_BUF_SIZE, + qnprintf( SqlBufUpdate, SQL_BUF_SIZE, "delete from vlog where domain = '%s' and user='%s'", domain, user ); pgres=PQexec(pgc, SqlBufUpdate); - if( !pgres || PGresultStatus(pgres)!=PGRES_COMMAND_OK) { + if( !pgres || PQresultStatus(pgres)!=PGRES_COMMAND_OK) { err = -1; } #endif @@ -1334,6 +1334,73 @@ else return valias_current->data; } +char *valias_select_names( char *alias, char *domain ) +{ + PGresult *pgvalias; + int err, verrori; + unsigned ntuples, ctuple; + struct linklist *temp_entry = NULL; + + /* remove old entries as necessary */ + while (valias_current != NULL) + valias_current = linklist_del (valias_current); + + if ( (err=vauth_open(0)) != 0 ) { + verrori = err; + return(NULL); + } + + qnprintf( SqlBufRead, SQL_BUF_SIZE, + "select distinct alias from valias where domain = '%s' order by alias", + domain ); + if ( ! (pgvalias=PQexec(pgc, SqlBufRead)) + || PQresultStatus(pgvalias) != PGRES_TUPLES_OK ) { + if(pgvalias) PQclear(pgvalias); + vcreate_valias_table(); + if ( ! (pgvalias=PQexec(pgc, SqlBufRead)) + || PQresultStatus(pgvalias) != PGRES_TUPLES_OK ) { + fprintf(stderr,"vpgsql: sql error[j]: %s\n", + PQerrorMessage(pgc)); + if (pgvalias) PQclear(pgvalias); + return(NULL); + } + } + + ntuples = PQntuples (pgvalias); + for (ctuple = 0; ctuple < ntuples; ctuple++) { + temp_entry = linklist_add (temp_entry, PQgetvalue (pgvalias, ctuple, 1), PQgetvalue (pgvalias, ctuple, 0)); + if (valias_current == NULL) valias_current = temp_entry; + } + PQclear (pgvalias); + pgvalias = NULL; + + if (valias_current == NULL) return NULL; /* no results */ + else { + strcpy (alias, valias_current->d2); + return(valias_current->data); + } +} + +char *valias_select_names_next(char *alias) +{ + if (valias_current == NULL) return NULL; + + valias_current = linklist_del (valias_current); + + if (valias_current == NULL) return NULL; + else { + strcpy (alias, valias_current->d2); + return valias_current->data; + } +} + +void valias_select_names_end() { + +// not needed by pgsql + +} + + int valias_insert( char *alias, char *domain, char *alias_line) { PGresult *pgres; @@ -1454,7 +1521,7 @@ #ifdef ONCHANGE_SCRIPT if( allow_onchange ) { /* tell other programs that data has changed */ - snprintf ( onchange_buf, MAX_BUFF, "[EMAIL PROTECTED] - %s", alias, domain, alias_line); + snprintf ( onchange_buf, MAX_BUFF, "%s", domain ); call_onchange ( "valias_delete_domain" ); } #endif @@ -1611,4 +1678,3 @@ return(strcmp(crypt(clear_pass,vpw->pw_passwd),vpw->pw_passwd)); } - !DSPAM:4741926532001880510646!