From: <ton...@us...> - 2004-02-29 23:15:29
|
Update of /cvsroot/serverfilters/script In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv14698 Modified Files: filtercmd.c checkcreds_cclient.c Log Message: Fixes/cleanups Index: filtercmd.c =================================================================== RCS file: /cvsroot/serverfilters/script/filtercmd.c,v retrieving revision 1.8 retrieving revision 1.9 diff -C2 -d -r1.8 -r1.9 *** filtercmd.c 23 Feb 2004 17:07:57 -0000 1.8 --- filtercmd.c 29 Feb 2004 22:57:04 -0000 1.9 *************** *** 98,109 **** /* define DEBUG for debugging output */ ! #define DEBUG /* define this in filtercmd.opts */ ! #ifndef CONFIGFILE ! #define CONFIGFILE "/etc/squirrelmail/config.php" #endif #ifndef SERVERSIDEFILTERHOME ! #define SERVERSIDEFILTERHOME "/usr/share/squirrelmail/plugins/serversidefilter/" #endif --- 98,109 ---- /* define DEBUG for debugging output */ ! /* #define DEBUG */ /* define this in filtercmd.opts */ ! #ifndef SQUIRRELMAILCONFIGFILE ! #define SQUIRRELMAILCONFIGFILE "/etc/squirrelmail/config.php" #endif #ifndef SERVERSIDEFILTERHOME ! #define SERVERSIDEFILTERHOME "../plugins/serversidefilter/" #endif *************** *** 116,131 **** #include "filtercmd.h" ! void eperror(register char *); ! int rcexists(char *); ! int getrc(char*); ! int putrc(char*, uid_t, gid_t); ! int copy_file(char*, FILE*, char*, FILE*); int checkcredentials(char*, char*, char*); ! ! /* global variables -- used in path calculation code */ ! char user[STR_MAX]; ! char real_user[STR_MAX]; ! char *domain; int main(int argc, char *argv[]){ --- 116,128 ---- #include "filtercmd.h" ! /* externally defined functions */ int checkcredentials(char*, char*, char*); ! /* global variables -- used in path calculation code (findfilterfile) */ ! char separator[2] = "@"; /* the separator character */ ! char user[STR_MAX]; /* IMAP username possibly including domain name */ ! char real_user[STR_MAX]; /* real unix user */ ! char dom_user[STR_MAX]; /* IMAP username, sans any domain name */ ! char *domain; /* The domain of the IMAP username */ int main(int argc, char *argv[]){ *************** *** 151,157 **** if (err) return inerror(err); ! err = readvirtualdomain(user, real_user, STR_MAX); ! if (err) return inerror(err); ! err = finduidgid(real_user, &UID, &GID); if (err) return inerror(err); --- 148,168 ---- if (err) return inerror(err); ! #ifdef DEBUG ! fprintf(stderr, "user: %s\n", user); ! #endif ! ! if (splitdomain(user, &domain, dom_user, STR_MAX)) { ! err = readvirtualdomain(domain, real_user, STR_MAX); ! if (err) return inerror(err); ! } else { ! /* without domain mapping file, assume IMAP username is a real unix username */ ! strncpy(real_user, user, STR_MAX); ! } ! ! #ifdef DEBUG ! fprintf(stderr, "domain: %s\n", domain); ! fprintf(stderr, "dom_user: %s\n", dom_user); ! #endif ! err = finduidgid(real_user, &UID, &GID); if (err) return inerror(err); *************** *** 272,276 **** /* ! * Reads IMAP server information from CONFIGFILE. * * Parameters: --- 283,287 ---- /* ! * Reads IMAP server information from SQUIRRELMAILCONFIGFILE. * * Parameters: *************** *** 286,295 **** { int foundserver; ! foundserver = readconfigvar(CONFIGFILE, "$imapServerAddress", server, serverlen); return foundserver ? ERR_OK : ERR_CANT_READ_IMAP_SERVER; } /* ! * Reads a setting from CONFIGFILE. * * Parameters: --- 297,306 ---- { int foundserver; ! foundserver = readconfigvar(SQUIRRELMAILCONFIGFILE, "$imapServerAddress", server, serverlen); return foundserver ? ERR_OK : ERR_CANT_READ_IMAP_SERVER; } /* ! * Reads a setting from a config file. * * Parameters: *************** *** 379,390 **** if (s == NULL) return 0; ! /* look for // comment marker */ ! commentpos = strstr(line, "//"); if (commentpos && commentpos < s) return 0; - #ifdef DEBUG - /*fprintf(stderr, "parsephpstring: varname=%s line=%s", varname, line);*/ - #endif - /* skip ahead to either ' or " */ s += strcspn(s, "\"'\0\n") + 1; --- 390,398 ---- if (s == NULL) return 0; ! /* look for // comment marker, making sure the // can't be ! treated as a comment by the compiler */ ! commentpos = strstr(line, "/" "/"); if (commentpos && commentpos < s) return 0; /* skip ahead to either ' or " */ s += strcspn(s, "\"'\0\n") + 1; *************** *** 394,401 **** dest[n] = '\0'; - #ifdef DEBUG - /*fprintf(stderr, "parsephpstring -> %s\n", dest);*/ - #endif - return 1; } --- 402,405 ---- *************** *** 473,495 **** int findfilterfile(char *filter_type, char *filter_file, int buflen) { int err; - char *tmp; - char *dom_user; err = findfilterpath(filter_type, filter_file, buflen); if (err) return err; fprintf(stderr, "filter_file: %s\n", filter_file); ! ! /* TODO: these need to be replaced with global variable references */ ! strcpy(dom_user, user); ! tmp = index(dom_user, '@'); ! *tmp = '\0'; ! replace(filter_file, buflen, "[USERNAME]",dom_user); ! replace(filter_file, buflen, "[DOMAIN]", domain ? domain : ""); ! replace(filter_file, buflen, "[DOMUSER]", real_user); ! /* DEBUG */ fprintf(stderr, "filter_file: %s\n", filter_file); } --- 477,498 ---- int findfilterfile(char *filter_type, char *filter_file, int buflen) { int err; err = findfilterpath(filter_type, filter_file, buflen); if (err) return err; + #ifdef DEBUG fprintf(stderr, "filter_file: %s\n", filter_file); ! fprintf(stderr, "dom_user: %s\n", dom_user); ! fprintf(stderr, "domain: %s\n", domain); ! fprintf(stderr, "real_user: %s\n", real_user); ! #endif ! replace(filter_file, buflen, "[USERNAME]", dom_user); ! replace(filter_file, buflen, "[DOMAIN]", domain); ! replace(filter_file, buflen, "[DOMUSER]", real_user); ! #ifdef DEBUG fprintf(stderr, "filter_file: %s\n", filter_file); + #endif } *************** *** 554,571 **** } ! int readvirtualdomain(char *user, char *real_user, int buflen) { FILE *f; char line[STR_MAX]; char *colon, *s; int err; ! ! domain = strchr(user, '@'); ! if (domain == NULL) { ! /* no at sign in username implies no virtual domain -- not necessarily correct */ ! strncpy(real_user, user, buflen); ! return ERR_OK; ! } ! domain++; ! /* find the first line with a colon that matches the domain up to the colon. * copy the rest of the line (or up to another colon) into the real_user --- 557,617 ---- } ! ! /* ! * Handles splitting a user into a username and a domain. ! * ! * Globals: ! * separator - IN. This should be a one-character string, usually "@" ! * Parameters: ! * user - IN. This can possibly contain the separator character. ! * domain - OUT. This pointer will be set to part of the dom_user buffer. ! * dom_user - OUT. This buffer will be set to the first part of the user. ! * buflen - IN. Length of the dom_user buffer. ! * Returns: ! * 1 if the user contained the separator character, 0 if not. ! */ ! int splitdomain(char *user, char** domain, char* dom_user, int buflen) { ! char *dom; ! strncpy(dom_user, user, buflen); ! dom = strchr(dom_user, separator[0]); ! #ifdef DEBUG ! fprintf(stderr, "user:%s dom_user:%s dom:%s buflen:%d\n", user, dom_user, dom, buflen); ! #endif ! if (dom == NULL) { ! /* no at sign in username implies no virtual domain. */ ! /* make domain be the empty string */ ! dom = dom_user + strlen(dom_user); ! *domain = dom; ! return 0; ! } else { ! /* terminate the dom_user string at the separator and ! make domain point to the rest of the string */ ! #ifdef DEBUG ! fprintf(stderr, "user:%s dom_user:%s dom:%s\n", user, dom_user, dom); ! #endif ! ! *dom = '\0'; ! (*dom)++; ! *domain = dom; ! return 1; ! } ! } ! ! /* ! * Reads the virtualdomain file to find the real unix user name for a domain. ! * ! * Parameters: ! * domain - IN. The domain name. ! * real_user - OUT. This buffer will be set to the real unix username. ! * buflen - IN. Length of the real_user buffer. ! * Returns: ! * ERR_OK if an entry was found, an error message if not. ! */ ! int readvirtualdomain(char *domain, char *real_user, int buflen) { FILE *f; char line[STR_MAX]; char *colon, *s; int err; ! /* find the first line with a colon that matches the domain up to the colon. * copy the rest of the line (or up to another colon) into the real_user *************** *** 593,597 **** } ! /* open a file while verifying that it is sufficiently protected so that * we can trust its contents. That means the file must be owned by root, * and either not group readable or be in root's group. The same test is --- 639,643 ---- } ! /* Open a file while verifying that it is sufficiently protected so that * we can trust its contents. That means the file must be owned by root, * and either not group readable or be in root's group. The same test is *************** *** 628,635 **** *ix = '\0'; } while (1); ! } int trusted_error(char *err, char *path, char *file) { fprintf(stderr, "trust error on %s while checking %s\n %s\n", path, file, err); return ERR_CANT_TRUST_FILE; } --- 674,683 ---- *ix = '\0'; } while (1); ! } int trusted_error(char *err, char *path, char *file) { + #ifdef DEBUG fprintf(stderr, "trust error on %s while checking %s\n %s\n", path, file, err); + #endif return ERR_CANT_TRUST_FILE; } Index: checkcreds_cclient.c =================================================================== RCS file: /cvsroot/serverfilters/script/checkcreds_cclient.c,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** checkcreds_cclient.c 14 Dec 2003 20:55:27 -0000 1.1 --- checkcreds_cclient.c 29 Feb 2004 22:57:04 -0000 1.2 *************** *** 10,13 **** --- 10,17 ---- #include MAIL_H + #ifndef MAILBOXFLAGS + #define MAILBOXFLAGS "/norsh/notls" + #endif + static char *callback_user, *callback_passwd; *************** *** 45,49 **** mail_parameters(NIL, SET_MAXLOGINTRIALS, (void*)1); ! snprintf(mailboxname, MAILTMPLEN, "{%s/norsh/service=imap/user=\"%s\"}INBOX", imapserver, user); stream = mail_open(NIL, mailboxname, NIL); --- 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); |