Bugfixes
authorMatthew Mondor <mmondor@pulsar-zone.net>
Fri, 16 Mar 2007 02:06:46 +0000 (02:06 +0000)
committerMatthew Mondor <mmondor@pulsar-zone.net>
Fri, 16 Mar 2007 02:06:46 +0000 (02:06 +0000)
mmsoftware/mmmail/scripts/pgsql-convert.php
mmsoftware/mmmail/scripts/pgsql-tables.sql
mmsoftware/mmmail/src/mmpop3d/mmpop3d.c
mmsoftware/mmmail/src/mmsmtpd/mmsmtpd.c

index 285a6e1..dfdfbf3 100755 (executable)
@@ -1,6 +1,6 @@
 #!/usr/pkg/bin/php
 <?
-/* $Id: pgsql-convert.php,v 1.1.2.1 2007/03/15 04:26:55 mmondor Exp $ */
+/* $Id: pgsql-convert.php,v 1.1.2.2 2007/03/16 02:06:42 mmondor Exp $ */
 
 require_once (".password.php");
 
@@ -201,62 +201,24 @@ function convert_session()
 
 function sequences()
 {
-       $q = "SELECT table_name FROM information_schema.tables" .
-           " WHERE table_schema='public'";
+
+       $q = "SELECT pg_catalog.SETVAL(pg_catalog.PG_GET_SERIAL_SEQUENCE(" .
+           "'mail', 'id'), (SELECT MAX(id) FROM mail), TRUE)";
        print("$q\n");
-       if ((!$res = pg_query($q)))
+       if (!$res = pg_exec($q))
                exit(-1);
-       while ($row = pg_fetch_row($res)) {
-               $q = "SELECT MAX(id) FROM {$row[0]}";
-               print("$q\n");
-               if (($res1 = pg_query($q))) {
-                       $row1 = pg_fetch_row($res1);
-                       $id = $row1[0];
-                       pg_free_result($res1);
-                       $q = "SELECT pg_catalog.setval(pg_catalog." .
-                           "pg_get_serial_sequence(" .
-                           "'{$row[0]}','id'),$id,true)";
-                       print("$q\n");
-                       pg_exec($q);
-                       $q = "VACUUM ANALYZE {$row[0]}";
-                       print("$q\n");
-                       pg_exec($q);
-               }
-       }
-       pg_free_result($res);
-}
 
-function grants()
-{
-       $q = "SELECT table_name FROM information_schema.tables" .
-           " WHERE table_schema='public'";
+       $q = "SELECT pg_catalog.SETVAL(pg_catalog.PG_GET_SERIAL_SEQUENCE(" .
+           "'file_gc_queue', 'id'), (SELECT MAX(id) FROM file_gc_queue), TRUE)";
        print("$q\n");
-       if ((!$res = pg_query($q)))
+       if (!$res = pg_exec($q))
                exit(-1);
-       while ($row = pg_fetch_row($res)) {
-               $q = "GRANT ALL ON {$row[0]} TO mmmail";
-               print("$q\n");
-               pg_exec($q);
-               $q = "GRANT ALL ON {$row[0]}_id_seq TO mmmail";
-               print("$q\n");
-               pg_exec($q);
-       }
-       pg_free_result($res);
 
-       $q = "SELECT table_name FROM information_schema.views" .
-           " WHERE table_schema='public'";
+       $q = "SELECT pg_catalog.SETVAL(pg_catalog.PG_GET_SERIAL_SEQUENCE(" .
+           "'relayqueue', 'id'), (SELECT MAX(id) FROM relayqueue), TRUE)";
        print("$q\n");
-       if ((!$res = pg_query($q)))
+       if (!$res = pg_exec($q))
                exit(-1);
-       while ($row = pg_fetch_row($res)) {
-               $q = "GRANT ALL ON {$row[0]} TO mmmail";
-               print("$q\n");
-               pg_exec($q);
-               $q = "GRANT ALL ON {$row[0]}_id_seq TO mmmail";
-               print("$q\n");
-               pg_exec($q);
-       }
-       pg_free_result($res);
 }
 
 convert_user();
