/**************************************************************************** * @format.tab-size 4 (Plain Text/Source Code File Header) * * @format.use-tabs true (see http://www.synchro.net/ptsc_hdr.html) * * * * Copyright Rob Swindell - http://www.synchro.net/copyright.html * * * * 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. * * See the GNU General Public License for more details: gpl.txt or * * http://www.fsf.org/copyleft/gpl.html * * * * For Synchronet coding style and modification guidelines, see * * http://www.synchro.net/source.html * * * * Note: If this box doesn't appear square, then you need to fix your tabs. * ****************************************************************************/ #include #include #include #include #include #include "sbbsdefs.h" #include "str_util.h" int min=0,max=99; long reqflags[4]={0},reqrest=0,reqexempt=0; char *usage= "\nusage: allusers [data\\user path] [[-require] [...]] " "/modify [[/modify] [...]]\n" "\nwhere require is one of:\n" " L# set minimum level to # (default=0)\n" " M# set maximum level to # (default=99)\n" " F# set required flags from flag set #\n" " E set required exemptions\n" " R set required restrictions\n" "\nwhere modify is one of:\n" " L# change security level to #\n" " F#[+|-] add or remove flags from flag set #\n" " E[+|-] add or remove exemption flags\n" " R[+|-] add or remove restriction flags\n" "\nExamples:\n" " ALLUSERS -L30 /FA add 'A' to flag set #1 for all level 30+ users\n" " ALLUSERS /F3-G remove 'G' from flag set #3 for all users\n" " ALLUSERS -F2B /E-P remove 'P' exemption for all users with FLAG '2B'\n" " ALLUSERS /R+W add 'W' restriction for all users" ; /****************************************************************************/ /* Attempts to lock a user record, retries for up to 10 seconds */ /* Returns 0 on success, -1 on failure */ /****************************************************************************/ int lockuser(FILE *stream, ulong offset) { time_t start; if(lock(fileno(stream),offset,U_LEN)==0) return(0); start=time(NULL); while(1) { if(lock(fileno(stream),offset,U_LEN)==0) return(0); if(time(NULL)-start>=10L) break; } return(-1); } /****************************************************************************/ /* Returns bytes offset into user record for flag set # 'set' */ /****************************************************************************/ long getflagoff(int set) { switch(set) { default: return(U_FLAGS1); case 2: return(U_FLAGS2); case 3: return(U_FLAGS3); case 4: return(U_FLAGS4); } } /****************************************************************************/ /* Checks a user record against the requirements set on the command line */ /* Returns 1 if the user meets the requirements (or no requirements were */ /* specified) or 0 if the user does not meet any of the requirements. */ /****************************************************************************/ int chkuser(FILE *stream, long offset) { char str[128]; int i; if(min || max!=99) { /* Check security level */ fseek(stream,offset+U_LEVEL,SEEK_SET); if(!fread(str,2,1,stream)) return(0); str[2]=0; i=atoi(str); if(imax) /* not within range */ return(0); /* so skip this user */ } for(i=0;i<4;i++) if(reqflags[i]) { fseek(stream,offset+getflagoff(i+1),SEEK_SET); if(!fread(str,8,1,stream)) return(0); str[8]=0; truncsp(str); if((ahtoul(str)&reqflags[i])!=reqflags[i]) return(0); /* doesn't have 'em all */ } if(reqrest) { fseek(stream,offset+U_REST,SEEK_SET); if(!fread(str,8,1,stream)) return(0); str[8]=0; truncsp(str); if((ahtoul(str)&reqrest)!=reqrest) return(0); } if(reqexempt) { fseek(stream,offset+U_REST,SEEK_SET); if(!fread(str,8,1,stream)) return(0); str[8]=0; truncsp(str); if((ahtoul(str)&reqexempt)!=reqexempt) return(0); } return(1); } int main(int argc, char **argv) { char dir[128],str[128]; int i,j,file,set,sub,mod; long l,f,flags,flagoff,offset; off_t length; FILE *stream; printf("\nALLUSERS v2.10 - Bulk User Editor for Synchronet User Database\n"); if(argc<2) { puts(usage); exit(1); } dir[0]=0; for(i=1;i99) j=99; if(j<0) j=0; SAFEPRINTF(str,"%suser.dat",dir); if(!fexistcase(str) || (file=sopen(str,O_RDWR|O_BINARY,SH_DENYNO))==-1) { printf("Error opening %s\n",str); exit(1); } if((stream=fdopen(file,"w+b"))==NULL) { printf("Error opening %s\n",str); exit(1); } setvbuf(stream,NULL,_IOFBF,2048); length=filelength(file); printf("\nChanging Levels\n"); for(offset=0;offset