Hi list, 

I am attaching a rewrite of Pawel Wilk's "myownquery" intended for the
authpgsql module. 

This is a very crude approach; I have done minimal work for adapting the
patch; the functions that have been added to modmysqllib.c by Pawel are
now duplicated in modpgsqllib.c. Of course this is not right, probably
they have to be extracted into a separate c file, but i am not that far
down the "C" road ;) So, this is just a start. It works for my setup so
I am pleased with the result (I have dumped my old ugly patches ;). 

georgeb 

PS: As you may notice, this is basically search&replace ;) 
PPS: the patch applies both on 1.4.2 and on courier-imap-1.4.2.20020220.

 authpgsqllib.c |  641 ++++++++++++++++++++++++++++++++++++++++++++++-----------
 authpgsqlrc    |   63 +++++
 2 files changed, 588 insertions(+), 116 deletions(-)

diff -ur --new-file courier-imap-1.4.2/authlib/authpgsqllib.c 
courier-imap-1.4.2-moq-pgport/authlib/authpgsqllib.c
--- courier-imap-1.4.2/authlib/authpgsqllib.c   Sat Oct  6 22:01:23 2001
+++ courier-imap-1.4.2-moq-pgport/authlib/authpgsqllib.c        Sun Feb 24 16:00:26 
+2002
@@ -18,8 +18,27 @@
 #include       "authpgsqlrc.h"
 #include       "auth.h"
 
+/* [EMAIL PROTECTED] */
+#define                MAX_SUBSTITUTION_LEN    32
+#define                SV_BEGIN_MARK           "$("
+#define                SV_END_MARK             ")"
+#define                SV_BEGIN_LEN            ((sizeof(SV_BEGIN_MARK))-1)
+#define                SV_END_LEN              ((sizeof(SV_END_MARK))-1)
+
+
 static const char rcsid[]="$Id: authpgsqllib.c,v 1.1 2001/10/06 19:01:23 mrsam Exp $";
 
+/* [EMAIL PROTECTED] */
+struct var_data {
+       const char *name;
+       const char *value;
+       const size_t size;
+       size_t value_length;
+       } ;
+
+/* [EMAIL PROTECTED] */
+typedef int (*parsefunc)(const char *, size_t, void *);
+
 static const char *read_env(const char *env)
 {
 static char *pgsqlauth=0;
@@ -51,7 +70,16 @@
 
                for (i=0; i<pgsqlauth_size; i++)
                        if (pgsqlauth[i] == '\n')
-                               pgsqlauth[i]=0;
+                       {       /* [EMAIL PROTECTED] */
+                               if (!i || pgsqlauth[i-1] != '\\')
+                               {
+                                       pgsqlauth[i]='\0';
+                               }
+                               else
+                               {
+                                       pgsqlauth[i]=pgsqlauth[i-1]= ' ';
+                               }
+                       }
                fclose(f);
        }
 
@@ -195,6 +223,354 @@
                strcat(strcpy(p, "@"), defdomain);
 }
 
