From: Tony L. <ton...@us...> - 2004-04-03 22:09:01
|
Update of /cvsroot/serverfilters/script In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv20340 Modified Files: Makefile checkcreds_cclient.c filtercmd.c test.sh Log Message: * Enhanced FREEBSD compatibility (patches contributed by st...@sm...) * Debug option now run-time (FILTERCMDDEBUG envar) instead of compile-time * $cclient_mailboxflags run-time option * $imapPort read from config file Index: test.sh =================================================================== RCS file: /cvsroot/serverfilters/script/test.sh,v retrieving revision 1.7 retrieving revision 1.8 diff -C2 -d -r1.7 -r1.8 *** test.sh 2 Mar 2004 02:56:02 -0000 1.7 --- test.sh 3 Apr 2004 21:56:36 -0000 1.8 *************** *** 17,36 **** cd $RUNFROM cat $SCRIPTDIR/test_creds | $SCRIPTDIR/filtercmd getrc filter > $SCRIPTDIR/filter; ! if [ $? == '0' ] ; then echo "Pass: Filter get" else ! echo "RESULT:" $? fi; cp $SCRIPTDIR/filter $SCRIPTDIR/filter.orig echo '# filtercmd testing ' >> $SCRIPTDIR/filter cat $SCRIPTDIR/test_creds $SCRIPTDIR/filter | $SCRIPTDIR/filtercmd putrc filter; ! rm $SCRIPTDIR/filter ! if [ $? == '0' ] ; then echo "Pass: Filter put" else ! echo "RESULT:" $? fi; cat $SCRIPTDIR/test_creds | $SCRIPTDIR/filtercmd getrc filter > $SCRIPTDIR/filter; ! if [ $? == '0' ] ; then command=`grep "filtercmd testing" $SCRIPTDIR/filter`; if [ -n "$command" ] ; then --- 17,39 ---- cd $RUNFROM cat $SCRIPTDIR/test_creds | $SCRIPTDIR/filtercmd getrc filter > $SCRIPTDIR/filter; ! xx=$? ! if [ $xx -eq '0' ] ; then echo "Pass: Filter get" else ! echo "RESULT:" $xx fi; cp $SCRIPTDIR/filter $SCRIPTDIR/filter.orig echo '# filtercmd testing ' >> $SCRIPTDIR/filter cat $SCRIPTDIR/test_creds $SCRIPTDIR/filter | $SCRIPTDIR/filtercmd putrc filter; ! xx=$? ! if [ $xx -eq '0' ] ; then echo "Pass: Filter put" else ! echo "RESULT:" $xx fi; + rm $SCRIPTDIR/filter cat $SCRIPTDIR/test_creds | $SCRIPTDIR/filtercmd getrc filter > $SCRIPTDIR/filter; ! xx=$? ! if [ $xx -eq '0' ] ; then command=`grep "filtercmd testing" $SCRIPTDIR/filter`; if [ -n "$command" ] ; then *************** *** 43,47 **** fi; else ! echo "RESULT:" $? fi; --- 46,50 ---- fi; else ! echo "RESULT:" $xx fi; *************** *** 54,58 **** done; ! if [ $REMOVE == 'y' ] || [ $REMOVE == 'Y' ] ; then rm $SCRIPTDIR/test_creds fi; --- 57,61 ---- done; ! if [ $REMOVE = 'y' ] || [ $REMOVE = 'Y' ] ; then rm $SCRIPTDIR/test_creds fi; Index: checkcreds_cclient.c =================================================================== RCS file: /cvsroot/serverfilters/script/checkcreds_cclient.c,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** checkcreds_cclient.c 1 Mar 2004 01:20:24 -0000 1.3 --- checkcreds_cclient.c 3 Apr 2004 21:56:36 -0000 1.4 *************** *** 4,7 **** --- 4,9 ---- */ + #include <stdio.h> + // error definitions #include "filtercmd.h" *************** *** 11,23 **** #ifndef MAILBOXFLAGS ! #define MAILBOXFLAGS "/norsh/notls" #endif static char *callback_user, *callback_passwd; ! int checkcredentials(imapserver, user, passwd) char *imapserver; char *user; char *passwd; { char mailboxname[MAILTMPLEN]; --- 13,28 ---- #ifndef MAILBOXFLAGS ! #define MAILBOXFLAGS "/norsh" #endif static char *callback_user, *callback_passwd; + char *checkcreds_extra_configvar = "$cclient_mailboxflags"; ! int checkcredentials(imapserver, imapport, user, passwd, extra) char *imapserver; + int imapport; char *user; char *passwd; + char *extra; { char mailboxname[MAILTMPLEN]; *************** *** 49,53 **** mail_parameters(NIL, SET_MAXLOGINTRIALS, (void*)1); ! snprintf(mailboxname, MAILTMPLEN, "{%s/service=imap/user=\"%s\"" MAILBOXFLAGS "}INBOX", imapserver, user); stream = mail_open(NIL, mailboxname, NIL); --- 54,67 ---- mail_parameters(NIL, SET_MAXLOGINTRIALS, (void*)1); ! /* extra may be null (if configvar was not set) */ ! if (!extra) extra = ""; ! ! snprintf(mailboxname, MAILTMPLEN, ! "{%s:%d/service=imap/user=%s" MAILBOXFLAGS "%s}INBOX", ! imapserver, imapport, user, extra); ! ! if (debugon()) { ! fprintf(stderr, "c-client mailboxname: %s\n", mailboxname); ! } stream = mail_open(NIL, mailboxname, NIL); *************** *** 61,70 **** } ! /* we must store user and password when this is called */ void mm_login (NETMBX *mb,char *user,char *pwd,long trial) { ! #ifdef DEBUG ! fprintf(stderr, "mm_login: {%s/%s/user=\"%s\"}\n",mb->host,mb->service,mb->user); ! fprintf(stderr, "mm_login -> %s %s\n", callback_user, callback_passwd); ! #endif strncpy(user, callback_user, MAILTMPLEN); --- 75,84 ---- } ! /* we must store user and password when this is called by the c-client library */ void mm_login (NETMBX *mb,char *user,char *pwd,long trial) { ! if (debugon()) { ! fprintf(stderr, "mm_login: {%s/%s/user=\"%s\"}\n",mb->host,mb->service,mb->user); ! fprintf(stderr, "mm_login -> %s %s\n", callback_user, callback_passwd); ! } strncpy(user, callback_user, MAILTMPLEN); *************** *** 72,86 **** } void mm_log (char *string,long errflg) { ! #ifdef DEBUG ! char *errflgname; ! switch ((short) errflg) { ! case NIL: errflgname = "NIL"; break; ! case PARSE: errflgname = "PARSE"; break; ! case WARN: errflgname = "WARN"; break; ! case ERROR: errflgname = "ERROR"; break; ! default: errflgname = "?"; break; ! }; ! fprintf(stderr, "mm_log: %s: %s\n", errflgname, string); ! #endif } void mm_notify (MAILSTREAM *stream,char *string,long errflg) { --- 86,100 ---- } void mm_log (char *string,long errflg) { ! char *errflgname; ! switch ((short) errflg) { ! case NIL: errflgname = "NIL"; break; ! case PARSE: errflgname = "PARSE"; break; ! case WARN: errflgname = "WARN"; break; ! case ERROR: errflgname = "ERROR"; break; ! default: errflgname = "?"; break; ! } ! if (debugon()) { ! fprintf(stderr, "mm_log: %s: %s\n", errflgname, string); ! } } void mm_notify (MAILSTREAM *stream,char *string,long errflg) { Index: Makefile =================================================================== RCS file: /cvsroot/serverfilters/script/Makefile,v retrieving revision 1.7 retrieving revision 1.8 diff -C2 -d -r1.7 -r1.8 *** Makefile 2 Mar 2004 03:24:19 -0000 1.7 --- Makefile 3 Apr 2004 21:56:36 -0000 1.8 *************** *** 7,11 **** # change this to match the group your HTTPD server runs as. # The resulting binary will be owned by this group. ! HTTPD_GROUP=apache # If you are having problems connecting, recompile with this --- 7,11 ---- # change this to match the group your HTTPD server runs as. # The resulting binary will be owned by this group. ! HTTPD_GROUP=http # If you are having problems connecting, recompile with this Index: filtercmd.c =================================================================== RCS file: /cvsroot/serverfilters/script/filtercmd.c,v retrieving revision 1.14 retrieving revision 1.15 diff -C2 -d -r1.14 -r1.15 *** filtercmd.c 1 Mar 2004 16:16:36 -0000 1.14 --- filtercmd.c 3 Apr 2004 21:56:36 -0000 1.15 *************** *** 24,29 **** * * The putrc command will read an rc file from standard input, after ! * reading the credentials, and replace the existing rcfile. Note: the use ! * of two input-redirections is intended to indicate that the * * The rcexists command will return a zero exit status if the rc file exists, --- 24,28 ---- * * The putrc command will read an rc file from standard input, after ! * reading the credentials, and replace the existing rcfile. * * The rcexists command will return a zero exit status if the rc file exists, *************** *** 88,91 **** --- 87,93 ---- * DIAGNOSTICS * + * Setting an environment variable FILTERCMDDEBUG to 1 will + * cause debugging output to be printed. + * * filtercmd will exit with a non-zero status if an error occurs. * filtercmd will write text to standard error in the case of *************** *** 96,102 **** #define STR_MAX 1024 #define MAXLEN 1024 ! ! /* define DEBUG for debugging output */ ! /* #define DEBUG */ /* define this in filtercmd.opts */ --- 98,102 ---- #define STR_MAX 1024 #define MAXLEN 1024 ! #define VERSION "filtercmd 1.41, part of serversidefilter for squirrelmail" /* define this in filtercmd.opts */ *************** *** 109,112 **** --- 109,113 ---- #include <stdio.h> + #include <stdlib.h> #include <string.h> #include <unistd.h> *************** *** 116,121 **** #include "filtercmd.h" ! /* externally defined functions */ ! int checkcredentials(char*, char*, char*); /* global variables -- used in path calculation code (findfilterfile) */ --- 117,123 ---- #include "filtercmd.h" ! /* externally defined functions and variables */ ! extern char *checkcreds_extra_configvar; ! int checkcredentials(char*, int, char*, char*, char*); /* global variables -- used in path calculation code (findfilterfile) */ *************** *** 126,129 **** --- 128,136 ---- char *domain; /* The domain of the IMAP username */ + /* function prototypes */ + void eperror(register char *s, int exitcode); + void setdebug(int *argc, char ***argv); + void printversion(); + int main(int argc, char *argv[]){ /* *************** *** 139,154 **** char temp_file[STR_MAX]; char imap_server[STR_MAX]; uid_t UID; gid_t GID; err = readcredentials(user, passwd, STR_MAX); if (err) return inerror(err); ! err = readimapserver(imap_server, STR_MAX); if (err) return inerror(err); ! #ifdef DEBUG ! fprintf(stderr, "user: %s\n", user); ! #endif if (splitdomain(user, &domain, dom_user, STR_MAX)) { --- 146,171 ---- char temp_file[STR_MAX]; char imap_server[STR_MAX]; + char checkcreds_extra[STR_MAX] = ""; + int imap_port; uid_t UID; gid_t GID; + setdebug(&argc, &argv); + + /* look for the "version" command early */ + if (argc > 1 && !strcmp("version", argv[1])) { + printversion(); + return ERR_OK; + } + err = readcredentials(user, passwd, STR_MAX); if (err) return inerror(err); ! err = readimapserver(imap_server, &imap_port, STR_MAX); if (err) return inerror(err); ! if (debugon()) { ! fprintf(stderr, "imap user validated: %s\n", user); ! } if (splitdomain(user, &domain, dom_user, STR_MAX)) { *************** *** 160,167 **** } ! #ifdef DEBUG ! fprintf(stderr, "domain: %s\n", domain); ! fprintf(stderr, "dom_user: %s\n", dom_user); ! #endif err = finduidgid(real_user, &UID, &GID); --- 177,184 ---- } ! if (debugon()) { ! fprintf(stderr, "domain: %s\n", domain); ! fprintf(stderr, "dom_user: %s\n", dom_user); ! } err = finduidgid(real_user, &UID, &GID); *************** *** 171,175 **** if((setuid(UID)) < 0) eperror("setuid", ERR_NOT_SUID); ! err = checkcredentials(imap_server, user, passwd); if (err) return inerror(err); --- 188,197 ---- if((setuid(UID)) < 0) eperror("setuid", ERR_NOT_SUID); ! if (checkcreds_extra_configvar) { ! readconfigvar(SERVERSIDEFILTERHOME "/config.php", checkcreds_extra_configvar, ! checkcreds_extra, STR_MAX); ! } ! ! err = checkcredentials(imap_server, imap_port, user, passwd, checkcreds_extra); if (err) return inerror(err); *************** *** 242,245 **** --- 264,298 ---- } + static int _debuglevel = 0; + int debugon() { + return _debuglevel; + } + + /* + * Figure out from the environment/arguments what the current debug level + * should be. Currently this only reads the environment. Pointers to argc and + * argv are provided, so that this routine can (in the future) remove any + * debug-related arguments. + * + * Parameters: + * argc - IN/OUT. + * argv - IN/OUT. + */ + void setdebug(int *argc, char ***argv) { + char *FILTERCMDDEBUG; + FILTERCMDDEBUG = getenv("FILTERCMDDEBUG"); + if (FILTERCMDDEBUG) { + sscanf(FILTERCMDDEBUG, "%d", &_debuglevel); + } + } + + void printversion() { + puts( VERSION "\n" + "\n" + "Compile-time definitions:\n" + "\tSQUIRRELMAILCONFIGFILE: " SQUIRRELMAILCONFIGFILE "\n" + "\tSERVERSIDEFILTERHOME: " SERVERSIDEFILTERHOME "\n" + ); + } /* *************** *** 282,286 **** /* ! * Reads IMAP server information from SQUIRRELMAILCONFIGFILE. * * Parameters: --- 335,342 ---- /* ! * Reads IMAP server information from SQUIRRELMAILCONFIGFILE. Also ! * reads the port. The routine is not fussy about finding a port ! * specification in the file -- it will just set a useful default if ! * there are issues. * * Parameters: *************** *** 288,299 **** * serverlen - IN. buffer size of the server buffer. * Returns: ! * ERR_OK if it found all the parameters, an error code if not. */ ! int readimapserver(server, serverlen) ! char *server; ! int serverlen; { int foundserver; foundserver = readconfigvar(SQUIRRELMAILCONFIGFILE, "$imapServerAddress", server, serverlen); return foundserver ? ERR_OK : ERR_CANT_READ_IMAP_SERVER; --- 344,360 ---- * serverlen - IN. buffer size of the server buffer. * Returns: ! * ERR_OK if it found the necessary parameters, an error code if not. */ ! int readimapserver(char *server, int *port, int serverlen) { int foundserver; + char port_str[STR_MAX]; + + *port = 143; /* a useful default */ + if (readconfigvar(SQUIRRELMAILCONFIGFILE, "$imapPort", port_str, STR_MAX)) { + sscanf(port_str, "%d", port); + } + foundserver = readconfigvar(SQUIRRELMAILCONFIGFILE, "$imapServerAddress", server, serverlen); return foundserver ? ERR_OK : ERR_CANT_READ_IMAP_SERVER; *************** *** 323,329 **** if (err) return err; while (fgets(line, STR_MAX, f)) { ! /*fprintf(stderr, "config: %s", line);*/ ! if (!found) ! found = parsephpstring(phpvar, line, outbuf, outbuflen); } return found; --- 384,392 ---- if (err) return err; while (fgets(line, STR_MAX, f)) { ! found = parsephpstring(phpvar, line, outbuf, outbuflen); ! if (found) break; ! } ! if (debugon()) { ! fprintf(stderr, "config: %s %s -> %d\n", configfile, phpvar, found); } return found; *************** *** 361,368 **** /* ! * Looks for a given varname in a line of PHP code; if it is found, the ! * code will try to parse out the value between quotes. This funtion is ! * easily confused and when it returns 1 it means the variable was found, ! * not necessarily that the string contents were successfully passed. * * Parameters: --- 424,431 ---- /* ! * Looks for a given varname in a line of PHP code; if it is found, the code ! * will try to parse out the number or string between quotes. This function ! * is easily confused and when it returns 1 it means the variable was found, ! * not necessarily that the string contents were successfully parsed. * * Parameters: *************** *** 394,400 **** if (commentpos && commentpos < s) return 0; ! /* skip ahead to either ' or " */ ! s += strcspn(s, "\"'\0\n") + 1; ! n = strcspn(s, "\"'\0\n"); if (n > destlen) n = destlen; strncpy(dest, s, n); --- 457,471 ---- if (commentpos && commentpos < s) return 0; ! /* skip ahead to either ' or " or a number */ ! s += strcspn(s, "\"'0123456789\0\n"); ! if (strchr("0123456789", *s)) { ! /* found number - now find semicolon, space or EOL */ ! n = strcspn(s, "; \0\n"); ! } else { ! /* found quote - now find next quote or EOL */ ! /* this does not find matching quotes */ ! s++; ! n = strcspn(s, "\"'\0\n"); ! } if (n > destlen) n = destlen; strncpy(dest, s, n); *************** *** 664,668 **** do { if (stat(filepath, &buf)) ! eperror(filepath); if (buf.st_mode & S_IWOTH) return trusted_error("writable by others", curpath, filepath); --- 735,739 ---- do { if (stat(filepath, &buf)) ! eperror(filepath, ERR_CANT_TRUST_FILE); if (buf.st_mode & S_IWOTH) return trusted_error("writable by others", curpath, filepath); |