Imported Upstream version 2.6.0
[debian/amanda] / server-src / server_util.c
index 3e3fceeaafaa8801254f79cac6b0c55dbd44b891..7c6c3231c83ee993e144a4f4ba992bf6fa2a16f4 100644 (file)
@@ -24,7 +24,7 @@
  * file named AUTHORS, in the root directory of this distribution.
  */
 /*
- * $Id: server_util.c,v 1.13 2005/10/20 23:18:15 martinea Exp $
+ * $Id: server_util.c,v 1.17 2006/05/25 01:47:20 johnfranks Exp $
  *
  */
 
 #include "server_util.h"
 #include "arglist.h"
 #include "token.h"
+#include "logfile.h"
+#include "util.h"
+#include "conffile.h"
+#include "diskfile.h"
 
 const char *cmdstr[] = {
     "BOGUS", "QUIT", "QUITTING", "DONE", "PARTIAL", 
-    "FILE-DUMP", "PORT-DUMP", "CONTINUE", "ABORT",     /* dumper cmds */
+    "START", "FILE-DUMP", "PORT-DUMP", "CONTINUE", "ABORT",/* dumper cmds */
     "FAILED", "TRY-AGAIN", "NO-ROOM", "RQ-MORE-DISK",  /* dumper results */
     "ABORT-FINISHED", "BAD-COMMAND",                   /* dumper results */
-    "START-TAPER", "FILE-WRITE", "PORT-WRITE",         /* taper cmds */
-    "PORT", "TAPE-ERROR", "TAPER-OK", "SPLIT-NEEDNEXT", /* taper results */
-    "SPLIT-CONTINUE",
+    "START-TAPER", "FILE-WRITE", "NEW-TAPE", "NO-NEW-TAPE",
+     
+    "PARTDONE", "PORT-WRITE", "DUMPER-STATUS",             /* taper cmds */
+    "PORT", "TAPE-ERROR", "TAPER-OK",                   /* taper results */
+    "REQUEST-NEW-TAPE",
+    "LAST_TOK",
     NULL
 };
 
 
-cmd_t getcmd(cmdargs)
-struct cmdargs *cmdargs;
+cmd_t
+getcmd(
+    struct cmdargs *   cmdargs)
 {
     char *line;
     cmd_t cmd_i;
@@ -54,24 +62,27 @@ struct cmdargs *cmdargs;
     assert(cmdargs != NULL);
 
     if (isatty(0)) {
-       printf("%s> ", get_pname());
+       g_printf("%s> ", get_pname());
        fflush(stdout);
+        line = agets(stdin);
+    } else {
+        line = agets(stdin);
     }
-
-    if ((line = agets(stdin)) == NULL) {
+    if (line == NULL) {
        line = stralloc("QUIT");
     }
 
     cmdargs->argc = split(line, cmdargs->argv,
-       sizeof(cmdargs->argv) / sizeof(cmdargs->argv[0]), " ");
+       (int)(sizeof(cmdargs->argv) / sizeof(cmdargs->argv[0])), " ");
+    dbprintf(_("getcmd: %s\n"), line);
     amfree(line);
 
 #if DEBUG
     {
        int i;
-       fprintf(stderr,"argc = %d\n", cmdargs->argc);
+       g_fprintf(stderr,_("argc = %d\n"), cmdargs->argc);
        for (i = 0; i < cmdargs->argc+1; i++)
-           fprintf(stderr,"argv[%d] = \"%s\"\n", i, cmdargs->argv[i]);
+           g_fprintf(stderr,_("argv[%d] = \"%s\"\n"), i, cmdargs->argv[i]);
     }
 #endif
 
@@ -90,8 +101,95 @@ printf_arglist_function1(void putresult, cmd_t, result, const char *, format)
     va_list argp;
 
     arglist_start(argp, format);
-    printf("%s ",cmdstr[result]);
-    vprintf(format, argp);
+    dbprintf(_("putresult: %d %s\n"), result, cmdstr[result]);
+    g_printf("%s ", cmdstr[result]);
+    g_vprintf(format, argp);
     fflush(stdout);
     arglist_end(argp);
 }
+
+char *
+amhost_get_security_conf(
+    char *     string,
+    void *     arg)
+{
+    if(!string || !*string)
+       return(NULL);
+
+    if(strcmp(string, "krb5principal")==0)
+       return(getconf_str(CNF_KRB5PRINCIPAL));
+    else if(strcmp(string, "krb5keytab")==0)
+       return(getconf_str(CNF_KRB5KEYTAB));
+
+    if(!arg || !((am_host_t *)arg)->disks) return(NULL);
+
+    if(strcmp(string, "amandad_path")==0)
+       return ((am_host_t *)arg)->disks->amandad_path;
+    else if(strcmp(string, "client_username")==0)
+       return ((am_host_t *)arg)->disks->client_username;
+    else if(strcmp(string, "ssh_keys")==0)
+       return ((am_host_t *)arg)->disks->ssh_keys;
+
+    return(NULL);
+}
+
+int check_infofile(
+    char        *infodir,
+    disklist_t  *dl,
+    char       **errmsg)
+{
+    disk_t      *dp, *diskp;
+    char        *hostinfodir, *old_hostinfodir, *Xhostinfodir;
+    char        *diskdir,     *old_diskdir,     *Xdiskdir;
+    char        *infofile,    *old_infofile,    *Xinfofile;
+    struct stat  statbuf;
+    int other_dle_match;
+
+    if (stat(infodir, &statbuf) != 0) {
+       return 0;
+    }
+
+    for (dp = dl->head; dp != NULL; dp = dp->next) {
+       hostinfodir = sanitise_filename(dp->host->hostname);
+       diskdir     = sanitise_filename(dp->name);
+       infofile = vstralloc(infodir, "/", hostinfodir, "/", diskdir,
+                            "/info", NULL);
+       if (stat(infofile, &statbuf) == -1 && errno == ENOENT) {
+           old_hostinfodir = old_sanitise_filename(dp->host->hostname);
+           old_diskdir     = old_sanitise_filename(dp->name);
+           old_infofile    = vstralloc(infodir, old_hostinfodir, "/",
+                                       old_diskdir, "/info", NULL);
+           if (stat(old_infofile, &statbuf) == 0) {
+               other_dle_match = 0;
+               diskp = dl->head;
+               while (diskp != NULL) {
+                   Xhostinfodir = sanitise_filename(diskp->host->hostname);
+                   Xdiskdir     = sanitise_filename(diskp->name);
+                   Xinfofile = vstralloc(infodir, "/", Xhostinfodir, "/",
+                                         Xdiskdir, "/info", NULL);
+                   if (strcmp(old_infofile, Xinfofile) == 0) {
+                       other_dle_match = 1;
+                       diskp = NULL;
+                   }
+                   else {
+                       diskp = diskp->next;
+                   }
+               }
+               if (other_dle_match == 0) {
+                   if(mkpdir(infofile, (mode_t)02755, (uid_t)-1,
+                             (gid_t)-1) == -1)  {
+                       *errmsg = vstralloc("Can't create directory for ",
+                                           infofile, NULL);
+                       return -1;
+                   }
+                   if(copy_file(infofile, old_infofile, errmsg) == -1) 
+                       return -1;
+               }
+           }
+       }
+       amfree(diskdir);
+       amfree(hostinfodir);
+       amfree(infofile);
+    }
+    return 0;
+}