+/* [EMAIL PROTECTED] */
+static struct var_data *get_variable (const char *begin, size_t len,
+                                               struct var_data *vdt)
+{
+struct var_data *vdp;
+
+       if (!begin || !vdt) /* should never happend */
+       {
+               fprintf (stderr, "authpgsql: critical error while "
+                               "parsing substitution variable\n");
+               return NULL;
+       }
+       if (len < 1)
+       {
+               fprintf (stderr, "authpgsql: unknown empty substitution "
+                               "variable - aborting\n");
+               return NULL;
+       }
+       if (len > MAX_SUBSTITUTION_LEN)
+       {
+               fprintf (stderr, "authpgsql: variable name too long "
+                               "while parsing substitution\n"
+                               "authpgsql: name begins with "
+                               SV_BEGIN_MARK
+                               "%.*s...\n", MAX_SUBSTITUTION_LEN, begin);
+               return NULL;
+       }
+
+       for (vdp=vdt; vdp->name; vdp++)
+               if (vdp->size == len+1 &&
+                   !strncmp(begin, vdp->name, len))
+               {
+                       if (!vdp->value)
+                               vdp->value = "";
+                       if (!vdp->value_length)         /* length cache */
+                               vdp->value_length = strlen (vdp->value);
+                       return vdp;
+               }
+
+       fprintf (stderr, "authpgsql: unknown substitution variable "
+                       SV_BEGIN_MARK
+                       "%.*s"
+                       SV_END_MARK
+                       "\n", len, begin);
+
+       return NULL;
+}
+
+/* [EMAIL PROTECTED] */
+static int ParsePlugin_counter (const char *p, size_t length, void *vp)
+{
+       if (!p || !vp || length < 0)
+       {
+               fprintf (stderr, "authpgsql: bad arguments while counting "
+                               "query string\n");
+               return -1;
+       }
+
+       *((size_t *)vp) += length;
+
+       return 0;
+}
+
+/* [EMAIL PROTECTED] */
+static int ParsePlugin_builder (const char *p, size_t length, void *vp)
+{
+char    **strptr = (char **) vp;
+
+       if (!p || !vp || length < 0)
+       {
+               fprintf (stderr, "authpgsql: bad arguments while building "
+                               "query string\n");
+               return -1;
+       }
+
+       if (!length) return 0;
+       memcpy ((void *) *strptr, (void *) p, length);
+       *strptr += length;
+
+       return 0;
+}
+
+/* [EMAIL PROTECTED] */
+static int parse_core  (const char *source, struct var_data *vdt,
+               parsefunc outfn, void *result)
+{
+size_t v_size          = 0,
+       t_size          = 0;
+const char     *p, *q, *e,
+               *v_begin, *v_end,
+               *t_begin, *t_end;
+struct var_data *v_ptr;
+
+       if (!source)
+               source = "";
+       if (!result)
+       {
+               fprintf (stderr, "authpgsql: no memory allocated for result"
+                               "while parser core was invoked\n");
+               return -1;
+       }
+       if (!vdt)
+       {
+               fprintf (stderr, "authpgsql: no substitution table found "
+                               "while parser core was invoked\n");
+               return -1;
+       }
+
+       q = source;
+       while ( (p=strstr(q, SV_BEGIN_MARK)) )
+       {
+               e = strstr (p, SV_END_MARK);
+               if (!e)
+               {
+                       fprintf (stderr, "authpgsql: syntax error in "
+                                       "substitution "
+                                       "- no closing symbol fould!\n"
+                                       "authpgsql: bad variable begins with:"
+                                       "%.*s...\n", MAX_SUBSTITUTION_LEN, p);
+                       return -1;
+               }
+
+               /*
+                **
+                **          __________sometext$(variable_name)_________
+                **                    |      |  |           |  
+                **             t_begin' t_end'  `v_begin    `v_end
+                **
+                 */
+
+               v_begin = p+SV_BEGIN_LEN; /* variable field ptr             */
+               v_end   = e-SV_END_LEN;   /* variable field last character  */
+               v_size  = v_end-v_begin+1;/* variable field length          */
+               
+               t_begin = q;              /* text field ptr                 */
+               t_end   = p-1;            /* text field last character      */
+               t_size  = t_end-t_begin+1;/* text field length              */
+               
+               /* work on text */
+               if ( (outfn (t_begin, t_size, result)) == -1 )
+                       return -1;
+
+               /* work on variable */
+               v_ptr = get_variable (v_begin, v_size, vdt);
+               if (!v_ptr) return -1;
+
+               if ( (outfn (v_ptr->value, v_ptr->value_length, result)) == -1 )
+                       return -1;
+
+               q = e + 1;
+       }
+
+       /* work on last part of text if any */
+       if (*q != '\0')
+               if ( (outfn (q, strlen(q), result)) == -1 )
+                       return -1;
+
+       return 0;
+}
+
+/* [EMAIL PROTECTED] */
+static char *parse_string (const char *source, struct var_data *vdt)
+{
+struct var_data *vdp   = NULL;
+char   *output_buf     = NULL,
+       *pass_buf       = NULL;
+size_t buf_size        = 2;
+
+       if (source == NULL || *source == '\0' ||
+                       vdt == NULL    || vdt[0].name == NULL)
+       {
+               fprintf (stderr, "authpgsql: source clause is empty "
+                               "- this is critical error\n");
+               return NULL;
+       }
+
+       /* zero var_data length cache - important! */
+       for (vdp=vdt; vdp->name; vdp++)
+               vdp->value_length = 0;
+
+       /* phase 1 - count and validate string */
+       if ( (parse_core (source, vdt, &ParsePlugin_counter, &buf_size)) != 0)
+               return NULL;
+
+       /* phase 2 - allocate memory */
+       output_buf = malloc (buf_size);
+       if (!output_buf)
+       {
+               perror ("malloc");
+               return NULL;
+       }
+       pass_buf = output_buf;
+
+       /* phase 3 - build the output string */
+       if ( (parse_core (source, vdt, &ParsePlugin_builder, &pass_buf)) != 0)
+       {
+               free (output_buf);
+               return NULL;
+       }
+       *pass_buf = '\0';
+
+       return output_buf;
+}
+
+/* [EMAIL PROTECTED] */
+static const char *get_localpart (const char *username)
+{
+size_t         lbuf    = 0;
+const char     *l_end, *p;
+char           *q;
+static char    localpart_buf[130];
+
+       if (!username || *username == '\0')     return NULL;
+
+       p = strchr(username,'@');
+       if (p)
+       {
+               if ((p-username) > 128)
+                       return NULL;
+               l_end = p;
+       }
+       else
+       {
+               if ((lbuf = strlen(username)) > 128)
+                       return NULL;
+               l_end = username + lbuf;
+       }
+
+       p=username;
+       q=localpart_buf;
+
+       while (*p && p != l_end)
+               if (*p == '\"' || *p == '\\' ||
+                   *p == '\'' || (int)(unsigned char)*p < ' ')
+                       p++;
+               else
+                       *q++ = *p++;
+
+       *q = '\0';
+       return localpart_buf;
+}
+
+/* [EMAIL PROTECTED] */
+static const char *get_domain (const char *username, const char *defdomain)
+{
+static char    domain_buf[260];
+const char     *p;
+char           *q;
+       
+       if (!username || *username == '\0')     return NULL;
+       p = strchr(username,'@');
+
+       if (!p || *(p+1) == '\0')
+       {
+               if (defdomain && *defdomain)
+                       return defdomain;
+               else
+                       return NULL;
+       }
+
+       p++;
+       if ((strlen(p)) > 256)
+               return NULL;
+
+       q = domain_buf;
+       while (*p)
+               if (*p == '\"' || *p == '\\' ||
+                   *p == '\'' || (int)(unsigned char)*p < ' ')
+                       p++;
+               else
+                       *q++ = *p++;
+
+       *q = '\0';
+       return domain_buf;
+}
+
+/* [EMAIL PROTECTED] */
+static const char *validate_password (const char *password)
+{
+static char    pass_buf[260];
+const char     *p;
+char           *q;
+
+       if (!password || *password == '\0' || (strlen(password)) > 256)
+               return NULL;
+
+       p = password;
+       q = pass_buf;
+
+       while (*p)
+               if (*p == '\"' || *p == '\\' || *p == '\'')
+                       *q++ = '\\';
+               else
+                       *q++ = *p++;
+
+       *q = '\0';
+       return pass_buf;
+}
+
+/* [EMAIL PROTECTED] */
+static char *parse_select_clause (const char *clause, const char *username,
+                                  const char *defdomain)
+{
+static struct var_data vd[]={
+           {"local_part",      NULL,   sizeof("local_part"),   0},
+           {"domain",          NULL,   sizeof("domain"),       0},
+           {NULL,              NULL,   0,                      0}};
+
+       if (clause == NULL || *clause == '\0' ||
+           !username || *username == '\0')
+               return NULL;
+
+       vd[0].value     = get_localpart (username);
+       vd[1].value     = get_domain (username, defdomain);
+       if (!vd[0].value || !vd[1].value)
+               return NULL;
+
+       return (parse_string (clause, vd));
+}
+
+/* [EMAIL PROTECTED] */
+static char *parse_chpass_clause (const char *clause, const char *username,
+                                 const char *defdomain, const char *newpass,
+                                 const char *newpass_crypt)
+{
+static struct var_data vd[]={
+           {"local_part",      NULL,   sizeof("local_part"),           0},
+           {"domain",          NULL,   sizeof("domain"),               0},
+           {"newpass",         NULL,   sizeof("newpass"),              0},
+           {"newpass_crypt",   NULL,   sizeof("newpass_crypt"),        0},
+           {NULL,              NULL,   0,                              0}};
+       
+       if (clause == NULL || *clause == '\0'           ||
+           !username || *username == '\0'              ||
+           !newpass || *newpass == '\0'                ||
+           !newpass_crypt || *newpass_crypt == '\0')   return NULL;
+
+       vd[0].value     = get_localpart (username);
+       vd[1].value     = get_domain (username, defdomain);
+       vd[2].value     = validate_password (newpass);
+       vd[3].value     = validate_password (newpass_crypt);
+
+       if (!vd[0].value || !vd[1].value ||
+           !vd[2].value || !vd[3].value)       return NULL;
+
+       return (parse_string (clause, vd));
+}
+
 struct authpgsqluserinfo *auth_pgsql_getuserinfo(const char *username)
 {
 const char *user_table;
@@ -203,7 +579,8 @@
 
 const char *crypt_field, *clear_field, *maildir_field, *home_field,
        *name_field,
-       *login_field, *uid_field, *gid_field, *quota_field, *where_clause;
+       *login_field, *uid_field, *gid_field, *quota_field, *where_clause,
+       *select_clause; /* [EMAIL PROTECTED] */
 
 static const char query[]=
        "SELECT %s, %s, %s, %s, %s, %s, %s, %s, %s FROM %s WHERE %s = '";
@@ -230,83 +607,98 @@
        fprintf(DEBUG,"1Leggo parametri\n");
        fflush(DEBUG);
 */
-       user_table=read_env("PGSQL_USER_TABLE");
+
+       select_clause=read_env("PGSQL_SELECT_CLAUSE");
        defdomain=read_env("DEFAULT_DOMAIN");
 
-       if (!user_table)
+       if (!select_clause) /* [EMAIL PROTECTED] */
        {
-               fprintf(stderr, "authpgsql: PGSQL_USER_TABLE not set in "
-                       AUTHPGSQLRC ".\n");
-               return (0);
-       }
+               user_table=read_env("PGSQL_USER_TABLE");        
+
+               if (!user_table)
+               {
+                       fprintf(stderr, "authpgsql: PGSQL_USER_TABLE not set in "
+                               AUTHPGSQLRC ".\n");
+                       return (0);
+               }
 
-       crypt_field=read_env("PGSQL_CRYPT_PWFIELD");
-       clear_field=read_env("PGSQL_CLEAR_PWFIELD");
-       name_field=read_env("PGSQL_NAME_FIELD");
+               crypt_field=read_env("PGSQL_CRYPT_PWFIELD");
+               clear_field=read_env("PGSQL_CLEAR_PWFIELD");
+               name_field=read_env("PGSQL_NAME_FIELD");
 /*
-       fprintf(DEBUG,"2Leggo parametri\n");
-       fflush(DEBUG);
+               fprintf(DEBUG,"2Leggo parametri\n");
+               fflush(DEBUG);
 */
 
-       if (!crypt_field && !clear_field)
-       {
-               fprintf(stderr,
-                       "authpgsql: PGSQL_CRYPT_PWFIELD and "
-                       "PGSQL_CLEAR_PWFIELD not set in " AUTHPGSQLRC ".\n");
-               return (0);
-       }
-       if (!crypt_field) crypt_field="''";
-       if (!clear_field) clear_field="''";
-       if (!name_field) name_field="''";
+               if (!crypt_field && !clear_field)
+               {
+                       fprintf(stderr,
+                               "authpgsql: PGSQL_CRYPT_PWFIELD and "
+                               "PGSQL_CLEAR_PWFIELD not set in " AUTHPGSQLRC ".\n");
+                       return (0);
+               }
+               if (!crypt_field) crypt_field="''";
+               if (!clear_field) clear_field="''";
+               if (!name_field) name_field="''";
 
-       uid_field = read_env("PGSQL_UID_FIELD");
-       if (!uid_field) uid_field = "uid";
+               uid_field = read_env("PGSQL_UID_FIELD");
+               if (!uid_field) uid_field = "uid";
 
-       gid_field = read_env("PGSQL_GID_FIELD");
-       if (!gid_field) gid_field = "gid";
+               gid_field = read_env("PGSQL_GID_FIELD");
+               if (!gid_field) gid_field = "gid";
 
-       login_field = read_env("PGSQL_LOGIN_FIELD");
-       if (!login_field) login_field = "id";
+               login_field = read_env("PGSQL_LOGIN_FIELD");
+               if (!login_field) login_field = "id";
 
-       home_field = read_env("PGSQL_HOME_FIELD");
-       if (!home_field) home_field = "home";
+               home_field = read_env("PGSQL_HOME_FIELD");
+               if (!home_field) home_field = "home";
 
-       maildir_field=read_env("PGSQL_MAILDIR_FIELD");
-       if (!maildir_field) maildir_field="''";
+               maildir_field=read_env("PGSQL_MAILDIR_FIELD");
+               if (!maildir_field) maildir_field="''";
 
-       quota_field=read_env("PGSQL_QUOTA_FIELD");
-       if (!quota_field) quota_field="''"; 
+               quota_field=read_env("PGSQL_QUOTA_FIELD");
+               if (!quota_field) quota_field="''"; 
 
-       where_clause=read_env("PGSQL_WHERE_CLAUSE");
-       if (!where_clause) where_clause = "";
+               where_clause=read_env("PGSQL_WHERE_CLAUSE");
+               if (!where_clause) where_clause = "";
+       }
        
        if (!defdomain) defdomain="";
 
