A
download rpmunpack.c
Language: C
LOC: 70
Project Info
callisto - Unofficial firmware for the Lin...uter.(callisto)
Server: Google
Type: svn
...listo\trunk\router\busybox\
   adjtimex.c
   applets.c
   applets.h
   ar.c
   ash.c
   basename.c
   busybox.c
   busybox.h
   busybox.mkll
   busybox.sh
   busybox.spec
   busyboxold.h
   cat.c
   chgrp.c
   chmod.c
   chmod_chown_chgrp.c
   chown.c
   chroot.c
   chvt.c
   clear.c
   cmdedit.c
   cmdedit.h
   cmp.c
   Config.h
   Config.h.Hurd
   cp.c
   cp_mv.c
   cpio.c
   cut.c
   date.c
   dc.c
   dd.c
   deallocvt.c
   df.c
   dirname.c
   dmesg.c
   dos2unix.c
   dpkg.c
   dpkg_deb.c
   du.c
   dumpkmap.c
   dutmp.c
   echo.c
   env.c
   expr.c
   fbset.c
   fdflush.c
   find.c
   free.c
   freeramdisk.c
   fsck_minix.c
   getopt.c
   grep.c
   gunzip.c
   gzip.c
   halt.c
   head.c
   hostid.c
   hostname.c
   hush.c
   id.c
   ifconfig.c
   init.c
   insmod.c
   install.sh
   interface.c
   kill.c
   klogd.c
   ktab.c
   lash.c
   length.c
   ln.c
   loadacm.c
   loadfont.c
   loadkmap.c
   logger.c
   login.c
   logname.c
   logread.c
   ls.c
   lsmod.c
   makedevs.c
   md5sum.c
   messages.c
   mk_loop_h.sh
   mkdir.c
   mkfifo.c
   mkfs_minix.c
   mknod.c
   mkswap.c
   mktemp.c
   modprobe.c
   more.c
   mount.c
   msh.c
   mt.c
   mtab.c
   mv.c
   nc.c
   nfsmount.c
   nfsmount.h
   nslookup.c
   pidof.c
   ping.c
   pivot_root.c
   poweroff.c
   printf.c
   pristine_setup.sh
   ps.c
   pwd.c
   rdate.c
   readlink.c
   real_loop.h
   reboot.c
   renice.c
   reset.c
   rm.c
   rmdir.c
   rmmod.c
   route.c
   rpm2cpio.c
   rpmunpack.c
   sed.c
   setkeycodes.c
   sh.c
   sleep.c
   sort.c
   stdbool.h
   stty.c
   swaponoff.c
   sync.c
   syslog.c
   syslogd.c
   syslogd.c-0326
   syslogd525.c
   syslogd526.c
   syslogd527.c
   syslogdold.c
   tail.c
   tar.c
   tee.c
   telnet.c
   telnetd.c
   test.c
   tftp.c
   touch.c
   tr.c
   traceroute.c
   true_false.c
   tty.c
   umount.c
   uname.c
   uniq.c
   unix2dos.c
   update.c
   uptime.c
   usage.c
   usage.h
   usleep.c
   utility.c
   uudecode.c
   uuencode.c
   vi.c
   watchdog.c
   wc.c
   wget.c
   which.c
   whoami.c
   xargs.c
   yes.c

/*
 * rpmunpack for busybox
 *
 * rpmunpack.c  -  Utility program to unpack an RPM archive
 *
 * Gero Kuhlmann <gero@gkminix.han.de> 1998
 *
 *  This program is public domain software; you can do whatever you like
 *  with this source, including modifying and redistributing it.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 */
 
#include <fcntl.h>
#include <unistd.h>
#include <string.h>
#include <stdlib.h>
#include "busybox.h" 

/*
 * Some general definitions
 */

#define RPM_MAGIC	"\355\253\356\333"
#define GZ_MAGIC_1	'\037'
#define GZ_MAGIC_2	'\213'

/*
 * Global variables
 */
static char *progname;
static int infile, outfile;

/*
 * Read a specified number of bytes from input file
 */
static void myread(int num, char *buffer)
{
  int err;

  if ((err = read(infile, buffer, num)) != num) {
	if (err < 0)
		perror_msg_and_die(progname);
	else
		error_msg_and_die("Unexpected end of input file!");
  }
}

/*
 * Main program
 */
int rpmunpack_main(int argc, char **argv)
{
  int len, status = 0;
  RESERVE_BB_BUFFER(buffer, BUFSIZ);

  /* Get our own program name */
  if ((progname = strrchr(argv[0], '/')) == NULL)
	progname = argv[0];
  else
	progname++;

  /* Check for command line parameters */
	if (argc>=2 && *argv[1]=='-') {
           show_usage();
	}

  /* Open input file */
  if (argc == 1)
	infile = STDIN_FILENO;
  else if ((infile = open(argv[1], O_RDONLY)) < 0)
	perror_msg_and_die("%s", argv[1]);

  /* Read magic ID and output filename */
  myread(4, buffer);
  if (strncmp(buffer, RPM_MAGIC, 4)) {
	fprintf(stderr, "Input file is not in RPM format!\n");
	exit(1);
  }
  myread(6, buffer);		/* Skip flags */
  myread(64, buffer);
  buffer[64] = '\0';

  /* Open output file */
  strcat(buffer, ".cpio.gz");
  if (infile == STDIN_FILENO)
	outfile = STDOUT_FILENO;
  else if ((outfile = open(buffer, O_WRONLY | O_CREAT | O_TRUNC, 0644)) < 0)
	  perror_msg_and_die("%s", buffer);

  /*
   * Now search for the GZIP signature. This is rather awkward, but I don't
   * know any other way how to find out the exact starting position of the
   * archive within the input file. There are a couple of data structures
   * and texts (obviously descriptions, installation shell scripts etc.)
   * coming before the archive, but even they start at different offsets
   * with different RPM files. However, it looks like the GZIP signature
   * never appears before offset 0x200, so we skip these first couple of
   * bytes to make the signature scan a little more reliable.
   */
  myread(0x200 - 74, buffer);
  while (status < 2) {
	myread(1, buffer);
	if (status == 0 && buffer[0] == GZ_MAGIC_1)
		status++;
	else if (status == 1 && buffer[0] == GZ_MAGIC_2)
		status++;
	else
		status = 0;
  }
  buffer[0] = GZ_MAGIC_1;
  buffer[1] = GZ_MAGIC_2;
  if (write(outfile, buffer, 2) < 0)
	perror_msg_and_die("write");

  /* Now simply copy the GZIP archive into the output file */
  while ((len = read(infile, buffer, BUFSIZ)) > 0) {
	if (write(outfile, buffer, len) < 0)
		perror_msg_and_die("write");
  }
  if (len < 0)
    perror_msg_and_die("read");
  return EXIT_SUCCESS;
}

About Koders | Resources | Downloads | Support | Black Duck | Terms of Service | DMCA | Privacy Policy | Contact Us