commit untracked files ... confusing
[debian/amanda] / restore-src / amidxtaped.c
index 93d93506577a6b55531aba9b60122906e4ad545b..2e7492c87a096988a9e2c6231b8938cf7646e056 100644 (file)
@@ -23,7 +23,7 @@
  * Authors: the Amanda Development Team.  Its members are listed in a
  * file named AUTHORS, in the root directory of this distribution.
  */
-/* $Id: amidxtaped.c,v 1.73.2.1 2006/09/27 12:04:09 martinea Exp $
+/* $Id: amidxtaped.c,v 1.73 2006/07/25 19:06:46 martinea Exp $
  *
  * This daemon extracts a dump image off a tape for amrecover and
  * returns it over the network. It basically, reads a number of
 #include "stream.h"
 #include "amandad.h"
 
+#define amidxtaped_debug(i,x) do {     \
+       if ((i) <= debug_amidxtaped) {  \
+           dbprintf(x);                \
+       }                               \
+} while (0)
+
 #define TIMEOUT 30
 
 static char *pgm = "amidxtaped";       /* in case argv[0] is not set */
@@ -188,7 +194,7 @@ check_security_buffer(
     char *errstr = NULL;
 
     dbprintf(("%s: check_security_buffer(buffer='%s')\n",
-               debug_prefix(NULL), buffer));
+               debug_prefix_time(NULL), buffer));
 
     i = SIZEOF(addr);
     if (getpeername(0, (struct sockaddr *)&addr, &i) == -1) {
@@ -219,7 +225,7 @@ check_security_buffer(
        /*NOTREACHED*/
     }
     skip_whitespace(s, ch);
-    if (!check_security(&addr, s-1, 0, &errstr)) {
+    if (!check_security((struct sockaddr_storage *)&addr, s-1, 0, &errstr)) {
        error("security check failed: %s", errstr);
        /*NOTREACHED*/
     }
@@ -245,6 +251,10 @@ main(
     char *conf_tapetype;
     tapetype_t *tape;
     char *line;
+    char *tapedev;
+#ifndef DEBUG_CODE
+    int i;
+#endif
 
     safe_fd(DATA_FD_OFFSET, 4);
     safe_cd();
@@ -367,9 +377,7 @@ main(
 
        /* read the REQ packet */
        for(; (line = agets(stdin)) != NULL; free(line)) {
-#define sc "OPTIONS "
-           if(strncmp(line, sc, sizeof(sc)-1) == 0) {
-#undef sc
+           if(strncmp_const(line, "OPTIONS ") == 0) {
                g_options = parse_g_options(line+8, 1);
                if(!g_options->hostname) {
                    g_options->hostname = alloc(MAX_HOSTNAME_LENGTH+1);
@@ -416,20 +424,22 @@ main(
     match_list->diskname = "";
 
     for (re_end = 0; re_end == 0; ) {
+       char *s, ch;
        amfree(buf);
        buf = stralloc(get_client_line(cmdin));
-       if(strncmp(buf, "LABEL=", 6) == 0) {
-           tapes = unmarshal_tapelist_str(buf+6);
+       s = buf;
+       if(strncmp_const_skip(buf, "LABEL=", s, ch) == 0) {
+           tapes = unmarshal_tapelist_str(s);
        }
-       else if(strncmp(buf, "FSF=", 4) == 0) {
-           rst_flags->fsf = OFF_T_ATOI(buf + 4);
+       else if(strncmp_const_skip(buf, "FSF=", s, ch) == 0) {
+           rst_flags->fsf = OFF_T_ATOI(s);
        }
-       else if(strncmp(buf, "HEADER", 6) == 0) {
+       else if(strncmp_const_skip(buf, "HEADER", s, ch) == 0) {
            rst_flags->headers = 1;
        }
-       else if(strncmp(buf, "FEATURES=", 9) == 0) {
+       else if(strncmp_const_skip(buf, "FEATURES=", s, ch) == 0) {
            char *our_feature_string = NULL;
-           their_feature_string = stralloc(buf+9);
+           their_feature_string = stralloc(s);
            am_release_feature_set(their_features);
            their_features = am_string_to_feature(their_feature_string);
            amfree(their_feature_string);
@@ -441,23 +451,23 @@ main(
            fflush(cmdout);
            amfree(our_feature_string);
        }
-       else if(strncmp(buf, "DEVICE=", 7) == 0) {
-           rst_flags->alt_tapedev= stralloc(buf+7);
+       else if(strncmp_const_skip(buf, "DEVICE=", s, ch) == 0) {
+           rst_flags->alt_tapedev= stralloc(s);
        }
-       else if(strncmp(buf, "HOST=", 5) == 0) {
-           match_list->hostname = stralloc(buf+5);
+       else if(strncmp_const_skip(buf, "HOST=", s, ch) == 0) {
+           match_list->hostname = stralloc(s);
        }
-       else if(strncmp(buf, "DISK=", 5) == 0) {
-           match_list->diskname = stralloc(buf+5);
+       else if(strncmp_const_skip(buf, "DISK=", s, ch) == 0) {
+           match_list->diskname = stralloc(s);
        }
-       else if(strncmp(buf, "DATESTAMP=", 10) == 0) {
-           match_list->datestamp = stralloc(buf+10);
+       else if(strncmp_const_skip(buf, "DATESTAMP=", s, ch) == 0) {
+           match_list->datestamp = stralloc(s);
        }
-       else if(strncmp(buf, "END", 3) == 0) {
+       else if(strncmp_const(buf, "END") == 0) {
            re_end = 1;
        }
-       else if(strncmp(buf, "CONFIG=", 7) == 0) {
-           re_config = stralloc(buf+7);
+       else if(strncmp_const_skip(buf, "CONFIG=", s, ch) == 0) {
+           re_config = stralloc(s);
        }
        else if(buf[0] != '\0' && buf[0] >= '0' && buf[0] <= '9') {
 /* XXX does nothing?     amrestore_nargs = atoi(buf); */
@@ -505,11 +515,11 @@ main(
        use_changer = 1;
     }
 
+    tapedev = getconf_str(CNF_TAPEDEV);
     /* If we'll be stepping on the tape server's devices, lock them. */
     if(re_config &&
-       (use_changer || (rst_flags->alt_tapedev &&
-                        strcmp(rst_flags->alt_tapedev,
-                               getconf_str(CNF_TAPEDEV)) == 0) ) ) {
+       (use_changer || (rst_flags->alt_tapedev && tapedev &&
+                        strcmp(rst_flags->alt_tapedev, tapedev) == 0) ) ) {
        dbprintf(("%s: Locking devices\n", get_pname()));
        parent_pid = getpid();
        atexit(cleanup);
@@ -581,11 +591,11 @@ main(
              get_pname(), rst_flags->pipe_to_fd));
 
 
+    tapedev = getconf_str(CNF_TAPEDEV);
     if(get_lock == 0 &&
        re_config && 
-       (use_changer || (rst_flags->alt_tapedev &&
-                        strcmp(rst_flags->alt_tapedev,
-                               getconf_str(CNF_TAPEDEV)) == 0) ) ) {
+       (use_changer || (rst_flags->alt_tapedev && tapedev &&
+                        strcmp(rst_flags->alt_tapedev, tapedev) == 0) ) ) {
        send_message(cmdout, rst_flags, their_features,
                     "%s exists: amdump or amflush is already running, "
                     "or you must run amcleanup",