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

List:       ipcop-svn
Subject:    [Ipcop-svn] SF.net SVN: ipcop:[7362] ipcop/trunk
From:       owes () users ! sourceforge ! net
Date:       2014-03-23 15:08:41
Message-ID: E1WRk0z-0007IL-BV () sfs-ml-4 ! v29 ! ch3 ! sourceforge ! com
[Download RAW message or body]

Revision: 7362
          http://sourceforge.net/p/ipcop/svn/7362
Author:   owes
Date:     2014-03-23 15:08:38 +0000 (Sun, 23 Mar 2014)
Log Message:
-----------
Add logging to installpackage.

Modified Paths:
--------------
    ipcop/trunk/src/misc-progs/installpackage.c
    ipcop/trunk/updates/2.1.3/ROOTFILES.i486-2.1.3

Modified: ipcop/trunk/src/misc-progs/installpackage.c
===================================================================
--- ipcop/trunk/src/misc-progs/installpackage.c	2014-03-23 14:11:54 UTC (rev 7361)
+++ ipcop/trunk/src/misc-progs/installpackage.c	2014-03-23 15:08:38 UTC (rev 7362)
@@ -1,13 +1,26 @@
-/* This file is part of the IPCop Firewall.
+/*
+ * This file is part of the IPCop Firewall.
  *
- * This program is distributed under the terms of the GNU General Public
- * Licence.  See the file COPYING for details.
+ * IPCop is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
  *
+ * IPCop 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.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with IPCop.  If not, see <http://www.gnu.org/licenses/>.
+ *
  * Copyright (C) 2004-05-31 Robert Kerr <rkerr@go.to>
  *
  * Loosely based on the smoothwall helper program by the same name,
  * portions are (c) Lawrence Manning, 2001
  *
+ * (c) 2008-2014, the IPCop team
+ *
  * $Id$
  * 
  */
@@ -28,35 +41,104 @@
 #include "setuid.h"
 
 
+#define ERR_NO_ERROR            0
 #define ERR_ANY                 1
 #define ERR_TMPDIR              2
 #define ERR_SIG                 3
 #define ERR_TAR                 4
 #define ERR_INFO                5
-#define ERR_PACKLIST            6
-#define ERR_INSTALLED           7
+#define ERR_PACKLIST            6       // not used
+#define ERR_INSTALLED           7       // not used, should be returned by setup
 #define ERR_SETUP               9
-#define ERR_MISSING_PREVIOUS    10
+#define ERR_MISSING_PREVIOUS    10      // not used
 #define ERR_DISK                11
 
+#define ERR_SUID                20      // identical error code to backup/restore
 
+
 /* Supplement of available space on disk to be safe to untar on setup. */
 #define MINIMUMSPACE 1500 * 1000
 
 static char command[STRING_SIZE];
 static char tmpdir[] = "/var/patches/install_XXXXXX";
