commit 0c3b317cab86de9a9ac645d4155c7238956bfd0c
Author: gottox@rootkit.lan <unknown>
Date: Wed, 19 Dec 2007 00:16:32 +0100
initial checkin
Diffstat:
Makefile | | | 57 | +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
config.mk | | | 19 | +++++++++++++++++++ |
tar.c | | | 57 | +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
3 files changed, 133 insertions(+), 0 deletions(-)
diff --git a/Makefile b/Makefile
@@ -0,0 +1,57 @@
+# tar - a minimal implementation of tar
+# (c) 2007 Enno Boland
+
+include config.mk
+
+SRC = tar.c
+OBJ = ${SRC:.c=.o}
+TARGET = tar
+
+all: options ${TARGET}
+
+options:
+ @echo spiceman build options:
+ @echo "CFLAGS = ${CFLAGS}"
+ @echo "LDFLAGS = ${LDFLAGS}"
+ @echo "CC = ${CC}"
+
+${OBJ}: config.mk
+
+%.o: %.c
+ @echo CC $@
+ @${CC} -c ${CFLAGS} $<
+
+${TARGET}: ${OBJ}
+ @echo CC -o $@
+ @${CC} -o $@ ${OBJ} ${LDFLAGS}
+
+clean:
+ @echo cleaning
+ @rm -f -- ${OBJ} ${TARGET} ${TARGET}-${VERSION}.tar.gz
+
+dist: clean
+ @echo creating dist tarball
+ @mkdir -p ${TARGET}-${VERSION}
+ @cp -R LICENSE Makefile \
+ ${TARGET}.1 ${SRC} ${TARGET}-${VERSION}
+ @tar -cf ${TARGET}-${VERSION}.tar ${TARGET}-${VERSION}
+ @gzip ${TARGET}-${VERSION}.tar
+ @rm -rf ${TARGET}-${VERSION}
+
+install: all
+ @echo installing executable file to ${DESTDIR}${PREFIX}/bin
+ @mkdir -p ${DESTDIR}${PREFIX}/bin
+ @cp -f spiceman ${DESTDIR}${PREFIX}/bin
+ @chmod 755 ${DESTDIR}${PREFIX}/bin/spiceman
+ @echo installing manual page to ${DESTDIR}${MANPREFIX}/man1
+ @mkdir -p ${DESTDIR}${MANPREFIX}/man1
+ @sed "s/VERSION/${VERSION}/g" < spiceman.1 > ${DESTDIR}${MANPREFIX}/man1/spiceman.1
+ @chmod 644 ${DESTDIR}${MANPREFIX}/man1/spiceman.1
+
+uninstall:
+ @echo removing executable file from ${DESTDIR}${PREFIX}/bin
+ @rm -f ${DESTDIR}${PREFIX}/bin/spiceman
+ @echo removing manual page from ${DESTDIR}${MANPREFIX}/man1
+ @rm -f ${DESTDIR}${MANPREFIX}/man1/spiceman.1
+
+.PHONY: all options clean dist install uninstall
diff --git a/config.mk b/config.mk
@@ -0,0 +1,19 @@
+# tar version
+VERSION = 0.0
+
+# Customize below to fit your system
+
+# paths
+PREFIX = /usr/local
+MANPREFIX = ${PREFIX}/share/man
+
+# includes and libs
+INCS = -I. -I/usr/include
+LIBS = -L/usr/lib -lc
+
+# flags
+CFLAGS = -static -Os -g -Wall -Werror ${INCS} -DVERSION=\"${VERSION}\"
+LDFLAGS = -g ${LIBS}
+
+# compiler and linker
+CC = cc
diff --git a/tar.c b/tar.c
@@ -0,0 +1,57 @@
+#include <stdlib.h>
+#include <unistd.h>
+#include <stdio.h>
+
+#define USAGE { puts("tar [xt]"); exit(EXIT_FAILURE); }
+#define FORBLOCK(x,b) for(l = x; l > 0 && (n = read(0,(void *)(b),512)) > 0; l -= n)
+
+/* POSIX tar Header Block, from POSIX 1003.1-1990 */
+struct Header
+{
+ /* Header: 512 Byte */
+ char name[100]; /* 0-99 */
+ char mode[8]; /* 100-107 */
+ char uid[8]; /* 108-115 */
+ char gid[8]; /* 116-123 */
+ char size[12]; /* 124-135 */
+ char mtime[12]; /* 136-147 */
+ char chksum[8]; /* 148-155 */
+ char typeflag; /* 156-156 */
+ char linkname[100]; /* 157-256 */
+ char magic[6]; /* 257-262 */
+ char version[2]; /* 263-264 */
+ char uname[32]; /* 265-296 */
+ char gname[32]; /* 297-328 */
+ char devmajor[8]; /* 329-336 */
+ char devminor[8]; /* 337-344 */
+ char prefix[155]; /* 345-499 */
+ char padding[12]; /* 500-512 */
+};
+
+int main(int argc, char *argv[]) {
+ int a, l, n;
+ char b[512];
+ struct Header h;
+
+ if((argc != 2 || (a = argv[1][0]) == '\0') ||
+ argv[1][1] != '\0' || (a != 't' && a != 'x'))
+ USAGE;
+ while(1) {
+ FORBLOCK(sizeof(h),&h);
+ if(*h.name == '\0')
+ break;
+ else if(l != 0) {
+ fputs("Garbage!\n",stderr);
+ return EXIT_FAILURE;
+ }
+ if(a == 't') {
+ puts(h.name);
+ FORBLOCK(strtoull(h.size,0,8),b);
+ }
+ else {
+ FORBLOCK(strtoull(h.size,0,8),b)
+ puts("open, write, close, chmod, chown");
+ }
+ }
+ return EXIT_SUCCESS;
+}