@@ -270,7 +232,6 @@ convert_mail();
 convert_relayqueue();
 convert_session();
 sequences();
-grants();
 
 print("Disconnecting\n");
 pg_close($pdb);
index 106db85..4d5d8d3 100644 (file)
@@ -1,4 +1,4 @@
---- $Id: pgsql-tables.sql,v 1.1.2.7 2007/03/15 17:01:53 mmondor Exp $
+--- $Id: pgsql-tables.sql,v 1.1.2.8 2007/03/16 02:06:43 mmondor Exp $
 
 BEGIN;
 
@@ -246,14 +246,26 @@ CREATE TABLE "session" (
 ---
 --- Utility function to update the user's activity timestamps
 ---
-CREATE FUNCTION user_update(v_user varchar, v_box varchar) RETURNS boolean AS $usager_update$
+CREATE FUNCTION user_update(v_user varchar, v_box varchar) RETURNS boolean AS $user_update$
 BEGIN
        UPDATE box SET time_out = CURRENT_TIMESTAMP WHERE address = v_box;
        UPDATE "user" SET time_activity = CURRENT_TIMESTAMP WHERE id = v_user;
        RETURN TRUE;
 END;
-$usager_update$ LANGUAGE plpgsql;
+$user_update$ LANGUAGE plpgsql;
 
 
 
 COMMIT;
+
+
+
+---
+--- Give necessary privileges to mmmail user
+---
+GRANT ALL ON TABLE alias, box, file_gc_queue, filter, mail, nofrom,
+       relayfrom, relaylocal, relayqueue, session, "user" TO mmmail;
+GRANT ALL ON file_gc_queue_id_seq, mail_id_seq, relayqueue_id_seq TO mmmail;
+GRANT EXECUTE ON FUNCTION box_delete(), mail_add(), mail_delete(),
+       relayqueue_delete(), user_update() TO mmmail;
+--- No views
index ca7d2ba..b984166 100644 (file)
@@ -1,4 +1,4 @@
-/* $Id: mmpop3d.c,v 1.41.4.4 2007/03/15 20:46:26 mmondor Exp $ */
+/* $Id: mmpop3d.c,v 1.41.4.5 2007/03/16 02:06:44 mmondor Exp $ */
 
 /*
  * Copyright (C) 2001-2007, Matthew Mondor
@@ -83,7 +83,7 @@
 
 MMCOPYRIGHT("@(#) Copyright (c) 2001-2007\n\
 \tMatthew Mondor. All rights reserved.\n");
-MMRCSID("$Id: mmpop3d.c,v 1.41.4.4 2007/03/15 20:46:26 mmondor Exp $");
+MMRCSID("$Id: mmpop3d.c,v 1.41.4.5 2007/03/16 02:06:44 mmondor Exp $");
 
 
 
@@ -509,9 +509,8 @@ auth_pass(clientenv *clenv)
                    mm_strcpy(pwhash, PQgetvalue(pgres, 0, 1));
                }
                PQclear(pgres);
-           } else {
-               /* XXX Log */
-           }
+           } else
+               syslog(LOG_NOTICE, "auth_pass() - PQexecParams()");
            if (*pwhash == '\0') {
                /* User does not exist */
                mmsyslog(0, LOGLEVEL, "%08X Failed login for %s (unexisting)",
@@ -535,9 +534,8 @@ auth_pass(clientenv *clenv)
                        "SELECT user_update($1,$2)", 2,
                        NULL, params, NULL, NULL, 0)) != NULL)
                    PQclear(pgres);