-       querybuf=malloc(sizeof(query) + 100 + strlen(user_table) + strlen(defdomain)
-               + strlen(crypt_field) + strlen(clear_field) + strlen(maildir_field)
-               + strlen(uid_field) + strlen(gid_field) + 2 * strlen(login_field)
-               + strlen(home_field) + strlen(quota_field) + strlen(where_clause)
-                       + strlen(name_field));
-       if (!querybuf)
-       {
-               perror("malloc");
-               return (0);
-       }
-
-       sprintf(querybuf, query, login_field, crypt_field, clear_field, 
-               uid_field, gid_field, home_field, maildir_field, quota_field,
-               name_field, user_table, login_field);
-       p=querybuf+strlen(querybuf);
-
-       append_username(p, username, defdomain);
-       strcat(p, "'");
-       
-       if (strcmp(where_clause, "")) {
-               strcat(p, " AND (");
-               strcat(p, where_clause);
-               strcat(p, ")");
+       if (!select_clause) /* [EMAIL PROTECTED] */
+       {
+               querybuf=malloc(sizeof(query) + 100 + strlen(user_table) + 
+strlen(defdomain)
+                       + strlen(crypt_field) + strlen(clear_field) + 
+strlen(maildir_field)
+                       + strlen(uid_field) + strlen(gid_field) + 2 * 
+strlen(login_field)
+                       + strlen(home_field) + strlen(quota_field) + 
+strlen(where_clause)
+                               + strlen(name_field));
+               if (!querybuf)
+               {
+                       perror("malloc");
+                       return (0);
+               }
+       
+               sprintf(querybuf, query, login_field, crypt_field, clear_field, 
+                       uid_field, gid_field, home_field, maildir_field, quota_field,
+                       name_field, user_table, login_field);
+               p=querybuf+strlen(querybuf);
+       
+               append_username(p, username, defdomain);
+               strcat(p, "'");
+               
+               if (strcmp(where_clause, "")) {
+                       strcat(p, " AND (");
+                       strcat(p, where_clause);
+                       strcat(p, ")");
+               }
        }
-
+       else
+       {
+               /* [EMAIL PROTECTED] */
+               querybuf=parse_select_clause (select_clause, username, defdomain);
+               if (!querybuf) return 0;
+       }
+       
 /*
        fprintf(DEBUG,"Eseguo la query:\n%s\n",querybuf);
        fflush(DEBUG);
@@ -419,6 +811,7 @@
        const char *where_clause;
        const char *user_table;
        const char *login_field;
+       const char *chpass_clause; /* [EMAIL PROTECTED] */
 
        if (!pgconn)
                return (-1);
@@ -446,75 +839,93 @@
                ++l;
        }
 
