Merge tag 'upstream/3.3.3'
[debian/amanda] / client-src / calcsize.c
index 1336d8d1e553c0296d04c3ec04444d9da719c3ab..08e8d053c14c74355da4c84545eca56cc6972e42 100644 (file)
@@ -1,6 +1,7 @@
 /*
  * Amanda, The Advanced Maryland Automatic Network Disk Archiver
  * Copyright (c) 1991-1998 University of Maryland at College Park
+ * Copyright (c) 2007-2012 Zmanda, Inc.  All Rights Reserved.
  * All Rights Reserved.
  *
  * Permission to use, copy, modify, distribute, and sell this software and its
  * argv[1] is the config name or NOCONFIG
  */
 #include "amanda.h"
+#include "match.h"
+#include "conffile.h"
 #include "fsusage.h"
-#include "version.h"
-#include "sl.h"
+#include "am_sl.h"
 #include "util.h"
 
 #define ROUND(n,x)     ((x) + (n) - 1 - (((x) + (n) - 1) % (n)))
@@ -107,12 +109,12 @@ void add_file_name_unknown(int, char *);
 void add_file_unknown(int, struct stat *);
 off_t final_size_unknown(int, char *);
 
-sl_t *calc_load_file(char *filename);
+am_sl_t *calc_load_file(char *filename);
 int calc_check_exclude(char *filename);
 
 int use_star_excl = 0;
 int use_gtar_excl = 0;
-sl_t *include_sl=NULL, *exclude_sl=NULL;
+am_sl_t *include_sl=NULL, *exclude_sl=NULL;
 
 int
 main(
@@ -142,6 +144,7 @@ main(
     set_pname("calcsize");
 
     dbopen(NULL);
+    config_init(CONFIG_INIT_CLIENT, NULL);
 
     /* Don't die when child closes pipe */
     signal(SIGPIPE, SIG_IGN);
@@ -169,12 +172,10 @@ main(
     char *amname=NULL, *qamname=NULL;
     char *filename=NULL, *qfilename = NULL;
 
-    /* drop root privileges; we'll regain them for the required operations */
-#ifdef WANT_SETUID_CLIENT
-    if (!set_root_privs(0)) {
-       error(_("calcsize must be run setuid root"));
+    if (argc > 1 && argv && argv[1] && g_str_equal(argv[1], "--version")) {
+       printf("calcsize-%s\n", VERSION);
+       return (0);
     }
-#endif
 
     safe_fd(-1, 0);
     safe_cd();
@@ -182,10 +183,17 @@ main(
     set_pname("calcsize");
 
     dbopen(DBG_SUBDIR_CLIENT);
-    dbprintf(_("version %s\n"), version());
+    config_init(CONFIG_INIT_CLIENT, NULL);
+    dbprintf(_("version %s\n"), VERSION);
 
-#if 0
-    erroutput_type = (ERR_INTERACTIVE|ERR_SYSLOG);
+    /* drop root privileges; we'll regain them for the required operations */
+#ifdef WANT_SETUID_CLIENT
+    check_running_as(RUNNING_AS_CLIENT_LOGIN | RUNNING_AS_UID_ONLY);
+    if (!set_root_privs(0)) {
+       error(_("calcsize must be run setuid root"));
+    }
+#else
+    check_running_as(RUNNING_AS_CLIENT_LOGIN);
 #endif
 
     argc--, argv++;    /* skip program name */
@@ -205,8 +213,6 @@ main(
     argc--;
     argv++;
 
-    check_running_as(RUNNING_AS_CLIENT_LOGIN);
-
     /* parse backup program name */
 
     if(strcmp(*argv, "DUMP") == 0) {
@@ -677,13 +683,13 @@ final_size_unknown(
 /*
  * =========================================================================
  */
-sl_t *
+am_sl_t *
 calc_load_file(
     char *     filename)
 {
     char pattern[1025];
 
-    sl_t *sl_list;
+    am_sl_t *sl_list;
 
     FILE *file = fopen(filename, "r");