summaryrefslogtreecommitdiff
path: root/debian/bash.preinst.c
diff options
context:
space:
mode:
authorStephen Hemminger <stephen.hemminger@vyatta.com>2010-04-09 16:13:32 -0700
committerStephen Hemminger <stephen.hemminger@vyatta.com>2010-04-09 16:15:01 -0700
commit2d698b6e42d8dca191ac795ef5dba3bf62496eec (patch)
treeac5e0b67043c50f49160e9fe407435706cf30444 /debian/bash.preinst.c
parentf1250933e4a2ac09a3d0b25b3877068e12f44da5 (diff)
downloadvyatta-bash-2d698b6e42d8dca191ac795ef5dba3bf62496eec.tar.gz
vyatta-bash-2d698b6e42d8dca191ac795ef5dba3bf62496eec.zip
Integrate bash 3.2 version
This is merge of current Debian stable (Lenny) version of Bash with Vyatta changes.
Diffstat (limited to 'debian/bash.preinst.c')
-rw-r--r--debian/bash.preinst.c112
1 files changed, 109 insertions, 3 deletions
diff --git a/debian/bash.preinst.c b/debian/bash.preinst.c
index ff22653..524e126 100644
--- a/debian/bash.preinst.c
+++ b/debian/bash.preinst.c
@@ -1,5 +1,6 @@
/* Copyright (c) 1999 Anthony Towns
* Copyright (c) 2000, 2002 Matthias Klose
+ * Copyright (c) 2008 Canonical Ltd
*
* You may freely use, distribute, and modify this program.
*/
@@ -20,6 +21,8 @@
#define PATH_MAX 4096
#endif
+#include "md5.h"
+
int check_predepends(void)
{
pid_t child;
@@ -53,6 +56,81 @@ int check_predepends(void)
return EXIT_FAILURE;
}
+#define BUFSIZE 8192
+
+int md5sum_match(char *fn, char* fn_digest)
+{
+ md5_state_t md5;
+ md5_byte_t digest[16];
+ unsigned char hexdigest[33];
+ int i, j, fd;
+ size_t nbytes;
+ md5_byte_t buf[BUFSIZE];
+
+ // if not existant, md5sums don't match
+ if (access(fn, R_OK))
+ return 0;
+ if ((fd = open(fn, O_RDONLY)) == -1)
+ return 0;
+
+ md5_init(&md5);
+ while (nbytes = read(fd, buf, BUFSIZE))
+ md5_append(&md5, buf, nbytes);
+ md5_finish(&md5, digest);
+ close(fd);
+
+ for (i = j = 0; i < 16; i++) {
+ unsigned char c;
+ c = (digest[i] >> 4) & 0xf;
+ c = (c > 9) ? c + 'a' - 10 : c + '0';
+ hexdigest[j++] = c;
+ c = (digest[i] & 0xf);
+ c = (c > 9) ? c + 'a' - 10 : c + '0';
+ hexdigest[j++] = c;
+ }
+ hexdigest[j] = '\0';
+#ifdef NDEBUG
+ fprintf(stderr, "fn=%s, md5sum=%s, expected=%s\n", fn, hexdigest, fn_digest);
+#endif
+ return !strcmp(fn_digest, hexdigest);
+}
+
+int unmodified_file(char *fn, int md5sumc, unsigned char* md5sumv[])
+{
+ int i;
+
+ // if not existant, pretend its unmodified
+ if (access(fn, R_OK))
+ return 1;
+ for (i = 0; i < md5sumc; i++) {
+ if (md5sum_match(fn, md5sumv[i]))
+ return 1;
+ }
+ return 0;
+}
+
+unsigned char *md5sumv_bash_profile[] = {
+ "d1a8c44e7dd1bed2f3e75d1343b6e4e1", // dapper, edgy, etch
+ "0bc1802860b758732b862ef973cd79ff", // feisty, gutsy
+};
+const int md5sumc_bash_profile = sizeof(md5sumv_bash_profile) / sizeof (char *);
+
+unsigned char *md5sumv_profile[] = {
+ "7d97942254c076a2ea5ea72180266420", // feisty, gutsy
+};
+const int md5sumc_profile = sizeof(md5sumv_profile) / sizeof (char *);
+
+#ifdef BC_CONFIG
+unsigned char *md5sumv_completion[] = {
+ "2bc0b6cf841eefd31d607e618f1ae29d", // dapper
+ "ae1d298e51ea7f8253eea8b99333561f", // edgy
+ "adc2e9fec28bd2d4a720e725294650f0", // feisty
+ "c8bce25ea68fb0312579a421df99955c", // gutsy, and last one in bash
+ "9da8d1c95748865d516764fb9af82af9", // etch, sid (last one in bash)
+};
+const int md5sumc_completion = sizeof(md5sumv_completion) / sizeof (char *);
+#endif
+
char *check_diversion(void)
{
pid_t child;
@@ -105,13 +183,40 @@ char *check_diversion(void)
const char *msg =
"As bash for Debian is destined to provide a working /bin/sh (pointing to\n"
"/bin/bash) your link will be overwritten by a default link.\n\n"
- "If you don't want further upgrades to overwrite your customization,\n"
- "please read /usr/share/doc/bash/README.Debian for a more permanent solution.\n\n"
+ "If you don't want further upgrades to overwrite your customization, please\n"
+ "read /usr/share/doc/bash/README.Debian.gz for a more permanent solution.\n\n"
"[Press RETURN to continue]";
int main(void) {
int targetlen;
- char target[PATH_MAX+1], answer[1024];
+ char target[PATH_MAX+1], answer[1024], *fn;
+
+ fn = "/etc/skel/.bash_profile";
+ if (!access(fn, R_OK)) {
+ if (unmodified_file(fn, md5sumc_bash_profile, md5sumv_bash_profile)) {
+ printf("removing %s in favour of /etc/skel/.profile\n", fn);
+ unlink(fn);
+ }
+ else {
+ fn = "/etc/skel/.profile";
+ if (!access(fn, R_OK)) {
+ if (unmodified_file(fn, md5sumc_profile, md5sumv_profile)) {
+ printf("renaming /etc/skel/.bash_profile to %s\n", fn);
+ rename("/etc/skel/.bash_profile", fn);
+ }
+ }
+ }
+ }
+
+#ifdef BC_CONFIG
+ fn = "/etc/bash_completion";
+ if (!access(fn, R_OK)) {
+ if (unmodified_file(fn, md5sumc_completion, md5sumv_completion)) {
+ printf("removing unmodified %s, now in package bash-completion\n", fn);
+ unlink(fn);
+ }
+ }
+#endif
if (check_predepends() != EXIT_SUCCESS) {
printf("\nPlease upgrade to a new version of dpkg\n\n");
@@ -140,5 +245,6 @@ int main(void) {
fgets(answer, 1024, stdin);
return EXIT_SUCCESS;
}
+
return EXIT_SUCCESS;
}