-       login_field = read_env("PGSQL_LOGIN_FIELD");
-       if (!login_field) login_field = "id";
-       crypt_field=read_env("PGSQL_CRYPT_PWFIELD");
-       clear_field=read_env("PGSQL_CLEAR_PWFIELD");
+       chpass_clause=read_env("PGSQL_CHPASS_CLAUSE");  
        defdomain=read_env("DEFAULT_DOMAIN");
-       where_clause=read_env("PGSQL_WHERE_CLAUSE");
        user_table=read_env("PGSQL_USER_TABLE");
+       if (!chpass_clause)
+       {
+               login_field = read_env("PGSQL_LOGIN_FIELD");
+               if (!login_field) login_field = "id";
+               crypt_field=read_env("PGSQL_CRYPT_PWFIELD");
+               clear_field=read_env("PGSQL_CLEAR_PWFIELD");
+               where_clause=read_env("PGSQL_WHERE_CLAUSE");
+               sql_buf=malloc(strlen(crypt_field ? crypt_field:"")
+                               + strlen(clear_field ? clear_field:"")
+                               + strlen(defdomain ? defdomain:"")
+                               + strlen(login_field) + l + strlen(newpass_crypt)
+                               + strlen(user_table)
+                               + strlen(where_clause ? where_clause:"")
+                               + 200);
+       }
+       else
+       {
+               sql_buf=parse_chpass_clause(chpass_clause,
+                                           user,
+                                           defdomain,
+                                           pass,
+                                           newpass_crypt);
+       }
 
