addusernow() { char pw[50]; int cnt=0, num; char *c_num; char **mailingListNames; char *tmp; char *email; char **arguments; int pid; int i; int error; struct vqpasswd *mypw; c_num = malloc(MAX_BUFF); email = malloc(128); tmp = malloc(MAX_BUFF); arguments = (char **)malloc(MAX_BUFF); count_users(); load_limits(); if ( AdminType!=DOMAIN_ADMIN ) { sprintf(StatusMessage,"%s", get_html_text("142")); vclose(); exit(0); } if ( MaxPopAccounts != -1 && CurPopAccounts >= MaxPopAccounts ) { sprintf(StatusMessage, "%s %d\n", get_html_text("199"), MaxPopAccounts); show_menu(); vclose(); exit(0); } GetValue(TmpCGI,Newu, "newu=", MAX_BUFF); if ( fixup_local_name(Newu) ) { sprintf(StatusMessage, "%s %s\n", get_html_text("148"), Newu); adduser(); vclose(); exit(0); } if ( check_local_user(Newu) ) { sprintf(StatusMessage, "%s %s\n", get_html_text("175"), Newu); adduser(); vclose(); exit(0); } GetValue(TmpCGI,Password1, "password1=", MAX_BUFF); GetValue(TmpCGI,Password2, "password2=", MAX_BUFF); if ( strncmp( Password1, Password2, MAX_BUFF ) != 0 ) { sprintf(StatusMessage, "%s\n", get_html_text("200")); adduser(); vclose(); exit(0); } if ( strlen(Password1) <= 0 ) { sprintf(StatusMessage, "%s\n", get_html_text("234")); adduser(); vclose(); exit(0); } strcpy(email, ""); strcat(email,Newu); strcat(email,"@"); strcat(email,Domain); GetValue(TmpCGI,Gecos, "gecos=", MAX_BUFF); if ( strlen( Gecos ) == 0 ) { strcpy(Gecos, Newu); } GetValue(TmpCGI, c_num, "number_of_mailinglist=", MAX_BUFF); num = atoi(c_num); if(!(mailingListNames = malloc(sizeof(char *) * num))) { sprintf(StatusMessage, "%s\n", get_html_text("201")); vclose(); exit(0); } else { for(cnt = 0; cnt < num; cnt++) { if(!(mailingListNames[cnt] = malloc(MAX_BUFF))) { sprintf(StatusMessage, "%s\n", get_html_text("201")); vclose(); exit(0); } } for(cnt = 0; cnt < num; cnt++) { sprintf(tmp, "subscribe%d=", cnt); error = GetValue(TmpCGI, mailingListNames[cnt], tmp, MAX_BUFF); if( error != -1 ) { pid=fork(); if (pid==0) { sprintf(TmpBuf1, "%s/ezmlm-sub", EZMLMDIR); sprintf(TmpBuf2, "%s/%s", RealDir, mailingListNames[cnt]); execl(TmpBuf1, "ezmlm-sub", TmpBuf2, email, NULL); exit(127); } else { wait(&pid); } } } } /* add the user then get the vpopmail password structure */ if ( vadduser( Newu, Domain, Password1, Gecos, USE_POP ) == 0 && #ifdef MYSQL_REPLICATION !sleep(2) && #endif (mypw = vauth_getpw( Newu, Domain )) != NULL ) { /* from the load_limits() function, set user flags */ if( DisablePOP > 0 ) mypw->pw_gid |= NO_POP; if( DisableIMAP > 0 ) mypw->pw_gid |= NO_IMAP; if( DisableDialup > 0 ) mypw->pw_gid |= NO_DIALUP; if( DisablePasswordChanging > 0 ) mypw->pw_gid |= NO_PASSWD_CHNG; if( DisableWebmail > 0 ) mypw->pw_gid |= NO_WEBMAIL; if( DisableRelay > 0 ) mypw->pw_gid |= NO_RELAY; if( DefaultQuota[0]!= 0 ) mypw->pw_shell = DefaultQuota; /* update the user information */ if ( vauth_setpw( mypw, Domain ) != VA_SUCCESS ) { /* report error */ sprintf(StatusMessage, "%s %s@%s (%s) %s", get_html_text("002"), Newu, Domain, Gecos, get_html_text("120")); } else { /* report success */ sprintf(StatusMessage, "%s %s@%s (%s) %s", get_html_text("002"), Newu, Domain, Gecos, get_html_text("119")); } /* otherwise, report error */ } else { sprintf(StatusMessage, "<font color=\"red\">%s %s@%s (%s) %s</font>", get_html_text("002"), Newu, Domain, Gecos, get_html_text("120")); } call_hooks( HOOK_ADDUSER ); /* After we add the user, show the user page * people like to visually verify the results */ show_users(Username, Domain, Mytime); }
modusergo() { char crypted[20]; char *tmpstr; int i; int ret_code; int password_updated = 0; struct vqpasswd *vpw=NULL; static char box[50]; static char NewBuf[156]; int count; FILE *fs; #ifdef SQWEBMAIL_PASS uid_t uid; gid_t gid; #endif vpw = vauth_getpw(ActionUser, Domain); if (!( AdminType==DOMAIN_ADMIN || (AdminType==USER_ADMIN && strcmp(ActionUser,Username)==0))){ sprintf(StatusMessage,"%s", get_html_text("142")); vclose(); exit(0); } if (strlen(Password1)>0 && strlen(Password2)>0 ) { if ( strncmp( Password1, Password2, MAX_BUFF ) != 0 ) { sprintf(StatusMessage, "%s\n", get_html_text("200")); moduser(); vclose(); exit(0); } if (strlen(Password1) > MAX_PW_CLEAR_PASSWD) { sprintf(StatusMessage,"%s %s@%s %s", get_html_text("139"), ActionUser, Domain, VA_PASSWD_TOO_LONG ); moduser(); vclose(); exit(0); } else if (vpw->pw_gid & NO_PASSWD_CHNG) { sprintf(StatusMessage, "%s", get_html_text("140")); moduser(); vclose(); exit(0); } else { sprintf(StatusMessage,"%s %s@%s", get_html_text("139"), ActionUser, Domain); } mkpasswd3(Password1,Crypted, MAX_BUFF); vpw->pw_passwd = Crypted; #ifdef CLEAR_PASS vpw->pw_clear_passwd = Password1; #endif #ifdef SQWEBMAIL_PASS vget_assign(Domain, NULL, 0, &uid, &gid ); vsqwebmail_pass( vpw->pw_dir, Crypted, uid, gid); #endif } GetValue(TmpCGI,Gecos, "gecos=", MAX_BUFF); if ( strlen( Gecos ) != 0 ) { vpw->pw_gecos = Gecos; } vauth_setpw(vpw, Domain); /* get the value of the cforward radio button */ GetValue(TmpCGI,box, "cforward=", MAX_BUFF); /* if they want to disable everything */ if ( strcmp(box,"disable") == 0 ) { /* unlink the .qmail file */ if ( vpw == NULL ) vpw = vauth_getpw(ActionUser, Domain); snprintf(NewBuf,156,"%s/.qmail", vpw->pw_dir); unlink(NewBuf); /* delete any vacation directory */ snprintf(NewBuf,156,"%s/vacation", vpw->pw_dir); vdelfiles(NewBuf); /* if they want to forward */ } else if (strcmp(box,"forward") == 0 ) { /* get the value of the foward */ GetValue(TmpCGI,box, "nforward=", MAX_BUFF); /* If nothing was entered, error */ if ( box[0] == 0 ) { sprintf(StatusMessage, "%s\n", get_html_text("215")); moduser(); vclose(); exit(0); /* check it for a valid email address } else if ( check_email_addr( box ) == 1 ) { sprintf(StatusMessage, "%s\n", get_html_text("148")); moduser(); */ } /* everything looks good, open the file */ if ( vpw == NULL ) { vpw = vauth_getpw(ActionUser, Domain); } snprintf(NewBuf,156,"%s/.qmail", vpw->pw_dir); fs = fopen(NewBuf,"w+"); tmpstr = strtok(box," ,;\n"); count=0; while( tmpstr != NULL && count < 2) { fprintf(fs,"&%s\n", tmpstr); tmpstr = strtok(NULL," ,\n"); ++count; } /* if they want to save a copy */ GetValue(TmpCGI,box, "fsaved=", MAX_BUFF); if ( strcmp(box,"on") == 0 ) { fprintf(fs,"%s/Maildir/\n", vpw->pw_dir); } fclose(fs); /* they want vacation */ } else if (strcmp(box,"vacation") == 0 ) { /* get the subject */ GetValue(TmpCGI,box, "vsubject=", MAX_BUFF); /* if no subject, error */ if ( box[0] == 0 ) { sprintf(StatusMessage, "%s\n", get_html_text("216")); moduser(); vclose(); exit(0); } /* make the vacation directory */ if ( vpw == NULL ) vpw = vauth_getpw(ActionUser, Domain); snprintf(NewBuf,156,"%s/vacation", vpw->pw_dir); mkdir(NewBuf, 448); /* open the .qmail file */ snprintf(NewBuf,156,"%s/.qmail", vpw->pw_dir); fs = fopen(NewBuf,"w+"); fprintf(fs, "| %s/autorespond 86400 3 %s/vacation/message %s/vacation\n", AUTORESPOND_BIN, vpw->pw_dir, vpw->pw_dir ); /* save a copy for the user */ fprintf(fs,"%s/Maildir/\n", vpw->pw_dir); fclose(fs); /* set up the message file */ snprintf(NewBuf,156,"%s/vacation/message", vpw->pw_dir); GetValue(TmpCGI,Message, "vmessage=",MAX_BIG_BUFF); if ( (fs = fopen(NewBuf, "w")) == NULL ) ack("123", 123); fprintf(fs, "From: %s@%s\n", ActionUser,Domain); fprintf(fs, "Subject: %s\n\n", box); fprintf(fs, "%s", Message); fclose(fs); /* save the forward for vacation too */ GetValue(TmpCGI,box,"nforward=", MAX_BUFF); snprintf(NewBuf, 156, "%s/.qmail", vpw->pw_dir); fs = fopen(NewBuf, "a+"); tmpstr = strtok(box, " ,;\n"); count = 0; while( tmpstr != NULL && count < 2 ) { fprintf(fs, "&%s\n", tmpstr); tmpstr = strtok(NULL, " ,;\n"); ++count; } fclose(fs); } else { printf("nothing\n"); } call_hooks(HOOK_MODUSER); show_users(Username, Domain, Mytime); }
int main(int argc, char **argv) { FILE *fs; int first; struct passwd *pw; char *tmpstr; uid_t uid; gid_t gid; get_options(argc,argv); fs = fopen("/usr/tmp/vreorg", "w+"); if ( fs == NULL ) { perror("vreorg:"); exit(errno); } first = 1; printf("getting user list\n"); while( (pw=vauth_getall(Domain, first, 0))){ first = 0; fprintf(fs, "%s %s %s\n", pw->pw_user, Domain, pw->pw_dir); } rewind(fs); printf("done.\n"); vget_assign(Domain, DomainDir, MAX_BUFF, &uid, &gid); /* reset dir control external to this program */ printf("resetting the directory layout status\n"); vdel_dir_control(Domain); printf("working on users\n"); while ( fgets(TmpBuf, MAX_BUFF, fs) != NULL ) { /* user */ tmpstr = strtok(TmpBuf, TOKENS); if ( tmpstr == NULL ) continue; strcpy( User, tmpstr); /* domain */ tmpstr = strtok(NULL, TOKENS); if ( tmpstr == NULL ) continue; strcpy( Domain, tmpstr); /* old dir */ tmpstr = strtok(NULL, TOKENS); if ( tmpstr == NULL ) continue; strcpy( OldDir, tmpstr); /* get next dir */ open_big_dir(Domain); tmpstr = next_big_dir(uid, gid); close_big_dir(Domain, uid, gid); /* get old pw struct */ pw = vauth_getpw( User, Domain); /* get space for pw_dir */ pw->pw_dir = malloc(MAX_BUFF); /* format new directory string */ if ( slen(tmpstr) > 0 ) { sprintf(pw->pw_dir, "%s/%s/%s", DomainDir, tmpstr, User); } else { sprintf(pw->pw_dir, "%s/%s", DomainDir, User); } printf("%s@%s old %s new %s ", User, Domain, OldDir, pw->pw_dir); /* update database */ vauth_setpw( pw, domain ); /* move directory */ rename(OldDir, pw->pw_dir); /* free directory memory */ free(pw->pw_dir); printf("done\n"); } fclose(fs); unlink("/usr/tmp/vreorg"); exit(0); }