+static int tmpdir_created = 0;
+static int ret;
 
 
-void exithandler(void)
+static void ourexit(int err)
 {
-    /* Cleanup tmpdir */
-    if (chdir("/var/patches") != 0) {
-        perror("Couldn't chdir to /var/patches");
+    if (tmpdir_created) {
+        /* Cleanup tmpdir */
+        if (chdir("/var/patches") != 0) {
+            perror("Couldn't chdir to /var/patches");
+        }
+        snprintf(command, STRING_SIZE, "/bin/rm -rf %s", tmpdir);
+        if(safe_system(command)) {
+            perror("Couldn't remove temp dir");
+        }
     }
-    snprintf(command, STRING_SIZE, "/bin/rm -rf %s", tmpdir);
-    if(safe_system(command)) {
-        perror("Couldn't remove temp dir");
+
+    /* 
+     * Log only in case of error, setup will do logging in case of success.
+     * Errors might be duplicated, when the error is detected in setup.
+     */
+    if (err) {
+        switch (err) {
+        case ERR_TMPDIR:
+            snprintf(command, STRING_SIZE, 
+                "/usr/bin/logger -t installpackage \"ERROR (%d): Could not create \
directory.\"", err); +            break;
+        case ERR_SIG:
+            snprintf(command, STRING_SIZE, 
+                "/usr/bin/logger -t installpackage \"ERROR (%d): This is not an \
authorised update.\"", err); +            break;
+        case ERR_TAR:
+            snprintf(command, STRING_SIZE,
+                "/usr/bin/logger -t installpackage \"ERROR (%d): This is not a valid \
archive.\"", err); +            break;
+        case ERR_INFO:
+            snprintf(command, STRING_SIZE,
+                "/usr/bin/logger -t installpackage \"ERROR (%d): Could not open \
update information file. The update file is corrupt.\"", err); +            break;
+        case ERR_PACKLIST:
+            snprintf(command, STRING_SIZE,
+                "/usr/bin/logger -t installpackage \"ERROR (%d): Could not open \
installed updates file.\"", err); +            break;
+        case ERR_INSTALLED:
+            snprintf(command, STRING_SIZE,
+                "/usr/bin/logger -t installpackage \"ERROR (%d): This update is \
already installed.\"", err); +            break;
+        case ERR_SETUP:
+            snprintf(command, STRING_SIZE,
+                "/usr/bin/logger -t installpackage \"ERROR (%d): Setup script \
returned errorcode (%d).\"", err, ret); +            break;
+        case ERR_MISSING_PREVIOUS:
+            /* no text ? */
+            snprintf(command, STRING_SIZE,
+                "/usr/bin/logger -t installpackage \"ERROR (%d): \
ERR_MISSING_PREVIOUS.\"", err); +            break;
+        case ERR_DISK:
+            snprintf(command, STRING_SIZE,
+                "/usr/bin/logger -t installpackage \"ERROR (%d): Not enough disk \
space.\"", err); +            break;
+        case ERR_SUID:
+            snprintf(command, STRING_SIZE,
+                "/usr/bin/logger -t installpackage \"ERROR (%d): Could not \
initsetuid.\"", err); +            break;
+        default:
+            snprintf(command, STRING_SIZE,
+                "/usr/bin/logger -t installpackage \"ERROR (%d)\"", err);
+            break;
+        }
+        safe_system(command);
+
+        /* Errorcode for updates.cgi GUI page */
+        snprintf(command, STRING_SIZE, "echo %d > /var/patches/error", err);
+        safe_system(command);
+        snprintf(command, STRING_SIZE, "chown nobody.nobody /var/patches/error");
+        safe_system(command);
     }
+    exit(err);
 }
 
 
@@ -72,13 +154,12 @@
 }
 
 
-int main(int argc, char *argv[])
+void main(int argc, char *argv[])
 {
     int flag_install = 0;
     int flag_test = 0;
     char *upgrade_filename = NULL;
     char signature_filename[STRING_SIZE];
-    int ret;
     struct stat stbuf;
     struct statvfs statvfsbuf;
     double spaceavailable, rootspacerequired;
@@ -95,7 +176,7 @@
     int option_index = 0;
 
     if (!(initsetuid()))
-        exit(1);
+        ourexit(ERR_SUID);
 
     while ((c = getopt_long(argc, argv, "i:t:v", long_options, &option_index)) != \
-1) {  switch (c) {
@@ -120,19 +201,17 @@
 
     if (!flag_install && !flag_test) {
         fprintf(stderr, "option missing\n");
-        usage(argv[0], 2);
+        usage(argv[0], 1);
     }
 
-    atexit(exithandler);
-
     /* Some basic upgrade filename checks */
     if (strchr(upgrade_filename, '/') == NULL) {
         fprintf(stderr, "Incomplete filename %s\n", upgrade_filename);
-        exit(ERR_ANY);
+        ourexit(ERR_ANY);
     }
     if (strstr(upgrade_filename, ".tgz.gpg") == NULL) {
         fprintf(stderr, "Not a compressed gpg file %s\n", upgrade_filename);
-        exit(ERR_ANY);
+        ourexit(ERR_ANY);
     }
     snprintf(signature_filename, STRING_SIZE, "/var/patches/%s", \
strrchr(upgrade_filename, '/'));  strcpy(strstr(signature_filename, ".tgz.gpg"), \
".sig"); @@ -140,7 +219,7 @@
     /* Read size of the patch file */
     if (lstat(upgrade_filename, &stbuf)) {
         fprintf(stderr, "Unable to stat %s\n", upgrade_filename);
-        exit(ERR_ANY);
+        ourexit(ERR_ANY);
     }
     fprintf(stdout, "Update size is %ld KiB\n", stbuf.st_size / 1024);
     rootspacerequired = 2 * stbuf.st_size + MINIMUMSPACE;
@@ -149,7 +228,7 @@
     /* Check space available on disk to decrypt the gpg file */
     if (statvfs("/var/patches", &statvfsbuf)) {
         fprintf(stderr, "Couldn't test available space on rootfs partition.\n");
-        exit(ERR_ANY);
+        ourexit(ERR_ANY);
     }
     spaceavailable = statvfsbuf.f_frsize * statvfsbuf.f_bavail;
     fprintf(stdout,"Available space on rootfs is %4.0lf KiB\n", spaceavailable / \
1024 ); @@ -163,7 +242,7 @@
             "As disk buffers are smaller on boot, rebooting may help\n",
             spaceavailable / 1024 ,
             rootspacerequired / 1024);
-        exit(ERR_DISK);
+        ourexit(ERR_DISK);
     }
 
     /* Process is :
@@ -175,8 +254,9 @@
 
     if (!mkdtemp(tmpdir)) {
         perror("Unable to create secure temp dir");
-        exit(ERR_TMPDIR);
+        ourexit(ERR_TMPDIR);
     }
+    tmpdir_created = 1;
 
     /* Verify and extract package */
     snprintf(command, STRING_SIZE,
@@ -189,13 +269,13 @@
         break;
     case 1:         /* 1=> gpg-key error */
         fprintf(stderr, "Invalid package: signature check failed\n");
-        exit(ERR_SIG);
+        ourexit(ERR_SIG);
     case 2:         /* 2=> gpg pub key not found */
         fprintf(stderr, "Public signature not found (who signed package?) !\n");
-        exit(ERR_SIG);
+        ourexit(ERR_SIG);
     default:
         fprintf(stderr, "gpg returned: %d\n", ret);
-        exit(ERR_SIG);
+        ourexit(ERR_SIG);
     }
 
     /* prepare signature for display, take only the 2 first lines */
@@ -208,7 +288,7 @@
     snprintf(command, STRING_SIZE, "/bin/tar xzf %s/patch-1.tgz -C /var/patches \
information.xml", tmpdir);  if (safe_system(command)) {
         fprintf(stderr, "Invalid package: contains no information file\n");
-        exit(ERR_INFO);
+        ourexit(ERR_INFO);
     }
 
     if (flag_test) {
@@ -218,7 +298,7 @@
         safe_system(command);
 
         /* exithandler will do the cleaning */
-        exit(0);
+        ourexit(ERR_NO_ERROR);
     }
 
     /*
@@ -232,13 +312,13 @@
 
     if (chdir (tmpdir)) {
         perror("Unable to chdir to temp dir");
-        exit(ERR_TMPDIR);
+        ourexit(ERR_TMPDIR);
     }
     /* unzip the package */
     snprintf(command, STRING_SIZE, "/bin/tar xzf %s/patch-1.tgz", tmpdir);
     if (safe_system(command)) {
         fprintf(stderr, "Invalid package: untar failed\n");
-        exit(ERR_TAR);
+        ourexit(ERR_TAR);
     }
 
     /* patch-1 is no more needed, free that space */
@@ -251,7 +331,7 @@
     ret = safe_system(command)>>8;
     if (ret) {
         fprintf(stderr, "setup script returned exit code %d\n", ret);
-        exit(ERR_SETUP);
+        ourexit(ERR_SETUP);
     }
 
     /* update list of installed patches */
@@ -260,5 +340,5 @@
         tmpdir);
     safe_system(command);
 
-    exit(0);
+    ourexit(0);
 }