-       sql_buf=malloc(strlen(crypt_field ? crypt_field:"")
-                      + strlen(clear_field ? clear_field:"")
-                      + strlen(defdomain ? defdomain:"")
-                      + strlen(login_field) + l + strlen(newpass_crypt)
-                      + strlen(user_table)
-                      + strlen(where_clause ? where_clause:"")
-                      + 200);
-
+       
        if (!sql_buf)
        {
                free(newpass_crypt);
                return (-1);
        }
 
-       sprintf(sql_buf, "UPDATE %s SET", user_table);
-
-       comma="";
-
-       if (clear_field && *clear_field)
+       if (!chpass_clause) /*[EMAIL PROTECTED] */
        {
-               char *q;
 
-               strcat(strcat(strcat(sql_buf, " "), clear_field),
+               sprintf(sql_buf, "UPDATE %s SET", user_table);
+               
+               comma="";
+               
+               if (clear_field && *clear_field)
+               {
+                       char *q;
+       
+                       strcat(strcat(strcat(sql_buf, " "), clear_field),
+                              "='");
+       
+                       q=sql_buf+strlen(sql_buf);
+                       while (*pass)
+                       {
+                               if (*pass == '"' || *pass == '\\')
+                                       *q++= '\\';
+                               *q++ = *pass++;
+                       }
+                       strcpy(q, "'");
+                       comma=", ";
+               }
+       
+               if (crypt_field && *crypt_field)
+               {
+                       strcat(strcat(strcat(strcat(strcat(strcat(sql_buf, comma),
+                                                          " "),
+                                                   crypt_field),
+                                            "='"),
+                                     newpass_crypt_ptr),
+                              "'");
+               }
+               free(newpass_crypt);
+       
+               strcat(strcat(strcat(sql_buf, " WHERE "),
+                             login_field),
                       "='");
-
-               q=sql_buf+strlen(sql_buf);
-               while (*pass)
+       
+               append_username(sql_buf+strlen(sql_buf), user, defdomain);
+       
+               strcat(sql_buf, "'");
+       
+               if (where_clause && *where_clause)
                {
-                       if (*pass == '"' || *pass == '\\')
-                               *q++= '\\';
-                       *q++ = *pass++;
+                       strcat(sql_buf, " AND (");
+                       strcat(sql_buf, where_clause);
+                       strcat(sql_buf, ")");
                }
-               strcpy(q, "'");
-               comma=", ";
-       }
-
-       if (crypt_field && *crypt_field)
-       {
-               strcat(strcat(strcat(strcat(strcat(strcat(sql_buf, comma),
-                                                  " "),
-                                           crypt_field),
-                                    "='"),
-                             newpass_crypt_ptr),
-                      "'");
-       }
-       free(newpass_crypt);
-
-       strcat(strcat(strcat(sql_buf, " WHERE "),
-                     login_field),
-              "='");
 
-       append_username(sql_buf+strlen(sql_buf), user, defdomain);
-
-       strcat(sql_buf, "'");
-
-       if (where_clause && *where_clause)
-       {
-               strcat(sql_buf, " AND (");
-               strcat(sql_buf, where_clause);
-               strcat(sql_buf, ")");
-       }
+       } /* end of: if (!chpass_clause) */
+       
 
        pgresult=PQexec (pgconn, sql_buf);
        if (!pgresult || PQresultStatus(pgresult) != PGRES_COMMAND_OK)
