#include "pipespawn.h"
#include "amfeatures.h"
#include "client_util.h"
-#include "clientconf.h"
+#include "conffile.h"
#include "amandad.h"
#ifdef SAMBA_CLIENT
#include "findpass.h"
#endif
+#define selfcheck_debug(i,x) do { \
+ if ((i) <= debug_selfcheck) { \
+ dbprintf(x); \
+ } \
+} while (0)
+
int need_samba=0;
int need_rundump=0;
int need_dump=0;
int need_gnutar=0;
int need_compress_path=0;
int need_calcsize=0;
-int program_is_wrapper=0;
+int program_is_backup_api=0;
static char *amandad_auth = NULL;
static am_feature_t *our_features = NULL;
int main(int argc, char **argv);
static void check_options(char *program, char *calcprog, char *disk, char *amdevice, option_t *options);
-static void check_disk(char *program, char *calcprog, char *disk, char *amdevice, int level, char *optstr);
+static void check_disk(char *program, char *calcprog, char *disk, char *amdevice, int level, option_t *options);
static void check_overall(void);
static void check_access(char *filename, int mode);
+static int check_file_exist(char *filename);
static void check_file(char *filename, int mode);
static void check_dir(char *dirname, int mode);
static void check_suid(char *filename);
if (line[0] == '\0')
continue;
-#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);
skip_non_whitespace(s, ch);
s[-1] = '\0'; /* terminate the program name */
- program_is_wrapper = 0;
- if(strcmp(program,"DUMPER")==0) {
- program_is_wrapper = 1;
+ program_is_backup_api = 0;
+ if(strcmp(program,"BACKUP")==0) {
+ program_is_backup_api = 1;
skip_whitespace(s, ch); /* find dumper name */
if (ch == '\0') {
goto err; /* no program */
s[-1] = '\0'; /* terminate the program name */
}
- if(strncmp(program, "CALCSIZE", 8) == 0) {
+ if(strncmp_const(program, "CALCSIZE") == 0) {
skip_whitespace(s, ch); /* find program name */
if (ch == '\0') {
goto err; /* no program */
skip_integer(s, ch);
skip_whitespace(s, ch);
-#define sc "OPTIONS "
- if (ch && strncmp (s - 1, sc, SIZEOF(sc)-1) == 0) {
- s += SIZEOF(sc)-1;
- ch = s[-1];
-#undef sc
+ if (ch && strncmp_const_skip(s - 1, "OPTIONS ", s, ch) == 0) {
skip_whitespace(s, ch); /* find the option string */
if(ch == '\0') {
goto err; /* bad options string */
options = parse_options(optstr, disk, amdevice, g_options->features, 1);
/*@ignore@*/
check_options(program, calcprog, disk, amdevice, options);
- check_disk(program, calcprog, disk, amdevice, level, &optstr[2]);
+ check_disk(program, calcprog, disk, amdevice, level, options);
/*@end@*/
free_sl(options->exclude_file);
free_sl(options->exclude_list);
need_compress_path=1;
need_calcsize=1;
/*@ignore@*/
- check_disk(program, calcprog, disk, amdevice, level, "");
+ check_disk(program, calcprog, disk, amdevice, level, NULL);
/*@end@*/
} else {
goto err; /* bad syntax */
need_restore=1;
#endif
}
- if ((options->compress == COMPR_BEST) || (options->compress == COMPR_FAST)
- || (options->compress == COMPR_CUST)) {
+ if ((options->compress == COMP_BEST) || (options->compress == COMP_FAST)
+ || (options->compress == COMP_CUST)) {
need_compress_path=1;
}
if(options->auth && amandad_auth) {
char * disk,
char * amdevice,
int level,
- char * optstr)
+ option_t *options)
{
char *device = stralloc("nodevice");
char *err = NULL;
char *qdisk = quote_string(disk);
char *qamdevice = quote_string(amdevice);
char *qdevice = NULL;
+ FILE *toolin;
+ char number[NUM_STR_SIZE];
(void)level; /* Quiet unused parameter warning */
amode = F_OK;
amfree(device);
device = amname_to_dirname(amdevice);
- } else if (strcmp(program, "DUMP") == 0) {
+ } else if (strcmp(myprogram, "DUMP") == 0) {
if(amdevice[0] == '/' && amdevice[1] == '/') {
err = vstralloc("The DUMP program cannot handle samba shares,",
" use GNUTAR: ",
#endif
}
}
- else { /* program_is_wrapper==1 */
- pid_t pid_wrapper;
- fflush(stdout);fflush(stdin);
- switch (pid_wrapper = fork()) {
+ else { /* program_is_backup_api==1 */
+ pid_t backup_api_pid;
+ int property_pipe[2];
+ backup_support_option_t *bsu;
+
+ bsu = backup_support_option(program, g_options, disk, amdevice);
+
+ if (pipe(property_pipe) < 0) {
+ err = vstralloc("pipe failed: ", strerror(errno), NULL);
+ goto common_exit;
+ }
+ fflush(stdout);fflush(stderr);
+
+ switch (backup_api_pid = fork()) {
case -1:
- printf("ERROR [fork: %s]\n", strerror(errno));
- error("fork: %s", strerror(errno));
- /*NOTREACHED*/
+ err = vstralloc("fork failed: ", strerror(errno), NULL);
+ goto common_exit;
case 0: /* child */
{
- char *argvchild[6];
+ char *argvchild[14];
char *cmd = vstralloc(DUMPER_DIR, "/", program, NULL);
- argvchild[0] = program;
- argvchild[1] = "selfcheck";
- argvchild[2] = disk;
- argvchild[3] = amdevice;
- argvchild[4] = optstr;
- argvchild[5] = NULL;
+ int j=0;
+ argvchild[j++] = program;
+ argvchild[j++] = "selfcheck";
+ if (bsu->message_line == 1) {
+ argvchild[j++] = "--message";
+ argvchild[j++] = "line";
+ }
+ if (g_options->config != NULL && bsu->config == 1) {
+ argvchild[j++] = "--config";
+ argvchild[j++] = g_options->config;
+ }
+ if (g_options->hostname != NULL && bsu->host == 1) {
+ argvchild[j++] = "--host";
+ argvchild[j++] = g_options->hostname;
+ }
+ if (disk != NULL && bsu->disk == 1) {
+ argvchild[j++] = "--disk";
+ argvchild[j++] = disk;
+ }
+ argvchild[j++] = "--device";
+ argvchild[j++] = amdevice;
+ if(options && options->createindex && bsu->index_line == 1) {
+ argvchild[j++] = "--index";
+ argvchild[j++] = "line";
+ }
+ if (!options->no_record && bsu->record == 1) {
+ argvchild[j++] = "--record";
+ }
+ argvchild[j++] = NULL;
+ dup2(property_pipe[0], 0);
+ aclose(property_pipe[1]);
execve(cmd,argvchild,safe_env());
+ printf("ERROR [Can't execute %s: %s]\n", cmd, strerror(errno));
exit(127);
}
default: /* parent */
{
int status;
- waitpid(pid_wrapper, &status, 0);
+ aclose(property_pipe[0]);
+ toolin = fdopen(property_pipe[1],"w");
+ if (!toolin) {
+ err = vstralloc("Can't fdopen: ", strerror(errno), NULL);
+ goto common_exit;
+ }
+ output_tool_property(toolin, options);
+ fflush(toolin);
+ fclose(toolin);
+ if (waitpid(backup_api_pid, &status, 0) < 0) {
+ if (!WIFEXITED(status)) {
+ snprintf(number, SIZEOF(number), "%d",
+ (int)WTERMSIG(status));
+ err = vstralloc("Tool exited with signal ", number,
+ NULL);
+ } else if (WEXITSTATUS(status) != 0) {
+ snprintf(number, SIZEOF(number), "%d",
+ (int)WEXITSTATUS(status));
+ err = vstralloc("Tool exited with status ", number,
+ NULL);
+ } else {
+ err = stralloc("waitpid returned negative value");
+ }
+ goto common_exit;
+ }
}
}
- fflush(stdout);fflush(stdin);
+ amfree(bsu);
+ fflush(stdout);fflush(stderr);
amfree(device);
amfree(qamdevice);
amfree(qdisk);
dbprintf(("%s: device %s\n", debug_prefix_time(NULL), qdevice));
/* skip accessability test if this is an AFS entry */
- if(strncmp(device, "afs:", 4) != 0) {
+ if(strncmp_const(device, "afs:") != 0) {
#ifdef CHECK_FOR_ACCESS_WITH_OPEN
access_result = open(device, O_RDONLY);
access_type = "open";
printf("ERROR [GNUTAR program not available]\n");
#endif
need_amandates = 1;
- gnutar_list_dir = client_getconf_str(CLN_GNUTAR_LIST_DIR);
+ gnutar_list_dir = getconf_str(CNF_GNUTAR_LIST_DIR);
if (strlen(gnutar_list_dir) == 0)
gnutar_list_dir = NULL;
if (gnutar_list_dir)
if (need_amandates) {
char *amandates_file;
- amandates_file = client_getconf_str(CLN_AMANDATES);
+ amandates_file = getconf_str(CNF_AMANDATES);
check_file(amandates_file, R_OK|W_OK);
}
if( need_calcsize ) {
}
}
- if( need_compress_path )
+ if (need_compress_path )
check_file(COMPRESS_PATH, X_OK);
- if( need_dump || need_xfsdump )
- check_file("/var/lib/dumpdates",
+ if (need_dump || need_xfsdump ) {
+ if (check_file_exist("/var/lib/dumpdates")) {
+ check_file("/var/lib/dumpdates",
#ifdef USE_RUNDUMP
- F_OK
+ F_OK
#else
- R_OK|W_OK
+ R_OK|W_OK
#endif
- );
+ );
+ } else {
+#ifndef USE_RUNDUMP
+ if (access("/etc", R_OK|W_OK) == -1) {
+ printf("ERROR [dump will not be able to create the /etc/dumpdates file: %s]\n", strerror(errno));
+ }
+#endif
+ }
+ }
- if (need_vdump)
- check_file("/etc/vdumpdates", F_OK);
+ if (need_vdump) {
+ if (check_file_exist("/etc/vdumpdates")) {
+ check_file("/etc/vdumpdates", F_OK);
+ }
+ }
check_access("/dev/null", R_OK|W_OK);
check_space(AMANDA_TMPDIR, (off_t)64); /* for amandad i/o */
amfree(quoted);
}
+static int
+check_file_exist(
+ char *filename)
+{
+ struct stat stat_buf;
+
+ if (stat(filename, &stat_buf) != 0) {
+ if(errno == ENOENT) {
+ return 0;
+ }
+ }
+ return 1;
+}
+
static void
check_file(
char * filename,