[prev in list] [next in list] [prev in thread] [next in thread] 

List:       ipcop-cvs
Subject:    [IPCop-cvs] ipcop/src/misc-progs ipcopbackup.c,1.8.2.8,1.8.2.9 Makefile,1.5.2.8,1.5.2.9
From:       Gilles Espinasse <gespinasse () users ! sourceforge ! net>
Date:       2006-05-29 21:07:31
Message-ID: E1FkoxZ-00075C-El () mail ! sourceforge ! net
[Download RAW message or body]

Update of /cvsroot/ipcop/ipcop/src/misc-progs
In directory sc8-pr-cvs11.sourceforge.net:/tmp/cvs-serv22717/src/misc-progs

Modified Files:
      Tag: IPCOP_v1_4_0
	ipcopbackup.c Makefile 
Log Message:
Go back to previous 1.4.10 ipcopbackup code as there no sense to change
floppy code for web backup related changes

Changes are only:
- removal of unnecessary grp.h include
- shorter lines of code

Later I will commit functions shifted to ipcopbkcfg


Index: ipcopbackup.c
===================================================================
RCS file: /cvsroot/ipcop/ipcop/src/misc-progs/ipcopbackup.c,v
retrieving revision 1.8.2.8
retrieving revision 1.8.2.9
diff -C2 -d -r1.8.2.8 -r1.8.2.9
*** ipcopbackup.c	27 Apr 2006 14:08:24 -0000	1.8.2.8
--- ipcopbackup.c	29 May 2006 21:07:25 -0000	1.8.2.9
***************
*** 27,256 ****
  #include <unistd.h>
  #include <sys/types.h>
- #include <sys/stat.h>
  #include <fcntl.h>
- #include <pwd.h>
- #include <shadow.h>
- #include <crypt.h>
- #include <glob.h>
  #include "setuid.h"
  
! // want a bigger buffer to concatenate a possibly long string
! #define COMMAND_SIZE 4000
! //Append lines contained in 'inputfile' to 'string'
! int catlist(char* inputfile, char* string )
  {
! 	struct stat s;		// input file stats
! 	char buffer[STRING_SIZE];	// read buffer
! 
! 	if (stat(inputfile,&s) != 0) return 1;
! 	if (s.st_size+strlen(string)>COMMAND_SIZE) return 1;	// too big!
! 	int f = open(inputfile, O_RDONLY);
! 	// cannot open file
! 	if (!f) return 1;
! 
! 	int count;
! 	while ((count = read(f, buffer, STRING_SIZE - 1))) {
! 		int j;
! 		//replace newlines with spaces
! 		for (j=0; j<count; j++) {
! 			if (buffer[j] == '\n') buffer[j] = ' ';
! 		}
! 		buffer[j] = '\0';
! 		strcat (string,buffer);	// append to string
! 	}
! 	close (f);
! 	return 0;	//success
! }
  