diff -ur --new-file courier-imap-1.4.2/authlib/authpgsqlrc 
courier-imap-1.4.2-moq-pgport/authlib/authpgsqlrc
--- courier-imap-1.4.2/authlib/authpgsqlrc      Sun Oct  7 19:32:56 2001
+++ courier-imap-1.4.2-moq-pgport/authlib/authpgsqlrc   Sun Feb 24 16:02:36 2002
@@ -134,4 +134,65 @@
 #
 # PGSQL_WHERE_CLAUSE   server='mailhost.example.com'
 
-
+##NAME: PGSQL_SELECT_CLAUSE:0
+#
+# (EXPERIMENTAL)
+# This is optional, PGSQL_SELECT_CLAUSE can be set when you have a database,
+# which is structuraly different from proposed. The fixed string will
+# be used to do a SELECT operation on database, which should return fields
+# in order specified bellow:
+#
+# username, cryptpw, clearpw, uid, gid, home, maildir, quota, fullname
+#
+# Enabling this option causes ignorance of any other field-related
+# options, excluding default domain.
+#
+# There are two variables, which you can use. Substitution will be made
+# for them, so you can put entered username (local part) and domain name
+# in the right place of your query. These variables are:
+#               $(local_part) and $(domain)
+#
+# If a $(domain) is empty (not given by the remote user) the default domain
+# name is used in its place.
+#
+# This example is a little bit modified adaptation of vmail-sql
+# database scheme:
+#
+# PGSQL_SELECT_CLAUSE  SELECT popbox.local_part,                       \
+#                      '{MD5}'||popbox.password_hash,                  \
+#                      popbox.clearpw,                                 \
+#                      domain.uid,                                     \
+#                      domain.gid,                                     \
+#                      domain.path||'/'||popbox.mbox_name,             \
+#                      '',                                             \
+#                      domain.quota,                                   \
+#                      ''                                              \
+#                      FROM popbox, domain                             \
+#                      WHERE popbox.local_part = '$(local_part)'       \
+#                      AND popbox.domain_name = '$(domain)'            \
+#                      AND popbox.domain_name = domain.domain_name
+#
+##NAME: MYSQL_CHPASS_CLAUSE:0
+#
+# (EXPERIMENTAL)
+# This is optional, MYSQL_CHPASS_CLAUSE can be set when you have a database,
+# which is structuraly different from proposed. The fixed string will
+# be used to do an UPDATE operation on database. In other words, it is
+# used, when changing password.
+#
+# There are four variables, which you can use. Substitution will be made
+# for them, so you can put entered username (local part) and domain name
+# in the right place of your query. There variables are:
+#       $(local_part) , $(domain) , $(newpass) , $(newpass_crypt)
+#
+# If a $(domain) is empty (not given by the remote user) the default domain
+# name is used in its place.
+# $(newpass) contains plain password
+# $(newpass_crypt) contains its crypted form
+# 
+# MYSQL_CHPASS_CLAUSE  UPDATE  popbox                                  \
+#                      SET     clearpw='$(newpass)',                   \
+#                              password_hash='$(newpass_crypt)'        \
+#                      WHERE   local_part='$(local_part)'              \
+#                      AND     domain_name='$(domain)'
+#


_______________________________________________
courier-users mailing list
[EMAIL PROTECTED]
Unsubscribe: https://lists.sourceforge.net/lists/listinfo/courier-users

Reply via email to