Modified: ipcop/trunk/updates/2.1.3/ROOTFILES.i486-2.1.3
===================================================================
--- ipcop/trunk/updates/2.1.3/ROOTFILES.i486-2.1.3	2014-03-23 14:11:54 UTC (rev 7361)
+++ ipcop/trunk/updates/2.1.3/ROOTFILES.i486-2.1.3	2014-03-23 15:08:38 UTC (rev 7362)
@@ -8,6 +8,7 @@
 /home/httpd/cgi-bin/urlfilter.cgi
 /usr/lib/ipcop/firewall-lib.pl
 /usr/local/bin/emailhelper
+/usr/local/bin/installpackage
 /usr/local/bin/makegraphs.pl
 /usr/local/bin/vpn-watch
 /usr/share/locale/el_GR/LC_MESSAGES/ipcop.mo

This was sent by the SourceForge.net collaborative development platform, the world's \
largest Open Source development site.


------------------------------------------------------------------------------
Learn Graph Databases - Download FREE O'Reilly Book
"Graph Databases" is the definitive new guide to graph databases and their
applications. Written by three acclaimed leaders in the field,
this first edition is now available. Download your free book today!
http://p.sf.net/sfu/13534_NeoTech
_______________________________________________
Ipcop-svn mailing list
Ipcop-svn@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ipcop-svn


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

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