* 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 */
};
-cmd_t getcmd(cmdargs)
-struct cmdargs *cmdargs;
+cmd_t
+getcmd(
+ struct cmdargs * cmdargs)
{
char *line;
cmd_t cmd_i;
if (isatty(0)) {
printf("%s> ", get_pname());
fflush(stdout);
+ line = readline(NULL);
+ } 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])), " ");
amfree(line);
#if DEBUG
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;
+ }
+ }
+ }
+ }
+ return 0;
+}