Rick Widmer wrote:
>
> That is the basic idea but it was the wrong approach. Would you please
> change vauth.c back the way it was, then make changes in vpgsql.c to
> make it work. Once that is done, then do a diff -u oldfile newfile
> and either post the results to this list, or upload it to the tracker on
> SourceForge. I'll patch CVS with it, and add you to the list of
> contributors in Changelog. It's really pretty easy.
>
> The thing to remember, the rest of vpopmail is probably correct, all
> problems should be fixed in vpgsql.c. As long as you are testing and
> using your patches to vpgsql.c or vpgsql.h I'll apply them to the next
> release. If you think you need changes to any other files, you'll have
> to convince us why
> ...
>
I have attached a patch to vpgsql.c that will allow vpopmail 5.4.26 to
compile with the "--enable-valias" and "--enable-sql-loggin" configure
options, when "--enable-auth-module=pgsql" is in effect.
-------------------------------------------------------------------------
NOTE NOTE NOTE
Please can someone with more experience with vpopmail and C double check
the patch. I compared the functions against the mysql equivilents and
the two appear to be in sync, except for the obvious differences :)
-------------------------------------------------------------------------
I have not tested this as of yet.
These were the things that I changed/added:
[1] sqlBufUpdate typo, should be SqlBufUpdate
[2] PGresultStatus typo, should be PQresultStatus (Thanks Charles Boening)
[3] Copied and modified the following functions:
valias_select -> valias_select_names
valias_select_next -> valias_select_names_next
[4] Created a blank valias_select_names_end finction
Thanks
Bruce
!DSPAM:4741862532001983174778!
--- ./vpgsql.c 2007-11-19 12:17:51.734995480 +0000
+++ ./vpgsql.c_new 2007-11-19 12:38:04.654285880 +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()
+{
+ 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;
@@ -1611,4 +1678,3 @@
return(strcmp(crypt(clear_pass,vpw->pw_passwd),vpw->pw_passwd));
}
-
!DSPAM:4741862532001983174778!