! // make a raw backup to floppy_dev (no partitioning)
! int savecfg_floppy(char* floppy_dev)
! {
! 	char command[COMMAND_SIZE];  // because copy each filename here
  
- 	// want special output...
  	if (close(0)) { fprintf(stderr, "Couldn't close 0\n"); exit(1); }
! 	if (open("/dev/zero", O_RDONLY) != 0) {fprintf(stderr, "Couldn't reopen stdin from \
/dev/zero\n"); exit(1); }  if (close(2)) { fprintf(stderr, "Couldn't close 2\n"); \
                exit(1); }
! 	if (! dup(1)) { fprintf(stderr, "Couldnt redirect stderr to stdout\n"); exit(1); }
! 
! 	/* Make sure floppy device name is up to date */
! 	safe_system ("/usr/sbin/updfstab");
! 
! 	/* Darren Critchley - check for floppy disk in disk drive before continuing */
! 	snprintf (command, STRING_SIZE-1, "dd if=%s of=/dev/null bs=1k count=1 2> \
                /dev/null", floppy_dev);
! 	if (safe_system(command)) {
! 		perror( "Error: No floppy in drive or bad floppy in drive" );
  		exit(1);
  	}
  
! 	/* Clearing disk */
! 	snprintf (command, STRING_SIZE-1, "/bin/dd if=/dev/zero of=%s bs=1k 2> /dev/null", \
                floppy_dev);
! 	safe_system (command);
  
! 	/* Start tarring files to floppy */
! 	snprintf (command, COMMAND_SIZE-1, "/bin/tar -X " \
                CONFIG_ROOT"/backup/exclude.system "
! 						    "-X " CONFIG_ROOT"/backup/exclude.user "
! 						    "-C / -cvzf %s "
! 						    "-T " CONFIG_ROOT"/backup/include.user ",
! 						    floppy_dev);
! 	/* add include.system file content to 'command' */
! 	if (catlist(CONFIG_ROOT "/backup/include.system", command)) {
  		fprintf(stderr, "Couldn't open backup system include file\n");
  		exit (1);
  	}
- 	safe_system (command);
- 
- 	/* Now check it */
- 	snprintf (command, STRING_SIZE-1,"/bin/echo '<b>Checking</b>'; /bin/tar -tzf %s" , \
                floppy_dev);
- 	safe_system (command);
  
! 	exit(0);
! }
! 
! 
! // Just verify that root password is ok
! int  checkrootpass (char* passwd)
! {
! 	struct passwd *pw;
! 	struct spwd *spwd;
! 
! 	if ((pw = getpwnam("root")) == NULL) {
! 		return (0); // root unknown....!
  	}
  
! 	// get shadowed password
! 	spwd = getspnam("root");
! 
! 	//and use it in right place
! 	if (spwd)
! 		pw->pw_passwd = spwd->sp_pwdp;
! 	//encrypt cleartext and compare to encrypted version and return true or false
! 	return (strcmp ( crypt(passwd, pw->pw_passwd), pw->pw_passwd) == 0 ) ?  1 : 0;
! }
! 
! 
! int main (int argc, char *argv[]) {
! 	char command[STRING_SIZE];
! 
! 	if (argc < 3) {		// at least two args always needed, avoid some testing.
! 		fprintf (stderr, "Err %s: used from cgi only !\n", argv[0]);
  		exit (1);
  	}
  
! 	if (!initsetuid()){
! 		fprintf (stderr, "Err %s: cannot setuid !\n", argv[0]);
! 		exit (1);
  	}
  
! 	// save on normal floppy for use during reinstall ONLY
! 	if ( (strcmp(argv[1],"-savecfg" ) == 0) &&
! 		(strcmp(argv[2],"floppy") == 0) ) 
! 		savecfg_floppy("/dev/floppy");	// to do: mount usb floppy...
  
! 	//  issue cat /proc/partitions
! 	if ( (strcmp(argv[1],"-proc" ) == 0) && (strcmp(argv[2],"partitions") == 0) ) {
! 		int fi;
! 		if ( (fi = open("/proc/partitions", O_RDONLY))==-1) exit (1); // cannot open file
! 		char string[STRING_SIZE];
! 		int count;
! 		while ((count = read(fi, string, STRING_SIZE))) {
! 			write (1, string, count);
! 		}
! 		close (fi);
! 		exit (0);
  	}
  
! 	// output result of 'glob' function
! 	if ( (strcmp(argv[1],"-glob" ) == 0)) {
! 		glob_t g;
! 		if (glob (argv[2],0,NULL,&g) == 0) {
! 			char** pstr = g.gl_pathv;	// base array
! 			while (*pstr) {			// while not NULL
! 				printf ("%s\n", *pstr);	// pstr is a pointer to array of char*
! 				pstr++;			// next pointer
! 			}
! 			globfree (&g);
! 		}
! 		exit (0);
! 	}
  
! 	// tell if the backup.key is present
! 	if ( (strcmp(argv[1],"-key" ) == 0) && (strcmp(argv[2],"exist") == 0) ) {
! 		if ( !(file_exists(BACKUP_KEY)) ) {
! 			fprintf (stderr, "Err %s: backup key "BACKUP_KEY" does not exist !\n", argv[0]);
! 			exit (ERR_KEY);
! 		}
! 		exit (0);
! 	}
  
! 	// cat the backup.key, for saving it
! 	if ( strcmp(argv[1],"-keycat" ) == 0) {
! 		if (! checkrootpass (argv[2])) exit (1); // but only if root pw provided
! 		int fi;
! 		if ( (fi = open(BACKUP_KEY, O_RDONLY))==-1) exit (1); // cannot open file
! 		char string[STRING_SIZE];
! 		int count;
! 		while ((count = read(fi, string, STRING_SIZE))) {
! 			write (1, string, count);
! 		}
! 		close (fi);
! 		exit (0);
! 	}
! 	
! 	// generate a new backup.key ONLY if inexistant
! 	if ( (strcmp(argv[1],"-key" ) == 0) && (strcmp(argv[2],"new") == 0) ) {
! 		if ( (file_exists(BACKUP_KEY)) ) {
! 			fprintf (stderr, "Err %s: backup key "BACKUP_KEY" already exists !\n", argv[0]);
! 			exit (ERR_KEY);
! 		}
! 		//ok we can generate it
! 		if (safe_system ("/usr/sbin/ipsec ranbits 256 > " BACKUP_KEY)) {
! 			fprintf (stderr, "Err %s: couldn't create key !\n", argv[0]);
! 			exit (ERR_KEY);
! 		}
! 		chmod(BACKUP_KEY, S_IRUSR);	// protect it
! 		exit (0);
! 	}
! 	
! 	// disk functions like mount umount,...
! 	if ((strspn(argv[2], LETTERS_NUMBERS ) == strlen(argv[2])) &&
! 			(strlen(argv[2]) >2) && (strlen(argv[2]) <6)) {
! 		// check that device is not our main disk
! 		char rootdev [50] = {0};
! 		int len = readlink ("/dev/root", rootdev, sizeof rootdev);
! 		if (len>0) {
! 			//remove partition number sda4=>sda
! 			rootdev[--len] = 0;
! 			//glue /dev/ to passed arg
! 			char dev [15] = "/dev/";
! 			strcat (dev, argv[2]);
! 			//if rootdev is in or equal to dev, stops
! 			if (!strncmp( rootdev, dev, len)) {
! 				fprintf (stderr, "Cannot mount or umount IPCop main disk !\n");
! 				exit (1);
! 			}
! 		} else {
! 			fprintf (stderr, "Cannot read /root/dev symlink !\n");
! 			exit (1);
! 		}
! 		//  -M sda1 => mount /dev/sda1 /mountpoint
! 		if (strcmp(argv[1],"-M") == 0) {
! 			snprintf(command, STRING_SIZE - 1,"/bin/mount -t vfat -o,uid=99,gid=99 /dev/%s \
                "MOUNTPOINT, argv[2]);
! 			safe_system(command);
! 		} else
! 		// -U sda1 => umount /dev/sda1
! 		if (strcmp(argv[1],"-U") == 0) {
! 			snprintf(command, STRING_SIZE - 1,"/bin/umount /dev/%s", argv[2]);
! 			safe_system(command);
! 			safe_system("/bin/sync");
! 		} else {
! 			fprintf (stderr, "Err %s: bad command !\n", argv[0]);
! 			exit (1);
! 		}
! 		exit (0);
! 	} else {
! 		fprintf (stderr, "Err %s: bad arg !\n", argv[0]);
! 		exit (1);
! 	}
! 	return 0;
  }
