I've attached the limits.c file. It should be more robust and "create" the table if its not there. Brian > > Hi Brian > > > I've updated my copy of qmailadmin that loads > > the limits from mysql already, if interested... > Yes, I'm, can you send me the source ? > > > > - I was looking the code to add this feature, too > > Pablo Murillo > [EMAIL PROTECTED] > ====================== > RED NET ARGENTINA > Internet Solutions > ====================== > Paraguay 419 Piso 2 Of.5 > (C1057AAC) - Capital > Buenos Aires - Argentina > Tel & Fax:(011)4315-3269 > http://rednet.com.ar > ====================== > > >
/* * QmailAdmin * Copyright (C) 1999 Inter7 Internet Technologies, Inc. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA */ #include <stdio.h> #include <stdlib.h> #include <string.h> #include <unistd.h> #include <sys/stat.h> #include <unistd.h> #include <pwd.h> #include <dirent.h> #include <errno.h> #include "config.h" #include "qmailadmin.h" #include "qmailadminx.h" /* bk: */ #include <mysql.h> #define USE_MYSQL #define MYSQL_SERVER "localhost" #define MYSQL_USER "mysqluser" #define MYSQL_PASSWD "mysqlpass" #define MYSQL_DATABASE "vpopmail" #define DEFAULT_MAX_DISKQUOTA 50 int MaxDiskQuota = DEFAULT_MAX_DISKQUOTA; static MYSQL mysql; static MYSQL_RES * res; static MYSQL_ROW row; #ifdef USE_MYSQL int load_limits() { FILE *fs; char *tmpstr; char buf[1024]; MaxPopAccounts = DEFAULT_MAX_POP_USERS; MaxAliases = DEFAULT_MAX_ALIASES; MaxForwards = DEFAULT_MAX_FORWARDS; MaxAutoResponders = DEFAULT_MAX_AUTORESPONDERS; MaxMailingLists = DEFAULT_MAX_MAILINGLISTS; MaxDiskQuota = DEFAULT_MAX_DISKQUOTA; /* use database */ mysql_init(&mysql); if (!(mysql_real_connect(&mysql,MYSQL_SERVER,MYSQL_USER,MYSQL_PASSWD, MYSQL_DATABASE, 0,NULL,0))) { if (!(mysql_real_connect(&mysql,MYSQL_SERVER,MYSQL_USER,MYSQL_PASSWD, NULL, 0,NULL,0))) { fprintf(stderr, "could not connect to mysql server\n"); return -1; } sprintf(buf, "create database %s", MYSQL_DATABASE); if (mysql_query(&mysql, buf)) { fprintf(stderr, "could not create %s database\n", MYSQL_DATABASE); return -1; } res = mysql_store_result(&mysql); mysql_free_result(res); if (mysql_select_db(&mysql,MYSQL_DATABASE)) { fprintf(stderr, "could not enter %s database\n", MYSQL_DATABASE); return -1; } } sprintf(buf, "SELECT maxpopaccounts, maxaliases, maxforwards, " "maxautoresponders, maxmailinglists, diskquota\n" "FROM limits\n" "WHERE domain = '%s'", Domain); if (mysql_query(&mysql, buf)) { fprintf(stderr, "mysql query failed for domain %s\n", Domain); fprintf(stderr, "query: %s\n", buf); return -1; } if (!(res = mysql_store_result(&mysql))) { fprintf(stderr, "mysql store result failed\n"); return -1; } if (mysql_num_rows(res) == 0) { fprintf(stderr, "mysql can't find limits for domain %s\n", Domain); return -1; } if ((row = mysql_fetch_row(res)) != NULL) { MaxPopAccounts = atoi(row[0]); MaxAliases = atoi(row[1]); MaxForwards = atoi(row[2]); MaxAutoResponders = atoi(row[3]); MaxMailingLists = atoi(row[4]); MaxDiskQuota = atoi(row[5]); } mysql_free_result(res); return 0; } #else int load_limits() { FILE *fs; char *tmpstr; MaxPopAccounts = DEFAULT_MAX_POP_USERS; MaxAliases = DEFAULT_MAX_ALIASES; MaxForwards = DEFAULT_MAX_FORWARDS; MaxAutoResponders = DEFAULT_MAX_AUTORESPONDERS; MaxMailingLists = DEFAULT_MAX_MAILINGLISTS; if ( (fs=fopen(".qmailadmin-limits","r"))==NULL) { return(0); } while( fgets(TmpBuf, MAX_BUFF, fs) != NULL ) { tmpstr = strtok(TmpBuf," :\t\n"); if ( tmpstr == NULL ) continue; if ( strncmp(tmpstr, "maxpopaccounts", 14 ) == 0 ) { tmpstr = strtok(NULL," :\t\n"); if (tmpstr==NULL) continue; MaxPopAccounts = atoi(tmpstr); } else if ( strncmp(tmpstr, "maxaliases", 10 ) == 0 ) { tmpstr = strtok(NULL," :\t\n"); if (tmpstr==NULL) continue; MaxAliases = atoi(tmpstr); } else if ( strncmp(tmpstr, "maxforwards", 11 ) == 0 ) { tmpstr = strtok(NULL," :\t\n"); if (tmpstr==NULL) continue; MaxForwards = atoi(tmpstr); } else if ( strncmp(tmpstr, "maxautoresponders", 17 ) == 0 ) { tmpstr = strtok(NULL," :\t\n"); if (tmpstr==NULL) continue; MaxAutoResponders = atoi(tmpstr); } else if ( strncmp(tmpstr, "maxmailinglists", 15 ) == 0 ) { tmpstr = strtok(NULL," :\t\n"); if (tmpstr==NULL) continue; MaxMailingLists = atoi(tmpstr); } } } #endif