-               else {
-                   /* XXX Log */
-               }
+               else
+                   syslog(LOG_NOTICE, "auth_pass() - PQexecParams(2)");
                clenv->login = TRUE;
                if (!do_buildindex(clenv)) {
                    reply(fdb, FALSE, "Error");
@@ -886,7 +884,10 @@ alloc_clientenv(void)
     pthread_mutex_unlock(&clenv_lock);
 
     /* XXX for now */
-    clenv->pgconn = PQconnectdb(CONF.DB_INFO);
+    if ((clenv->pgconn = PQconnectdb(CONF.DB_INFO)) == NULL) {
+       syslog(LOG_NOTICE, "alloc_clientenv() - PQconnectdb()");
+       return free_clientenv(clenv);
+    }
 
     return (clenv);
 }
index 9f82d0e..07c6b94 100644 (file)
@@ -1,4 +1,4 @@
-/* $Id: mmsmtpd.c,v 1.75.4.3 2007/03/15 20:46:28 mmondor Exp $ */
+/* $Id: mmsmtpd.c,v 1.75.4.4 2007/03/16 02:06:46 mmondor Exp $ */
 
 /*
  * Copyright (C) 2001-2007, Matthew Mondor
@@ -82,7 +82,7 @@
 
 MMCOPYRIGHT("@(#) Copyright (c) 2001-2007\n\
 \tMatthew Mondor. All rights reserved.\n");
-MMRCSID("$Id: mmsmtpd.c,v 1.75.4.3 2007/03/15 20:46:28 mmondor Exp $");
+MMRCSID("$Id: mmsmtpd.c,v 1.75.4.4 2007/03/16 02:06:46 mmondor Exp $");
 
 
 
@@ -1160,7 +1160,10 @@ alloc_clientenv(void)
     pthread_mutex_unlock(&clenv_lock);
 
     /* XXX for now */
-    clenv->pgconn = PQconnectdb(CONF.DB_INFO);
+    if ((clenv->pgconn = PQconnectdb(CONF.DB_INFO)) == NULL) {
+       syslog(LOG_NOTICE, "alloc_clientenv() - PQconnectdb()");
+       return free_clientenv(clenv);
+    }
 
     return (clenv);
 }
@@ -1249,7 +1252,7 @@ check_alias(clientenv *clenv, char *addr)
     params[0] = domain;
     params[1] = NULL;
     if ((pgres = PQexecParams(clenv->pgconn,
-           "SELECT pattern,box FROM alias WHERE alias=$1", 1, NULL, params, NULL,
+           "SELECT pattern,box FROM alias WHERE domain=$1", 1, NULL, params, NULL,
            NULL, 0)) != NULL) {
        int             i, t, cur = 0, max = -1;
        const char      *a = NULL;
@@ -2091,8 +2094,7 @@ do_data_queue_box(clientenv *clenv, const char *recvline, size_t recvlen,
            params, NULL, NULL, 0)) != NULL)
        PQclear(pgres);
     else {
-       /* XXX Log */
-       (void) snprintf(path, 255, "%s/%s", CONF.MAIL_DIR, path);
+       syslog(LOG_NOTICE, "do_date_queue_box() - PQexecParams()");
        (void) unlink(path);
 
        return FALSE;
@@ -2142,7 +2144,7 @@ do_data_queue_relay(clientenv *clenv, const char *recvline, size_t recvlen,
                != NULL)
            PQclear(pgres);
        else {
-           /* XXX Log */
+           syslog(LOG_NOTICE, "do_data_queue_relay() - PQexecParams()");
            (void) snprintf(path, 255, "%s/%s", CONF.MAIL_DIR, path);
            (void) unlink(path);
            ok = FALSE;
@@ -2625,7 +2627,7 @@ db_gc_thread(void *args)
     int                rounds;
 
     if ((pgconn = PQconnectdb(CONF.DB_INFO)) == NULL) {
-       syslog(LOG_NOTICE, "Couldn't connect to database!");
+       syslog(LOG_NOTICE, "do_gc_thread() - PQconnectdb()");
        exit(EXIT_FAILURE);
     }