--- 27,119 ----
  #include <unistd.h>
  #include <sys/types.h>
  #include <fcntl.h>
  #include "setuid.h"
  
! int main(void)
  {
! 	int count, systeminclude, userinclude, tempfile;
! 	char buffer[STRING_SIZE];
! 	char command[STRING_SIZE];
! 	char tempfilename[STRING_SIZE];
  
! 	if (!(initsetuid()))
! 		exit(1);
  
  	if (close(0)) { fprintf(stderr, "Couldn't close 0\n"); exit(1); }
! 	if (open("/dev/zero", O_RDONLY) != 0) {
! 		fprintf(stderr, "Couldn't reopen stdin from /dev/zero\n");
! 		exit(1);
! 	}
  	if (close(2)) { fprintf(stderr, "Couldn't close 2\n"); exit(1); }
! 	if (! dup(1)) {
! 		fprintf(stderr, "Couldnt redirect stderr to stdout\n");
  		exit(1);
  	}
  
! 	/* Open temporary file for copying the inclusion files */
! 	strcpy (tempfilename, "/tmp/backup-inclusion.XXXXXX");
! 	if (! (tempfile = mkstemp (tempfilename)) > 0) { 
! 		fprintf(stderr, "Couldn't create temporary file.\n");
! 		exit(1);
! 	}
  
! 	/* Duplicate system include to temporary inclusion file */
! 	if (!(systeminclude = open(CONFIG_ROOT "/backup/include.system", O_RDONLY))) {
  		fprintf(stderr, "Couldn't open backup system include file\n");
  		exit (1);
  	}
  
! 	while ((count = read(systeminclude, buffer, STRING_SIZE))) {
! 		if( write (tempfile, buffer, count) < 0 ) {
! 			perror( "temp file write failed" );
! 			exit(1);
! 		}
  	}
+ 	close (systeminclude);
  
! 	/* Duplicate user include to temporary inclusion file */
! 	if (!(userinclude = open(CONFIG_ROOT "/backup/include.user", O_RDONLY))) {
! 		fprintf(stderr, "Couldn't open backup user include file\n");
  		exit (1);
  	}
  
! 	while ((count = read(userinclude, buffer, STRING_SIZE))) {
! 		if( write (tempfile, buffer, count) < 0 ) {
! 			perror( "temp file write failed" );
! 			exit(1);
! 		}
  	}
+ 	close (userinclude);
+ 	close (tempfile);
  
! 	/* Make sure floppy device name is up to date */
! 	safe_system ("/usr/sbin/updfstab");
  
! 	/* Darren Critchley - check for floppy disk in disk drive before continuing */
! 	snprintf (command, STRING_SIZE-1,
! 		"dd if=/dev/floppy of=/dev/null bs=1k count=1 2> /dev/null");
! 	if (safe_system(command)) {
! 		perror( "Error: No floppy in drive or bad floppy in drive" );
! 		exit(1);
  	}
+ 	
+ 	/* Clearing disk */
+ 	safe_system ("/bin/dd if=/dev/zero of=/dev/floppy bs=1k 2> /dev/null");
  
! 	/* Start tarring files to floppy */
! 	snprintf (command, STRING_SIZE-1,
! 		"/bin/tar -T " CONFIG_ROOT
! 			" -X " CONFIG_ROOT "/backup/exclude.system"
! 			" -X " CONFIG_ROOT "/backup/exclude.user"
! 			" -C / -cvzf /dev/floppy",
! 			tempfilename);
! 	safe_system (command);
  
! 	/* Now check it */
! 	safe_system ("/bin/echo '<b>Checking</b>'");
! 	safe_system ("/bin/tar -tzf /dev/floppy");
  
! 	unlink (tempfilename);
! 
! 	exit(0);
  }

