static struct passdb_module * vpopmail_preinit(pool_t pool, const char *args) { static bool vauth_load_initialized = FALSE; struct vpopmail_passdb_module *module; const char *const *tmp; module = p_new(pool, struct vpopmail_passdb_module, 1); module->module.default_pass_scheme = VPOPMAIL_DEFAULT_PASS_SCHEME; module->module.blocking = TRUE; tmp = t_strsplit_spaces(args, " "); for (; *tmp != NULL; tmp++) { if (strncmp(*tmp, "cache_key=", 10) == 0) { module->module.default_cache_key = auth_cache_parse_key(pool, *tmp + 10); } else if (strncmp(*tmp, "webmail=", 8) == 0) { if (net_addr2ip(*tmp + 8, &module->webmail_ip) < 0) i_fatal("vpopmail: Invalid webmail IP address"); } else if (strcmp(*tmp, "blocking=no") == 0) { module->module.blocking = FALSE; } else { i_fatal("passdb vpopmail: Unknown setting: %s", *tmp); } } if (!vauth_load_initialized) { vauth_load_initialized = TRUE; if (vauth_open(0) != 0) i_fatal("vpopmail: vauth_open() failed"); } return &module->module; }
int main(int argc, char *argv[]) { FILE *fsi = NULL; FILE *fsx = NULL; char *domain; char *domain_dir = NULL; static struct stat statbuf; domain_entry *entry; memset(TmpBuf,0,sizeof(TmpBuf)); memset(MsgBuf,0,sizeof(MsgBuf)); Verbose = 0; DoNothing = 0; if ( argc == 1 ) { usage(); vexit(-1); } if( vauth_open( 1 )) { vexiterror( stderr, "Initial open." ); } get_options(argc,argv); getcwd(CurDir,sizeof(CurDir)); if ( EmailFileFlag == 1 ) { if ( (fsi = fopen(EmailFile, "r")) == NULL ) { fprintf(stderr, "Could not open file %s\n", EmailFile); vexit(-1); } else { /* make sure the file size is not 0 */ stat(EmailFile, &statbuf); if(statbuf.st_size == 0) { fprintf(stderr, "Error: %s is empty\n", EmailFile); vexit(-1); } /* check for existing date header */ while (fgets (TmpBuf, sizeof(TmpBuf), fsi) != NULL) { /* check for end of headers (blank line) */ if (*TmpBuf == '\n') break; if (strncasecmp ("Date: ", TmpBuf, 6) == 0) { InsertDate = 0; break; } } rewind(fsi); } } else if (! DoNothing) { /* require -f [email_file] */ fprintf(stderr, "Error: email_file not specified\n"); usage(); vexit(-1); } if ( ExcludeFileFlag == 1 ) { if ( (fsx = fopen(ExcludeFile, "r")) == NULL ) { fprintf(stderr, "Could not open file %s\n", ExcludeFile); vexit(-1); } } if (( EmailFile[0] != 0 || DoNothing == 1) && Domain[0] != 0 ) { /* Process list of domains */ domain = strtok(Domain, " "); while (domain != NULL ) { if((vget_assign(domain, domain_dir, sizeof(domain_dir), NULL, NULL)) != NULL) { process_domain(domain, fsi, fsx ); } else { fprintf(stderr, "Error: domain %s does not exist\n", domain); } domain = strtok(NULL, " "); } vexit(0); } else if ( (EmailFile[0] != 0 || DoNothing == 1) && Domain[0] == 0 ) { entry = get_domain_entries( "" ); if (entry==NULL) { if( verrori ) { printf("Can't get domain entries - %s\n", verror( verrori )); vexit(-1); } else { printf("What now - %s\n", verror( verrori )); vexit(0); } } while( entry ) { if (strcmp (entry->domain, entry->realdomain) != 0) { if (Verbose) { fprintf (stderr, "skipping %s (alias of %s)\n", entry->domain, entry->realdomain); } } else { chdir(entry->path); process_domain(entry->realdomain, fsi, fsx ); } entry = get_domain_entries(NULL); } } return(vexit(0)); }
int main() { #ifndef USE_SQL FILE *fs_smtp_cur; FILE *fs_smtp_tmp; char *tmpstr; time_t file_time; #endif /* ndef USE_SQL */ time_t mytime; time_t clear_minutes; if( vauth_open( 0 )) { vexiterror( stderr, "Initial open." ); } clear_minutes = RELAY_CLEAR_MINUTES * 60; mytime = time(NULL); #ifdef USE_SQL /* scan the relays table in mysql, and purge out any * entries that are older than our specified timestamp */ vclear_open_smtp(clear_minutes, mytime); #else /* OPEN_SMTP_CUR_FILE is typically ~vpopmail/etc/open-smtp */ fs_smtp_cur = fopen(OPEN_SMTP_CUR_FILE, "r+"); if ( fs_smtp_cur != NULL ) { /* OPEN_SMTP_TMP_FILE is typically ~vpopmail/etc/open-smtp.tmp */ /* create this file */ fs_smtp_tmp = fopen(OPEN_SMTP_TMP_FILE, "w+"); if ( fs_smtp_tmp == NULL ) { printf ("Error, could not create open-smtp.tmp\n"); vexit(-1); } /* read in the contents of the open-smtp file */ while ( fgets(TmpBuf1, MAX_BUFF, fs_smtp_cur ) != NULL ) { /* format is x.x.x.x:ALLOW,RELAYCLIENT="",RBLSMTPD=""<TAB>timestamp */ snprintf(TmpBuf2, sizeof(TmpBuf2), "%s", TmpBuf1); tmpstr = strtok( TmpBuf2, "\t"); tmpstr = strtok( NULL, "\t"); /* extract the timestamp for this line */ if ( tmpstr != NULL ) { /* compare the timestamp to see if it is not too old */ file_time = atoi(tmpstr); if ( file_time + clear_minutes > mytime) { /* if not too old, copy line out to .tmp file */ fputs(TmpBuf1, fs_smtp_tmp); } } } fclose(fs_smtp_cur); fclose(fs_smtp_tmp); /* replace open-relay with open-relay.tmp */ rename(OPEN_SMTP_TMP_FILE, OPEN_SMTP_CUR_FILE); /* set correct permissions on file */ chown(OPEN_SMTP_CUR_FILE,VPOPMAILUID,VPOPMAILGID); } #endif /* Now, regardless of backend, build a new tcp.smtp.cdb file * * For mysql this involves combining the tcp.smtp file with * the contents of the relay table. * For cdb this involves combining the tcp.smtp file with * the contents of the open-relay file. * The resultant file will then be compiled by the tcprules tool * to make a new tcp.smtp.cdb file for tcpserver to use */ update_rules(); return(vexit(0)); }
int main(int argc, char *argv[]) { int i; char OptionString[MAX_BUFF]; if( vauth_open( 1 )) { vexiterror( stderr, "Initial open." ); } get_options(argc,argv); if (EditDefaultLimits || vget_assign(Domain, NULL, 0, NULL, NULL ) != NULL) { if (EditDefaultLimits) { if (vlimits_read_limits_file(VLIMITS_DEFAULT_FILE, &limits) != 0) { printf ("Failed to read the vlimits.default file.\n"); vexit(-1); } if (DeleteLimits) { printf ("Default limits must not be deleted. If you really want to do this,\n"); printf ("remove the vlimits.default file.\n"); printf ("But be warned: this might stop vpopmail from working!!\n"); vexit(-1); } } else { if (vget_limits(Domain,&limits) != 0) { printf ("Failed to vget_limits\n"); vexit(-1); } if (DeleteLimits) { if (vdel_limits(Domain)==0) { printf ("Limits deleted\n"); vexit(0); } else { printf ("Failed to delete limits\n"); vexit(-1); } } } if (ShowLimits) { memset (OptionString, 0, sizeof(OptionString)); if (EditDefaultLimits) printf("Default limits: %s\n", VLIMITS_DEFAULT_FILE); else printf("Domain: %s\n", Domain); printf("--\n"); printf("Max Pop Accounts: %d\n", limits.maxpopaccounts); printf("Max Aliases: %d\n", limits.maxaliases); printf("Max Forwards: %d\n", limits.maxforwards); printf("Max Autoresponders: %d\n", limits.maxautoresponders); printf("Max Mailinglists: %d\n", limits.maxmailinglists); printf("GID Flags:\n"); if (limits.disable_imap != 0) { printf(" NO_IMAP\n"); strncat(OptionString, "i", sizeof(OptionString)-strlen(OptionString)-1); } if (limits.disable_smtp != 0) { printf(" NO_SMTP\n"); strncat(OptionString, "s", sizeof(OptionString)-strlen(OptionString)-1); } if (limits.disable_pop != 0) { printf(" NO_POP\n"); strncat(OptionString, "p", sizeof(OptionString)-strlen(OptionString)-1); } if (limits.disable_webmail != 0) { printf(" NO_WEBMAIL\n"); strncat(OptionString, "w", sizeof(OptionString)-strlen(OptionString)-1); } if (limits.disable_passwordchanging != 0) { printf(" NO_PASSWD_CHNG\n"); strncat(OptionString, "d", sizeof(OptionString)-strlen(OptionString)-1); } if (limits.disable_relay != 0) { printf(" NO_RELAY\n"); strncat(OptionString, "r", sizeof(OptionString)-strlen(OptionString)-1); } if (limits.disable_dialup != 0) { printf(" NO_DIALUP\n"); strncat(OptionString, "u", sizeof(OptionString)-strlen(OptionString)-1); } if (limits.disable_spamassassin != 0) { printf(" NO_SPAMASSASSIN\n"); strncat(OptionString, "c", sizeof(OptionString)-strlen(OptionString)-1); } if (limits.delete_spam != 0) { printf(" DEL_SPAM\n"); strncat(OptionString, "x", sizeof(OptionString)-strlen(OptionString)-1); } if (limits.disable_maildrop != 0) { printf(" NO_MAILDROP\n"); strncat(OptionString, "m", sizeof(OptionString)-strlen(OptionString)-1); } printf("Flags (for commandline): %s\n", OptionString); printf("Flags for non postmaster accounts:"); printf("\n pop account: "); printf ((limits.perm_account & VLIMIT_DISABLE_CREATE ? "DENY_CREATE " :"ALLOW_CREATE ") ); printf ((limits.perm_account & VLIMIT_DISABLE_MODIFY ? "DENY_MODIFY " :"ALLOW_MODIFY ") ); printf ((limits.perm_account & VLIMIT_DISABLE_DELETE ? "DENY_DELETE " :"ALLOW_DELETE ") ); printf("\n alias: "); printf ((limits.perm_alias & VLIMIT_DISABLE_CREATE ? "DENY_CREATE " :"ALLOW_CREATE ") ); printf ((limits.perm_alias & VLIMIT_DISABLE_MODIFY ? "DENY_MODIFY " :"ALLOW_MODIFY ") ); printf ((limits.perm_alias & VLIMIT_DISABLE_DELETE ? "DENY_DELETE " :"ALLOW_DELETE ") ); printf("\n forward: "); printf ((limits.perm_forward & VLIMIT_DISABLE_CREATE ? "DENY_CREATE " :"ALLOW_CREATE ") ); printf ((limits.perm_forward & VLIMIT_DISABLE_MODIFY ? "DENY_MODIFY " :"ALLOW_MODIFY ") ); printf ((limits.perm_forward & VLIMIT_DISABLE_DELETE ? "DENY_DELETE " :"ALLOW_DELETE ") ); printf("\n autoresponder: "); printf ((limits.perm_autoresponder & VLIMIT_DISABLE_CREATE ? "DENY_CREATE " :"ALLOW_CREATE ") ); printf ((limits.perm_autoresponder & VLIMIT_DISABLE_MODIFY ? "DENY_MODIFY " :"ALLOW_MODIFY ") ); printf ((limits.perm_autoresponder & VLIMIT_DISABLE_DELETE ? "DENY_DELETE " :"ALLOW_DELETE ") ); printf("\n mailinglist: "); printf ((limits.perm_maillist & VLIMIT_DISABLE_CREATE ? "DENY_CREATE " :"ALLOW_CREATE ") ); printf ((limits.perm_maillist & VLIMIT_DISABLE_MODIFY ? "DENY_MODIFY " :"ALLOW_MODIFY ") ); printf ((limits.perm_maillist & VLIMIT_DISABLE_DELETE ? "DENY_DELETE " :"ALLOW_DELETE ") ); printf("\n mailinglist users: "); printf ((limits.perm_maillist_users & VLIMIT_DISABLE_CREATE ? "DENY_CREATE " :"ALLOW_CREATE ") ); printf ((limits.perm_maillist_users & VLIMIT_DISABLE_MODIFY ? "DENY_MODIFY " :"ALLOW_MODIFY ") ); printf ((limits.perm_maillist_users & VLIMIT_DISABLE_DELETE ? "DENY_DELETE " :"ALLOW_DELETE ") ); printf("\n mailinglist moderators: "); printf ((limits.perm_maillist_moderators & VLIMIT_DISABLE_CREATE ? "DENY_CREATE " :"ALLOW_CREATE ") ); printf ((limits.perm_maillist_moderators & VLIMIT_DISABLE_MODIFY ? "DENY_MODIFY " :"ALLOW_MODIFY ") ); printf ((limits.perm_maillist_moderators & VLIMIT_DISABLE_DELETE ? "DENY_DELETE " :"ALLOW_DELETE ") ); printf("\n quota: "); printf ((limits.perm_quota & VLIMIT_DISABLE_CREATE ? "DENY_CREATE " :"ALLOW_CREATE ") ); printf ((limits.perm_quota & VLIMIT_DISABLE_MODIFY ? "DENY_MODIFY " :"ALLOW_MODIFY ") ); printf ((limits.perm_quota & VLIMIT_DISABLE_DELETE ? "DENY_DELETE " :"ALLOW_DELETE ") ); printf("\n default quota: "); printf ((limits.perm_defaultquota & VLIMIT_DISABLE_CREATE ? "DENY_CREATE " :"ALLOW_CREATE ") ); printf ((limits.perm_defaultquota & VLIMIT_DISABLE_MODIFY ? "DENY_MODIFY " :"ALLOW_MODIFY ") ); printf ((limits.perm_defaultquota & VLIMIT_DISABLE_DELETE ? "DENY_DELETE " :"ALLOW_DELETE ") ); printf("\n"); printf("Domain Quota: %d MB\n", limits.diskquota); printf("Default User Quota: %d bytes\n", limits.defaultquota); printf("Max Domain Messages: %d\n", limits.maxmsgcount); printf("Default Max Messages per User: %d\n", limits.defaultmaxmsgcount); return(vexit(0)); } if (MaxPopAccounts[0] != 0) { limits.maxpopaccounts = atoi(MaxPopAccounts); } if (MaxAliases[0] != 0) { limits.maxaliases = atoi(MaxAliases); } if (MaxForwards[0] != 0) { limits.maxforwards = atoi(MaxForwards); } if (MaxAutoresponders[0] != 0) { limits.maxautoresponders = atoi(MaxAutoresponders); } if (MaxMailinglists[0] != 0) { limits.maxmailinglists = atoi(MaxMailinglists); } /* quota & message count limits */ if (DomainQuota[0] != 0) { limits.diskquota = atoi(DomainQuota); } if (DomainMaxMsgCount[0] != 0) { limits.maxmsgcount = atoi(DomainMaxMsgCount); } if (DefaultUserQuota[0] != 0) { limits.defaultquota = atoi(format_maildirquota(DefaultUserQuota)); } if (DefaultUserMaxMsgCount[0] != 0) { limits.defaultmaxmsgcount = atoi(DefaultUserMaxMsgCount); } if (GidFlag == 1) { GidFlag = 0; limits.disable_dialup = 0; limits.disable_passwordchanging = 0; limits.disable_pop = 0; limits.disable_smtp = 0; limits.disable_webmail = 0; limits.disable_imap = 0; limits.disable_relay = 0; limits.disable_spamassassin = 0; limits.delete_spam = 0; limits.disable_maildrop = 0; for (i=0; i<(int)strlen(GidFlagString); i++) { switch(GidFlagString[i]) { case 'u': limits.disable_dialup = 1; break; case 'd': limits.disable_passwordchanging = 1; break; case 'p': limits.disable_pop = 1; break; case 's': limits.disable_smtp = 1; break; case 'w': limits.disable_webmail = 1; break; case 'i': limits.disable_imap = 1; break; case 'r': limits.disable_relay = 1; break; case 'c': limits.disable_spamassassin = 1; break; case 'x': limits.delete_spam = 1; break; case 'm': limits.disable_maildrop = 1; break; } } } if (PermAccountFlag == 1) { limits.perm_account=0; for (i=0; i<(int)strlen(PermAccountFlagString); i++) { switch(PermAccountFlagString[i]) { case 'a': limits.perm_account|=VLIMIT_DISABLE_ALL; break; case 'c': limits.perm_account|=VLIMIT_DISABLE_CREATE; break; case 'm': limits.perm_account|=VLIMIT_DISABLE_MODIFY; break; case 'd': limits.perm_account|=VLIMIT_DISABLE_DELETE; break; } } } if (PermAliasFlag == 1) { limits.perm_alias=0; for (i=0; i<(int)strlen(PermAliasFlagString); i++) { switch(PermAliasFlagString[i]) { case 'a': limits.perm_alias|=VLIMIT_DISABLE_ALL; break; case 'c': limits.perm_alias|=VLIMIT_DISABLE_CREATE; break; case 'm': limits.perm_alias|=VLIMIT_DISABLE_MODIFY; break; case 'd': limits.perm_alias|=VLIMIT_DISABLE_DELETE; break; } } } if (PermForwardFlag == 1) { limits.perm_forward=0; for (i=0; i<(int)strlen(PermForwardFlagString); i++) { switch(PermForwardFlagString[i]) { case 'a': limits.perm_forward|=VLIMIT_DISABLE_ALL; break; case 'c': limits.perm_forward|=VLIMIT_DISABLE_CREATE; break; case 'm': limits.perm_forward|=VLIMIT_DISABLE_MODIFY; break; case 'd': limits.perm_forward|=VLIMIT_DISABLE_DELETE; break; } } } if (PermAutoresponderFlag == 1) { limits.perm_autoresponder=0; for (i=0; i<(int)strlen(PermAutoresponderFlagString); i++) { switch(PermAutoresponderFlagString[i]) { case 'a': limits.perm_autoresponder|=VLIMIT_DISABLE_ALL; break; case 'c': limits.perm_autoresponder|=VLIMIT_DISABLE_CREATE; break; case 'm': limits.perm_autoresponder|=VLIMIT_DISABLE_MODIFY; break; case 'd': limits.perm_autoresponder|=VLIMIT_DISABLE_DELETE; break; } } } if (PermMaillistFlag == 1) { limits.perm_maillist=0; for (i=0; i<(int)strlen(PermMaillistFlagString); i++) { switch(PermMaillistFlagString[i]) { case 'a': limits.perm_maillist|=VLIMIT_DISABLE_ALL; break; case 'c': limits.perm_maillist|=VLIMIT_DISABLE_CREATE; break; case 'm': limits.perm_maillist|=VLIMIT_DISABLE_MODIFY; break; case 'd': limits.perm_maillist|=VLIMIT_DISABLE_DELETE; break; } } } if (PermMaillistUsersFlag == 1) { limits.perm_maillist_users=0; for (i=0; i<(int)strlen(PermMaillistUsersFlagString); i++) { switch(PermMaillistUsersFlagString[i]) { case 'a': limits.perm_maillist_users|=VLIMIT_DISABLE_ALL; break; case 'c': limits.perm_maillist_users|=VLIMIT_DISABLE_CREATE; break; case 'm': limits.perm_maillist_users|=VLIMIT_DISABLE_MODIFY; break; case 'd': limits.perm_maillist_users|=VLIMIT_DISABLE_DELETE; break; } } } if (PermMaillistModeratorsFlag == 1) { limits.perm_maillist_moderators=0; for (i=0; i<(int)strlen(PermMaillistModeratorsFlagString); i++) { switch(PermMaillistModeratorsFlagString[i]) { case 'a': limits.perm_maillist_moderators|=VLIMIT_DISABLE_ALL; break; case 'c': limits.perm_maillist_moderators|=VLIMIT_DISABLE_CREATE; break; case 'm': limits.perm_maillist_moderators|=VLIMIT_DISABLE_MODIFY; break; case 'd': limits.perm_maillist_moderators|=VLIMIT_DISABLE_DELETE; break; } } } if (PermQuotaFlag == 1) { limits.perm_quota=0; for (i=0; i<(int)strlen(PermQuotaFlagString); i++) { switch(PermQuotaFlagString[i]) { case 'a': limits.perm_quota|=VLIMIT_DISABLE_ALL; break; case 'c': limits.perm_quota|=VLIMIT_DISABLE_CREATE; break; case 'm': limits.perm_quota|=VLIMIT_DISABLE_MODIFY; break; case 'd': limits.perm_quota|=VLIMIT_DISABLE_DELETE; break; } } } if (PermDefaultQuotaFlag == 1) { limits.perm_defaultquota=0; for (i=0; i<(int)strlen(PermDefaultQuotaFlagString); i++) { switch(PermDefaultQuotaFlagString[i]) { case 'a': limits.perm_defaultquota|=VLIMIT_DISABLE_ALL; break; case 'c': limits.perm_defaultquota|=VLIMIT_DISABLE_CREATE; break; case 'm': limits.perm_defaultquota|=VLIMIT_DISABLE_MODIFY; break; case 'd': limits.perm_defaultquota|=VLIMIT_DISABLE_DELETE; break; } } } if (EditDefaultLimits) { if (vlimits_write_limits_file(VLIMITS_DEFAULT_FILE, &limits)) { printf ("Failed to write vlimits.default file"); return (vexit(-1)); } } else { if (vset_limits(Domain,&limits) != 0) { printf ("Failed to vset_limits\n"); return (vexit(-1)); } } } return(vexit(0)); }