summaryrefslogtreecommitdiffstats
path: root/isomd5sum
diff options
context:
space:
mode:
authorMike Fulbright <msf@redhat.com>2003-03-21 16:30:43 +0000
committerMike Fulbright <msf@redhat.com>2003-03-21 16:30:43 +0000
commitdd652f84b1e0de892e10e19ac75bd175230bece6 (patch)
tree2788ecdc46ae12ed68f49939950fd308d9569a2a /isomd5sum
parentc29f0955045cdd02965a14300ce5e99364db2d1b (diff)
downloadanaconda-dd652f84b1e0de892e10e19ac75bd175230bece6.tar.gz
anaconda-dd652f84b1e0de892e10e19ac75bd175230bece6.tar.xz
anaconda-dd652f84b1e0de892e10e19ac75bd175230bece6.zip
added python module for easy scripting of implanting and checking md5sums for tim
Diffstat (limited to 'isomd5sum')
-rw-r--r--isomd5sum/Makefile7
-rw-r--r--isomd5sum/checkisomd5.c2
-rw-r--r--isomd5sum/implantisomd5.c10
-rw-r--r--isomd5sum/libcheckisomd5.c39
-rw-r--r--isomd5sum/libcheckisomd5.h2
-rw-r--r--isomd5sum/libimplantisomd5.c27
-rw-r--r--isomd5sum/libimplantisomd5.h2
-rw-r--r--isomd5sum/pyisomd5sum.c48
-rwxr-xr-xisomd5sum/testpyisomd5sum.py22
9 files changed, 125 insertions, 34 deletions
diff --git a/isomd5sum/Makefile b/isomd5sum/Makefile
index 3166c654e..11b987357 100644
--- a/isomd5sum/Makefile
+++ b/isomd5sum/Makefile
@@ -1,18 +1,21 @@
include ../Makefile.inc
-all:
+all:
gcc -c -O -g -D_FILE_OFFSET_BITS=64 md5.c
gcc -c -O -g -D_FILE_OFFSET_BITS=64 libimplantisomd5.c
gcc -O -g -D_FILE_OFFSET_BITS=64 -o implantisomd5 implantisomd5.c libimplantisomd5.o md5.o -lm -lpopt
gcc -c -O -g -D_FILE_OFFSET_BITS=64 libcheckisomd5.c
gcc -O -g -D_FILE_OFFSET_BITS=64 -o checkisomd5 checkisomd5.c libcheckisomd5.o md5.o -lm
+ gcc -c -O -g -fPIC -o pyisomd5sum.lo pyisomd5sum.c -I$(PYTHONINCLUDE)
+ gcc -shared -g -o pyisomd5sum.so -fpic pyisomd5sum.lo libcheckisomd5.o libimplantisomd5.o md5.o
+
install:
install -m 755 implantisomd5 $(DESTDIR)/$(RUNTIMEDIR)
install -m 755 checkisomd5 $(DESTDIR)/$(RUNTIMEDIR)
clean:
- rm -f *.o
+ rm -f *.o *.lo *.so *.pyc
rm -f implantisomd5 checkisomd5
depend:
diff --git a/isomd5sum/checkisomd5.c b/isomd5sum/checkisomd5.c
index 177d10ef4..6ddd37fdf 100644
--- a/isomd5sum/checkisomd5.c
+++ b/isomd5sum/checkisomd5.c
@@ -21,7 +21,7 @@ int main(int argc, char **argv) {
exit(0);
}
- rc = mediaCheckFile(argv[1]);
+ rc = mediaCheckFile(argv[1], 1);
exit(rc ? 0 : 1);
}
diff --git a/isomd5sum/implantisomd5.c b/isomd5sum/implantisomd5.c
index 589fb8e49..5334c4b27 100644
--- a/isomd5sum/implantisomd5.c
+++ b/isomd5sum/implantisomd5.c
@@ -50,7 +50,11 @@ int main(int argc, char **argv) {
if (!args || !args[0] || !args[0][0])
usage();
- rc = implantISOFile((char *)args[0], supported, forceit, errstr);
- if (rc)
- fprintf(stderr, errstr);
+ rc = implantISOFile((char *)args[0], supported, forceit, 0, &errstr);
+ if (rc) {
+ fprintf(stderr, "ERROR: %s\n", errstr);
+ exit(1);
+ } else {
+ exit(0);
+ }
}
diff --git a/isomd5sum/libcheckisomd5.c b/isomd5sum/libcheckisomd5.c
index a13dc13a4..621bd92c0 100644
--- a/isomd5sum/libcheckisomd5.c
+++ b/isomd5sum/libcheckisomd5.c
@@ -20,7 +20,7 @@
/* finds primary volume descriptor and returns info from it */
/* mediasum must be a preallocated buffer at least 33 bytes long */
-int parsepvd(int isofd, char *mediasum, int *skipsectors, long long *isosize, int *supported) {
+static int parsepvd(int isofd, char *mediasum, int *skipsectors, long long *isosize, int *supported) {
unsigned char buf[2048];
unsigned char buf2[512];
unsigned char tmpbuf[512];
@@ -117,7 +117,7 @@ int parsepvd(int isofd, char *mediasum, int *skipsectors, long long *isosize, in
/* returns -1 if no checksum encoded in media, 0 if no match, 1 if match */
/* mediasum is the sum encoded in media, computedsum is one we compute */
/* both strings must be pre-allocated at least 33 chars in length */
-int checkmd5sum(int isofd, char *mediasum, char *computedsum) {
+static int checkmd5sum(int isofd, char *mediasum, char *computedsum, int quiet) {
int nread;
int i;
int appdata_start_offset, appdata_end_offset;
@@ -145,8 +145,11 @@ int checkmd5sum(int isofd, char *mediasum, char *computedsum) {
apoff = pvd_offset + APPDATA_OFFSET;
buf = malloc(bufsize * sizeof(unsigned char));
- printf("Percent complete: %05.1f%%", (100.0*offset)/(isosize-skipsectors*2048.0));
- fflush(stdout);
+ if (!quiet) {
+ printf("Percent complete: %05.1f%%", (100.0*offset)/(isosize-skipsectors*2048.0));
+ fflush(stdout);
+ }
+
while (offset < isosize - skipsectors*2048) {
nattempt = MIN(isosize - skipsectors*2048 - offset, bufsize);
@@ -178,12 +181,16 @@ int checkmd5sum(int isofd, char *mediasum, char *computedsum) {
MD5_Update(&md5ctx, buf, nread);
offset = offset + nread;
- printf("\b\b\b\b\b\b%05.1f%%", (100.0*offset)/(isosize-skipsectors*2048.0));
- fflush(stdout);
+ if (!quiet) {
+ printf("\b\b\b\b\b\b%05.1f%%", (100.0*offset)/(isosize-skipsectors*2048.0));
+ fflush(stdout);
+ }
+ }
+
+ if (!quiet) {
+ printf("\b\b\b\b\b\b\n\n", (100.0*offset)/(isosize-skipsectors*2048.0));
}
- printf("\b\b\b\b\b\b\n\n", (100.0*offset)/(isosize-skipsectors*2048.0));
-
sleep(1);
free(buf);
@@ -223,7 +230,7 @@ static void readCB(void *co, long long pos) {
}
#endif
-int doMediaCheck(int isofd, char *mediasum, char *computedsum, long long *isosize, int *supported) {
+static int doMediaCheck(int isofd, char *mediasum, char *computedsum, long long *isosize, int *supported, int quiet) {
int rc;
int llen;
int skipsectors;
@@ -236,12 +243,12 @@ int doMediaCheck(int isofd, char *mediasum, char *computedsum, long long *isosiz
return -1;
}
- rc = checkmd5sum(isofd, mediasum, computedsum);
+ rc = checkmd5sum(isofd, mediasum, computedsum, quiet);
return rc;
}
-int mediaCheckFile(char *file) {
+int mediaCheckFile(char *file, int quiet) {
int isofd;
int rc;
char *result;
@@ -257,14 +264,15 @@ int mediaCheckFile(char *file) {
return -1;
}
- rc = doMediaCheck(isofd, mediasum, computedsum, &isosize, &supported);
+ rc = doMediaCheck(isofd, mediasum, computedsum, &isosize, &supported, quiet);
close(isofd);
/* printf("isosize = %lld\n", isosize);
printf("%s\n%s\n", mediasum, computedsum);*/
- fprintf(stderr, "The supported flag value is %d\n", supported);
+ if (!quiet)
+ fprintf(stderr, "The supported flag value is %d\n", supported);
if ( rc == 0)
result = "FAIL.\n\nIt is not recommended to use this media.";
@@ -273,8 +281,9 @@ int mediaCheckFile(char *file) {
else
result = "NA.\n\nNo checksum information available, unable to verify media.";
- fprintf(stderr, "The media check is complete, the "
- "result is: %s\n", result);
+ if (!quiet)
+ fprintf(stderr, "The media check is complete, the "
+ "result is: %s\n", result);
return rc;
}
diff --git a/isomd5sum/libcheckisomd5.h b/isomd5sum/libcheckisomd5.h
index 0ce7f0bd5..79376b80e 100644
--- a/isomd5sum/libcheckisomd5.h
+++ b/isomd5sum/libcheckisomd5.h
@@ -1,6 +1,6 @@
#ifndef __LIBCHECKISOMD5_H__
#define __LIBCHECKISOMD5_H__
-int mediaCheckFile(char *iso);
+int mediaCheckFile(char *iso, int quiet);
#endif
diff --git a/isomd5sum/libimplantisomd5.c b/isomd5sum/libimplantisomd5.c
index 55bb73f2d..33c223b09 100644
--- a/isomd5sum/libimplantisomd5.c
+++ b/isomd5sum/libimplantisomd5.c
@@ -6,6 +6,7 @@
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
+#include <string.h>
#include "md5.h"
#include "libimplantisomd5.h"
@@ -21,7 +22,7 @@
/* finds primary volume descriptor and returns info from it */
/* mediasum must be a preallocated buffer at least 33 bytes long */
-int parsepvd(int isofd, char *mediasum, long long *isosize) {
+static int parsepvd(int isofd, char *mediasum, long long *isosize) {
unsigned char buf[2048];
long long offset;
unsigned char *p;
@@ -65,7 +66,7 @@ int parsepvd(int isofd, char *mediasum, long long *isosize) {
}
-unsigned int writeAppData(unsigned char *appdata, char *valstr, unsigned int loc) {
+static unsigned int writeAppData(unsigned char *appdata, char *valstr, unsigned int loc) {
if (loc + strlen(valstr) > 511) {
printf("Attempted to write too much appdata, exiting...\n");
exit(-1);
@@ -83,7 +84,7 @@ static void usage(void) {
}
-int implantISOFile(char *fname, int supported, int forceit, char *errstr) {
+int implantISOFile(char *fname, int supported, int forceit, int quiet, char **errstr) {
int i;
int rc;
int isofd;
@@ -103,13 +104,13 @@ int implantISOFile(char *fname, int supported, int forceit, char *errstr) {
isofd = open(fname, O_RDWR);
if (isofd < 0) {
- errstr = "Error - Unable to open file %s\n\n";
+ *errstr = "Error - Unable to open file %s\n\n";
return -1;
}
pvd_offset = parsepvd(isofd, mediasum, &isosize);
if (pvd_offset < 0) {
- errstr = "Could not find primary volumne!\n\n";
+ *errstr = "Could not find primary volumne!\n\n";
return -1;
}
@@ -123,7 +124,7 @@ int implantISOFile(char *fname, int supported, int forceit, char *errstr) {
dirty = 1;
if (dirty) {
- errstr = "Application data has been used - not implanting md5sum!\n";
+ *errstr = "Application data has been used - not implanting md5sum!\n";
return -1;
}
} else {
@@ -163,8 +164,10 @@ int implantISOFile(char *fname, int supported, int forceit, char *errstr) {
strcat(md5str, tmpstr);
}
- printf("Inserting md5sum into iso image...\n");
- printf("md5 = %s\n", md5str);
+ if (!quiet) {
+ printf("Inserting md5sum into iso image...\n");
+ printf("md5 = %s\n", md5str);
+ }
/* memcpy(new_appdata, orig_appdata, 512); */
memset(new_appdata, ' ', 512);
@@ -177,10 +180,12 @@ int implantISOFile(char *fname, int supported, int forceit, char *errstr) {
loc = writeAppData(new_appdata, ";", loc);
if (supported) {
- printf("Setting supported flag to 1\n");
+ if (!quiet)
+ printf("Setting supported flag to 1\n");
loc = writeAppData(new_appdata, "RHLISOSTATUS=1", loc);
} else {
- printf("Setting supported flag to 0\n");
+ if (!quiet)
+ printf("Setting supported flag to 0\n");
loc = writeAppData(new_appdata, "RHLISOSTATUS=0", loc);
}
@@ -199,6 +204,6 @@ int implantISOFile(char *fname, int supported, int forceit, char *errstr) {
}
close(isofd);
-
+ errstr = NULL;
return 0;
}
diff --git a/isomd5sum/libimplantisomd5.h b/isomd5sum/libimplantisomd5.h
index f5a983297..92fddb504 100644
--- a/isomd5sum/libimplantisomd5.h
+++ b/isomd5sum/libimplantisomd5.h
@@ -1,5 +1,5 @@
#ifndef __LIBIMPLANTISOMD5_H__
#define __LIBIMPLANTISOMD5_H__
-int implantISOFile(char *iso, int supported, int forceit, char *errstr);
+int implantISOFile(char *iso, int supported, int forceit, int quiet, char **errstr);
#endif
diff --git a/isomd5sum/pyisomd5sum.c b/isomd5sum/pyisomd5sum.c
new file mode 100644
index 000000000..feb7e002f
--- /dev/null
+++ b/isomd5sum/pyisomd5sum.c
@@ -0,0 +1,48 @@
+#include <stdio.h>
+
+#include "Python.h"
+#include "libcheckisomd5.h"
+#include "libimplantisomd5.h"
+
+static PyObject * doCheckIsoMD5Sum(PyObject * s, PyObject * args);
+static PyObject * doImplantIsoMD5Sum(PyObject * s, PyObject * args);
+
+static PyMethodDef isomd5sumMethods[] = {
+ { "checkisomd5sum", (PyCFunction) doCheckIsoMD5Sum, METH_VARARGS, NULL },
+ { "implantisomd5sum", (PyCFunction) doImplantIsoMD5Sum, METH_VARARGS, NULL },
+ { NULL }
+} ;
+
+
+static PyObject * doCheckIsoMD5Sum(PyObject * s, PyObject * args) {
+ char *isofile;
+ int rc;
+
+ if (!PyArg_ParseTuple(args, "s", &isofile))
+ return NULL;
+
+ rc = mediaCheckFile(isofile, 1);
+
+ return Py_BuildValue("i", rc);
+}
+
+static PyObject * doImplantIsoMD5Sum(PyObject * s, PyObject * args) {
+ char *isofile, *errstr;
+ int forceit, supported;
+ int rc;
+
+ if (!PyArg_ParseTuple(args, "sii", &isofile, &supported, &forceit))
+ return NULL;
+
+ rc = implantISOFile(isofile, supported, forceit, 1, &errstr);
+
+ return Py_BuildValue("i", rc);
+}
+
+
+void initpyisomd5sum(void) {
+ PyObject * m, * d;
+
+ m = Py_InitModule("pyisomd5sum", isomd5sumMethods);
+ d = PyModule_GetDict(m);
+}
diff --git a/isomd5sum/testpyisomd5sum.py b/isomd5sum/testpyisomd5sum.py
new file mode 100755
index 000000000..6f79830cf
--- /dev/null
+++ b/isomd5sum/testpyisomd5sum.py
@@ -0,0 +1,22 @@
+#!/usr/bin/python
+
+import os
+import pyisomd5sum
+
+# create iso file
+os.system("mkisofs -quiet . > testiso.iso")
+
+# implant it
+print "Implanting -> ", pyisomd5sum.implantisomd5sum("testiso.iso", 1, 0)
+
+# do it again without forcing, should get error
+print "Implanting again w/o forcing -> ", pyisomd5sum.implantisomd5sum("testiso.iso", 1, 0)
+
+# do it again with forcing, should work
+print "Implanting again forcing -> ", pyisomd5sum.implantisomd5sum("testiso.iso", 1, 1)
+
+# check it
+print "Checking -> ",pyisomd5sum.checkisomd5sum("testiso.iso")
+
+# clean up
+os.unlink("testiso.iso")