Index: Makefile
===================================================================
RCS file: /cvsroot/ipcop/ipcop/src/misc-progs/Makefile,v
retrieving revision 1.5.2.8
retrieving revision 1.5.2.9
diff -C2 -d -r1.5.2.8 -r1.5.2.9
*** Makefile	22 Feb 2006 23:03:02 -0000	1.5.2.8
--- Makefile	29 May 2006 21:07:25 -0000	1.5.2.9
***************
*** 78,81 ****
  	$(COMPILE) -I../install+setup/libsmooth/ ipsecctrl.c setuid.o \
../install+setup/libsmooth/varval.o -o $@  
! ipcopbackup: ipcopbackup.c setuid.o 
! 	$(COMPILE) -lcrypt ipcopbackup.c setuid.o -o $@
--- 78,81 ----
  	$(COMPILE) -I../install+setup/libsmooth/ ipsecctrl.c setuid.o \
../install+setup/libsmooth/varval.o -o $@  
! ipcopbkcfg: ipcopbkcfg.c setuid.o 
! 	$(COMPILE) -lcrypt ipcopbkcfg.c setuid.o -o $@



-------------------------------------------------------
All the advantages of Linux Managed Hosting--Without the Cost and Risk!
Fully trained technicians. The highest number of Red Hat certifications in
the hosting industry. Fanatical Support. Click to learn more
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=107521&bid=248729&dat=121642
_______________________________________________
IPCop-cvs mailing list
IPCop-cvs@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ipcop-cvs


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic