#!/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");
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();
convert_relayqueue();
convert_session();
sequences();
-grants();
print("Disconnecting\n");
pg_close($pdb);
---- $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;
---
--- 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
-/* $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
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 $");
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)",
"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");
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);
}
-/* $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
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 $");
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);
}
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;
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;
!= 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;
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);
}