X-Git-Url: https://git.gag.com/?a=blobdiff_plain;f=server-src%2Fserver_util.c;fp=server-src%2Fserver_util.c;h=b238f1217a6f8bb64d389cf6c5be26cf0dd033f2;hb=310f09c0f55a2fb6f3f3746d6ded20099792b773;hp=9f8835e47bb33b81f4b052aa3d2a51bc1295f83a;hpb=13d6d10aa48f1dfb956ccff2f72dbaa255073472;p=debian%2Famanda diff --git a/server-src/server_util.c b/server-src/server_util.c index 9f8835e..b238f12 100644 --- a/server-src/server_util.c +++ b/server-src/server_util.c @@ -24,7 +24,7 @@ * file named AUTHORS, in the root directory of this distribution. */ /* - * $Id: server_util.c,v 1.17 2006/05/25 01:47:20 johnfranks Exp $ + * $Id: server_util.c,v 1.17.2.1 2006/11/24 18:05:07 martinea Exp $ * */ @@ -127,3 +127,60 @@ amhost_get_security_conf( 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; +}