Merge tag 'upstream/3.3.3'
[debian/amanda] / client-src / selfcheck.c
index 8787a8245f40c0a055d6e7f8197662d10e4e8ad5..dfffe2e3c8c214fe3b9b337d97c7ae88dd089f29 100644 (file)
@@ -1,6 +1,7 @@
 /*
  * Amanda, The Advanced Maryland Automatic Network Disk Archiver
  * Copyright (c) 1991-1998 University of Maryland at College Park
+ * Copyright (c) 2007-2012 Zmanda, Inc.  All Rights Reserved.
  * All Rights Reserved.
  *
  * Permission to use, copy, modify, distribute, and sell this software and its
  *                        University of Maryland at College Park
  */
 /* 
- * $Id: selfcheck.c,v 1.95 2006/08/29 11:21:00 martinea Exp $
+ * $Id: selfcheck.c 10421 2008-03-06 18:48:30Z martineau $
  *
  * do self-check and send back any error messages
  */
 
 #include "amanda.h"
 #include "fsusage.h"
-#include "version.h"
 #include "getfsent.h"
 #include "amandates.h"
 #include "clock.h"
@@ -42,6 +42,8 @@
 #include "client_util.h"
 #include "conffile.h"
 #include "amandad.h"
+#include "amxml.h"
+#include "base64.h"
 
 #ifdef SAMBA_CLIENT
 #include "findpass.h"
@@ -61,7 +63,8 @@ int need_runtar=0;
 int need_gnutar=0;
 int need_compress_path=0;
 int need_calcsize=0;
-int program_is_backup_api=0;
+int need_global_check=0;
+int program_is_application_api=0;
 
 static char *amandad_auth = NULL;
 static am_feature_t *our_features = NULL;
@@ -71,34 +74,34 @@ static g_option_t *g_options = NULL;
 /* local functions */
 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, option_t *options);
+static void check_options(dle_t *dle);
+static void check_disk(dle_t *dle);
 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);
 static void check_space(char *dir, off_t kbytes);
+static void print_platform(void);
 
 int
 main(
     int                argc,
     char **    argv)
 {
-    int level;
     char *line = NULL;
-    char *program = NULL;
-    char *calcprog = NULL;
-    char *disk = NULL;
     char *qdisk = NULL;
-    char *amdevice = NULL;
     char *qamdevice = NULL;
     char *optstr = NULL;
     char *err_extra = NULL;
     char *s, *fp;
-    option_t *options;
     int ch;
+    dle_t *dle;
+    int level;
+    GSList *errlist;
+    am_level_t *alevel;
+
+    if (argc > 1 && argv && argv[1] && g_str_equal(argv[1], "--version")) {
+       printf("selfcheck-%s\n", VERSION);
+       return (0);
+    }
 
     /* initialize */
 
@@ -112,6 +115,7 @@ main(
     textdomain("amanda"); 
 
     safe_fd(-1, 0);
+    openbsd_fd_inform();
     safe_cd();
 
     set_pname("selfcheck");
@@ -119,16 +123,20 @@ main(
     /* Don't die when child closes pipe */
     signal(SIGPIPE, SIG_IGN);
 
-    erroutput_type = (ERR_INTERACTIVE|ERR_SYSLOG);
+    add_amanda_log_handler(amanda_log_stderr);
+    add_amanda_log_handler(amanda_log_syslog);
     dbopen(DBG_SUBDIR_CLIENT);
     startclock();
-    dbprintf(_("version %s\n"), version());
+    dbprintf(_("version %s\n"), VERSION);
+    g_printf("OK version %s\n", VERSION);
+    print_platform();
 
     if(argc > 2 && strcmp(argv[1], "amandad") == 0) {
        amandad_auth = stralloc(argv[2]);
     }
 
     config_init(CONFIG_INIT_CLIENT, NULL);
+    /* (check for config errors comes later) */
 
     check_running_as(RUNNING_AS_CLIENT_LOGIN);
 
@@ -166,12 +174,24 @@ main(
                config_init(CONFIG_INIT_CLIENT | CONFIG_INIT_EXPLICIT_NAME | CONFIG_INIT_OVERLAY,
                            g_options->config);
 
-               dbrename(config_name, DBG_SUBDIR_CLIENT);
+               dbrename(get_config_name(), DBG_SUBDIR_CLIENT);
            }
 
+           /* check for any config errors now */
+           if (config_errors(&errlist) >= CFGERR_ERRORS) {
+               char *errstr = config_errors_to_error_string(errlist);
+               g_printf("%s\n", errstr);
+               dbclose();
+               return 1;
+           }
+
+           if (am_has_feature(g_options->features, fe_req_xml)) {
+               break;
+           }
            continue;
        }
 
+       dle = alloc_dle();
        s = line;
        ch = *s++;
 
@@ -179,33 +199,36 @@ main(
        if (ch == '\0') {
            goto err;                           /* no program */
        }
-       program = s - 1;
+       dle->program = s - 1;
        skip_non_whitespace(s, ch);
        s[-1] = '\0';                           /* terminate the program name */
 
-       program_is_backup_api = 0;
-       if(strcmp(program,"BACKUP")==0) {
-           program_is_backup_api = 1;
+       dle->program_is_application_api = 0;
+       if(strcmp(dle->program,"APPLICATION")==0) {
+           dle->program_is_application_api = 1;
            skip_whitespace(s, ch);             /* find dumper name */
            if (ch == '\0') {
                goto err;                       /* no program */
            }
-           program = s - 1;
+           dle->program = s - 1;
            skip_non_whitespace(s, ch);
            s[-1] = '\0';                       /* terminate the program name */
        }
 
-       if(strncmp_const(program, "CALCSIZE") == 0) {
+       if(strncmp_const(dle->program, "CALCSIZE") == 0) {
            skip_whitespace(s, ch);             /* find program name */
            if (ch == '\0') {
                goto err;                       /* no program */
            }
-           calcprog = s - 1;
+           dle->program = s - 1;
            skip_non_whitespace(s, ch);
            s[-1] = '\0';
+           dle->estimatelist = g_slist_append(dle->estimatelist,
+                                              GINT_TO_POINTER(ES_CALCSIZE));
        }
        else {
-           calcprog = NULL;
+           dle->estimatelist = g_slist_append(dle->estimatelist,
+                                              GINT_TO_POINTER(ES_CLIENT));
        }
 
        skip_whitespace(s, ch);                 /* find disk name */
@@ -215,7 +238,7 @@ main(
        qdisk = s - 1;
        skip_quoted_string(s, ch);
        s[-1] = '\0';                           /* terminate the disk name */
-       disk = unquote_string(qdisk);
+       dle->disk = unquote_string(qdisk);
 
        skip_whitespace(s, ch);                 /* find the device or level */
        if (ch == '\0') {
@@ -226,17 +249,21 @@ main(
            skip_quoted_string(s, ch);
             s[-1] = '\0';                      /* terminate the device */
            qamdevice = stralloc(fp);
-           amdevice = unquote_string(qamdevice);
+           dle->device = unquote_string(qamdevice);
            skip_whitespace(s, ch);             /* find level number */
        }
        else {
-           amdevice = stralloc(disk);
+           dle->device = stralloc(dle->disk);
+           qamdevice = stralloc(qdisk);
        }
 
                                                /* find level number */
        if (ch == '\0' || sscanf(s - 1, "%d", &level) != 1) {
            goto err;                           /* bad level */
        }
+       alevel = g_new0(am_level_t, 1);
+       alevel->level = level;
+       dle->levellist = g_slist_append(dle->levellist, alevel);
        skip_integer(s, ch);
 
        skip_whitespace(s, ch);
@@ -248,18 +275,13 @@ main(
            optstr = s - 1;
            skip_quoted_string(s, ch);
            s[-1] = '\0';                       /* terminate the options */
-           options = parse_options(optstr, disk, amdevice, g_options->features, 1);
+           parse_options(optstr, dle, g_options->features, 1);
            /*@ignore@*/
-           check_options(program, calcprog, disk, amdevice, options);
-           check_disk(program, calcprog, disk, amdevice, level, options);
+
+           check_options(dle);
+           check_disk(dle);
+
            /*@end@*/
-           free_sl(options->exclude_file);
-           free_sl(options->exclude_list);
-           free_sl(options->include_file);
-           free_sl(options->include_list);
-           amfree(options->auth);
-           amfree(options->str);
-           amfree(options);
        } else if (ch == '\0') {
            /* check all since no option */
            need_samba=1;
@@ -276,22 +298,56 @@ main(
            need_gnutar=1;
            need_compress_path=1;
            need_calcsize=1;
+           need_global_check=1;
            /*@ignore@*/
-           check_disk(program, calcprog, disk, amdevice, level, NULL);
+           check_disk(dle);
            /*@end@*/
        } else {
            goto err;                           /* bad syntax */
        }
-       amfree(disk);
        amfree(qamdevice);
-       amfree(amdevice);
     }
     if (g_options == NULL) {
-       printf(_("ERROR [Missing OPTIONS line in selfcheck input]\n"));
+       g_printf(_("ERROR [Missing OPTIONS line in selfcheck input]\n"));
        error(_("Missing OPTIONS line in selfcheck input\n"));
        /*NOTREACHED*/
     }
 
+    if (am_has_feature(g_options->features, fe_req_xml)) {
+       char  *errmsg = NULL;
+       dle_t *dles, *dle, *dle_next;
+
+       dles = amxml_parse_node_FILE(stdin, &errmsg);
+       if (errmsg) {
+           err_extra = errmsg;
+           goto err;
+       }
+       if (merge_dles_properties(dles, 1) == 0) {
+           goto checkoverall;
+       }
+       for (dle = dles; dle != NULL; dle = dle->next) {
+           run_client_scripts(EXECUTE_ON_PRE_HOST_AMCHECK, g_options, dle,
+                              stdout);
+       }
+       for (dle = dles; dle != NULL; dle = dle->next) {
+           check_options(dle);
+           run_client_scripts(EXECUTE_ON_PRE_DLE_AMCHECK, g_options, dle,
+                              stdout);
+           check_disk(dle);
+           run_client_scripts(EXECUTE_ON_POST_DLE_AMCHECK, g_options, dle,
+                              stdout);
+       }
+       for (dle = dles; dle != NULL; dle = dle->next) {
+           run_client_scripts(EXECUTE_ON_POST_HOST_AMCHECK, g_options, dle,
+                              stdout);
+       }
+       for (dle = dles; dle != NULL; dle = dle_next) {
+           dle_next = dle->next;
+           free_dle(dle);
+       }
+    }
+
+checkoverall:
     check_overall();
 
     amfree(line);
@@ -304,10 +360,13 @@ main(
     return 0;
 
  err:
-    g_printf(_("ERROR [BOGUS REQUEST PACKET]\n"));
-    dbprintf(_("REQ packet is bogus%s%s\n"),
-             err_extra ? ": " : "",
-             err_extra ? err_extra : "");
+    if (err_extra) {
+       g_printf(_("ERROR [FORMAT ERROR IN REQUEST PACKET %s]\n"), err_extra);
+       dbprintf(_("REQ packet is bogus: %s\n"), err_extra);
+    } else {
+       g_printf(_("ERROR [FORMAT ERROR IN REQUEST PACKET]\n"));
+       dbprintf(_("REQ packet is bogus\n"));
+    }
     dbclose();
     return 1;
 }
@@ -315,71 +374,43 @@ main(
 
 static void
 check_options(
-    char *     program,
-    char *     calcprog,
-    char *     disk,
-    char *     amdevice,
-    option_t * options)
+    dle_t *dle)
 {
-    char *myprogram = program;
-
-    if(strcmp(myprogram,"CALCSIZE") == 0) {
-       int nb_exclude = 0;
-       int nb_include = 0;
-       char *file_exclude = NULL;
-       char *file_include = NULL;
-
-       if(options->exclude_file) nb_exclude += options->exclude_file->nb_element;
-       if(options->exclude_list) nb_exclude += options->exclude_list->nb_element;
-       if(options->include_file) nb_include += options->include_file->nb_element;
-       if(options->include_list) nb_include += options->include_list->nb_element;
-
-       if(nb_exclude > 0) file_exclude = build_exclude(disk, amdevice, options, 1);
-       if(nb_include > 0) file_include = build_include(disk, amdevice, options, 1);
-
-       amfree(file_exclude);
-       amfree(file_include);
-
+    if (GPOINTER_TO_INT(dle->estimatelist->data) == ES_CALCSIZE) {
        need_calcsize=1;
-       if (calcprog == NULL) {
-           g_printf(_("ERROR [no program name for calcsize]\n"));
-       } else {
-           myprogram = calcprog;
-       }
     }
 
-    if(strcmp(myprogram,"GNUTAR") == 0) {
+    if (strcmp(dle->program,"GNUTAR") == 0) {
        need_gnutar=1;
-        if(amdevice[0] == '/' && amdevice[1] == '/') {
-           if(options->exclude_file && options->exclude_file->nb_element > 1) {
+        if(dle->device && dle->device[0] == '/' && dle->device[1] == '/') {
+           if(dle->exclude_file && dle->exclude_file->nb_element > 1) {
                g_printf(_("ERROR [samba support only one exclude file]\n"));
            }
-           if(options->exclude_list && options->exclude_list->nb_element > 0 &&
-              options->exclude_optional==0) {
+           if (dle->exclude_list && dle->exclude_list->nb_element > 0 &&
+               dle->exclude_optional==0) {
                g_printf(_("ERROR [samba does not support exclude list]\n"));
            }
-           if(options->include_file && options->include_file->nb_element > 0) {
+           if (dle->include_file && dle->include_file->nb_element > 0) {
                g_printf(_("ERROR [samba does not support include file]\n"));
            }
-           if(options->include_list && options->include_list->nb_element > 0 &&
-              options->include_optional==0) {
+           if (dle->include_list && dle->include_list->nb_element > 0 &&
+               dle->include_optional==0) {
                g_printf(_("ERROR [samba does not support include list]\n"));
            }
            need_samba=1;
-       }
-       else {
+       } else {
            int nb_exclude = 0;
            int nb_include = 0;
            char *file_exclude = NULL;
            char *file_include = NULL;
 
-           if(options->exclude_file) nb_exclude += options->exclude_file->nb_element;
-           if(options->exclude_list) nb_exclude += options->exclude_list->nb_element;
-           if(options->include_file) nb_include += options->include_file->nb_element;
-           if(options->include_list) nb_include += options->include_list->nb_element;
+           if (dle->exclude_file) nb_exclude += dle->exclude_file->nb_element;
+           if (dle->exclude_list) nb_exclude += dle->exclude_list->nb_element;
+           if (dle->include_file) nb_include += dle->include_file->nb_element;
+           if (dle->include_list) nb_include += dle->include_list->nb_element;
 
-           if(nb_exclude > 0) file_exclude = build_exclude(disk, amdevice, options, 1);
-           if(nb_include > 0) file_include = build_include(disk, amdevice, options, 1);
+           if (nb_exclude > 0) file_exclude = build_exclude(dle, 1);
+           if (nb_include > 0) file_include = build_include(dle, 1);
 
            amfree(file_exclude);
            amfree(file_include);
@@ -388,17 +419,17 @@ check_options(
        }
     }
 
-    if(strcmp(myprogram,"DUMP") == 0) {
-       if(options->exclude_file && options->exclude_file->nb_element > 0) {
+    if (strcmp(dle->program,"DUMP") == 0) {
+       if (dle->exclude_file && dle->exclude_file->nb_element > 0) {
            g_printf(_("ERROR [DUMP does not support exclude file]\n"));
        }
-       if(options->exclude_list && options->exclude_list->nb_element > 0) {
+       if (dle->exclude_list && dle->exclude_list->nb_element > 0) {
            g_printf(_("ERROR [DUMP does not support exclude list]\n"));
        }
-       if(options->include_file && options->include_file->nb_element > 0) {
+       if (dle->include_file && dle->include_file->nb_element > 0) {
            g_printf(_("ERROR [DUMP does not support include file]\n"));
        }
-       if(options->include_list && options->include_list->nb_element > 0) {
+       if (dle->include_list && dle->include_list->nb_element > 0) {
            g_printf(_("ERROR [DUMP does not support include list]\n"));
        }
 #ifdef USE_RUNDUMP
@@ -407,66 +438,66 @@ check_options(
 #ifndef AIX_BACKUP
 #ifdef VDUMP
 #ifdef DUMP
-       if (strcmp(amname_to_fstype(amdevice), "advfs") == 0)
+       if (dle->device && strcmp(amname_to_fstype(dle->device), "advfs") == 0)
 #else
        if (1)
 #endif
        {
            need_vdump=1;
            need_rundump=1;
-           if (options->createindex)
+           if (dle->create_index)
                need_vrestore=1;
        }
        else
 #endif /* VDUMP */
 #ifdef XFSDUMP
 #ifdef DUMP
-       if (strcmp(amname_to_fstype(amdevice), "xfs") == 0)
+       if (dle->device && strcmp(amname_to_fstype(dle->device), "xfs") == 0)
 #else
        if (1)
 #endif
        {
            need_xfsdump=1;
            need_rundump=1;
-           if (options->createindex)
+           if (dle->create_index)
                need_xfsrestore=1;
        }
        else
 #endif /* XFSDUMP */
 #ifdef VXDUMP
 #ifdef DUMP
-       if (strcmp(amname_to_fstype(amdevice), "vxfs") == 0)
+       if (dle->device && strcmp(amname_to_fstype(dle->device), "vxfs") == 0)
 #else
        if (1)
 #endif
        {
            need_vxdump=1;
-           if (options->createindex)
+           if (dle->create_index)
                need_vxrestore=1;
        }
        else
 #endif /* VXDUMP */
        {
            need_dump=1;
-           if (options->createindex)
+           if (dle->create_index)
                need_restore=1;
        }
 #else
        /* AIX backup program */
        need_dump=1;
-       if (options->createindex)
+       if (dle->create_index)
            need_restore=1;
 #endif
     }
-    if ((options->compress == COMP_BEST) || (options->compress == COMP_FAST) 
-               || (options->compress == COMP_CUST)) {
+    if ((dle->compress == COMP_BEST) || (dle->compress == COMP_FAST) 
+               || (dle->compress == COMP_CUST)) {
        need_compress_path=1;
     }
-    if(options->auth && amandad_auth) {
-       if(strcasecmp(options->auth, amandad_auth) != 0) {
+    if (dle->auth && amandad_auth) {
+       if (strcasecmp(dle->auth, amandad_auth) != 0) {
            g_fprintf(stdout,_("ERROR [client configured for auth=%s while server requested '%s']\n"),
-                   amandad_auth, options->auth);
-           if(strcmp(options->auth, "ssh") == 0)  {    
+                   amandad_auth, dle->auth);
+           if (strcmp(dle->auth, "ssh") == 0)  {       
                g_fprintf(stderr, _("ERROR [The auth in ~/.ssh/authorized_keys "
                                  "should be \"--auth=ssh\", or use another auth "
                                  " for the DLE]\n"));
@@ -481,291 +512,399 @@ check_options(
 
 static void
 check_disk(
-    char *     program,
-    char *     calcprog,
-    char *     disk,
-    char *     amdevice,
-    int                level,
-    option_t    *options)
+    dle_t *dle)
 {
-    char *device = stralloc("nodevice");
+    char *device = NULL;
     char *err = NULL;
     char *user_and_password = NULL;
     char *domain = NULL;
     char *share = NULL, *subdir = NULL;
     size_t lpass = 0;
-    int amode;
+    int amode = R_OK;
     int access_result;
     char *access_type;
     char *extra_info = NULL;
-    char *myprogram = program;
-    char *qdisk = quote_string(disk);
-    char *qamdevice = quote_string(amdevice);
+    char *qdisk = NULL;
+    char *qamdevice = NULL;
     char *qdevice = NULL;
-    FILE *toolin;
-
-    (void)level;       /* Quiet unused parameter warning */
-
-    dbprintf(_("checking disk %s\n"), qdisk);
-
-    if(strcmp(myprogram,"CALCSIZE") == 0) {
-       if(amdevice[0] == '/' && amdevice[1] == '/') {
-           err = vstrallocf(_("Can't use CALCSIZE for samba estimate, use CLIENT: %s"),
-                           amdevice);
-           goto common_exit;
-       }
-       if (calcprog == NULL) {
-           err = _("no program for calcsize");
-           goto common_exit;
-       }
-       myprogram = calcprog;
-    }
 
-    if (strcmp(myprogram, "GNUTAR")==0) {
-        if(amdevice[0] == '/' && amdevice[1] == '/') {
-#ifdef SAMBA_CLIENT
-           int nullfd, checkerr;
-           int passwdfd;
-           char *pwtext;
-           size_t pwtext_len;
-           pid_t checkpid;
-           amwait_t retstat;
-           pid_t wpid;
-           int rc;
-           char *line;
-           char *sep;
-           FILE *ferr;
-           char *pw_fd_env;
-           int errdos;
-
-           parsesharename(amdevice, &share, &subdir);
-           if (!share) {
-               err = vstrallocf(_("cannot parse for share/subdir disk entry %s"), amdevice);
-               goto common_exit;
-           }
-           if ((subdir) && (SAMBA_VERSION < 2)) {
-               err = vstrallocf(_("subdirectory specified for share '%s' but, samba is not v2 or better"),
-                               amdevice);
-               goto common_exit;
-           }
-           if ((user_and_password = findpass(share, &domain)) == NULL) {
-               err = vstrallocf(_("cannot find password for %s"), amdevice);
-               goto common_exit;
-           }
-           lpass = strlen(user_and_password);
-           if ((pwtext = strchr(user_and_password, '%')) == NULL) {
-               err = vstrallocf(_("password field not \'user%%pass\' for %s"), amdevice);
-               goto common_exit;
-           }
-           *pwtext++ = '\0';
-           pwtext_len = (size_t)strlen(pwtext);
-           amfree(device);
-           if ((device = makesharename(share, 0)) == NULL) {
-               err = vstrallocf(_("cannot make share name of %s"), share);
+    if (dle->disk) {
+       need_global_check=1;
+       qdisk = quote_string(dle->disk);
+       qamdevice = quote_string(dle->device);
+       device = stralloc("nodevice");
+       dbprintf(_("checking disk %s\n"), qdisk);
+       if (GPOINTER_TO_INT(dle->estimatelist->data) == ES_CALCSIZE) {
+           if (dle->device[0] == '/' && dle->device[1] == '/') {
+               err = vstrallocf(
+                   _("Can't use CALCSIZE for samba estimate, use CLIENT: %s"),
+                   dle->device);
                goto common_exit;
            }
+       }
 
-           if ((nullfd = open("/dev/null", O_RDWR)) == -1) {
-               err = vstrallocf(_("Cannot access /dev/null : %s"), strerror(errno));
-               goto common_exit;
-           }
+       if (strcmp(dle->program, "GNUTAR")==0) {
+            if(dle->device[0] == '/' && dle->device[1] == '/') {
+               #ifdef SAMBA_CLIENT
+               int nullfd, checkerr;
+               int passwdfd;
+               char *pwtext;
+               size_t pwtext_len;
+               pid_t checkpid;
+               amwait_t retstat;
+               pid_t wpid;
+               int rc;
+               char *line;
+               char *sep;
+               FILE *ferr;
+               char *pw_fd_env;
+               int errdos;
+
+               parsesharename(dle->device, &share, &subdir);
+               if (!share) {
+                   err = vstrallocf(
+                             _("cannot parse for share/subdir disk entry %s"),
+                             dle->device);
+                   goto common_exit;
+               }
+               if ((subdir) && (SAMBA_VERSION < 2)) {
+                   err = vstrallocf(_("subdirectory specified for share '%s' but, samba is not v2 or better"),
+                                    dle->device);
+                   goto common_exit;
+               }
+               if ((user_and_password = findpass(share, &domain)) == NULL) {
+                   err = vstrallocf(_("cannot find password for %s"),
+                                    dle->device);
+                   goto common_exit;
+               }
+               lpass = strlen(user_and_password);
+               if ((pwtext = strchr(user_and_password, '%')) == NULL) {
+                   err = vstrallocf(
+                               _("password field not \'user%%pass\' for %s"),
+                               dle->device);
+                   goto common_exit;
+               }
+               *pwtext++ = '\0';
+               pwtext_len = (size_t)strlen(pwtext);
+               amfree(device);
+               if ((device = makesharename(share, 0)) == NULL) {
+                   err = vstrallocf(_("cannot make share name of %s"), share);
+                   goto common_exit;
+               }
 
-           if (pwtext_len > 0) {
-               pw_fd_env = "PASSWD_FD";
-           } else {
-               pw_fd_env = "dummy_PASSWD_FD";
-           }
-           checkpid = pipespawn(SAMBA_CLIENT, STDERR_PIPE|PASSWD_PIPE,
-                                &nullfd, &nullfd, &checkerr,
-                                pw_fd_env, &passwdfd,
-                                "smbclient",
-                                device,
-                                *user_and_password ? "-U" : skip_argument,
-                                *user_and_password ? user_and_password : skip_argument,
-                                "-E",
-                                domain ? "-W" : skip_argument,
-                                domain ? domain : skip_argument,
+               if ((nullfd = open("/dev/null", O_RDWR)) == -1) {
+                   err = vstrallocf(_("Cannot access /dev/null : %s"),
+                                    strerror(errno));
+                   goto common_exit;
+               }
+
+               if (pwtext_len > 0) {
+                   pw_fd_env = "PASSWD_FD";
+               } else {
+                   pw_fd_env = "dummy_PASSWD_FD";
+               }
+               checkpid = pipespawn(SAMBA_CLIENT, STDERR_PIPE|PASSWD_PIPE, 0,
+                                    &nullfd, &nullfd, &checkerr,
+                                    pw_fd_env, &passwdfd,
+                                    "smbclient",
+                                    device,
+                                    *user_and_password ? "-U" : skip_argument,
+                                    *user_and_password ? user_and_password
+                                                       : skip_argument,
+                                    "-E",
+                                    domain ? "-W" : skip_argument,
+                                    domain ? domain : skip_argument,
 #if SAMBA_VERSION >= 2
-                                subdir ? "-D" : skip_argument,
-                                subdir ? subdir : skip_argument,
+                                    subdir ? "-D" : skip_argument,
+                                    subdir ? subdir : skip_argument,
 #endif
-                                "-c", "quit",
-                                NULL);
-           amfree(domain);
-           aclose(nullfd);
-           /*@ignore@*/
-           if ((pwtext_len > 0)
-             && fullwrite(passwdfd, pwtext, (size_t)pwtext_len) < 0) {
-               err = vstrallocf(_("password write failed: %s: %s"),
-                               amdevice, strerror(errno));
+                                    "-c", "quit",
+                                    NULL);
+               checkpid = checkpid;
+               amfree(domain);
+               aclose(nullfd);
+               /*@ignore@*/
+               if ((pwtext_len > 0) &&
+                   full_write(passwdfd, pwtext, pwtext_len) < pwtext_len) {
+                   err = vstrallocf(_("password write failed: %s: %s"),
+                                    dle->device, strerror(errno));
+                   aclose(passwdfd);
+                   goto common_exit;
+               }
+               /*@end@*/
+               memset(user_and_password, '\0', (size_t)lpass);
+               amfree(user_and_password);
                aclose(passwdfd);
-               goto common_exit;
-           }
-           /*@end@*/
-           memset(user_and_password, '\0', (size_t)lpass);
-           amfree(user_and_password);
-           aclose(passwdfd);
-           ferr = fdopen(checkerr, "r");
-           if (!ferr) {
-               g_printf(_("ERROR [Can't fdopen: %s]\n"), strerror(errno));
-               error(_("Can't fdopen: %s"), strerror(errno));
-               /*NOTREACHED*/
-           }
-           sep = "";
-           errdos = 0;
-           for(sep = ""; (line = agets(ferr)) != NULL; free(line)) {
-               if (line[0] == '\0')
-                   continue;
-               strappend(extra_info, sep);
-               strappend(extra_info, line);
-               sep = ": ";
-               if(strstr(line, "ERRDOS") != NULL) {
-                   errdos = 1;
+               ferr = fdopen(checkerr, "r");
+               if (!ferr) {
+                   g_printf(_("ERROR [Can't fdopen: %s]\n"), strerror(errno));
+                   error(_("Can't fdopen: %s"), strerror(errno));
+                   /*NOTREACHED*/
                }
-           }
-           afclose(ferr);
-           checkerr = -1;
-           rc = 0;
-           sep = "";
-           while ((wpid = wait(&retstat)) != -1) {
-               if (!WIFEXITED(retstat) || WEXITSTATUS(retstat) != 0) {
-                   char *exitstr = str_exit_status("smbclient", retstat);
-                   err = newvstralloc(err, err, sep, exitstr);
-                   sep = "\n";
-                   amfree(exitstr);
-
-                   rc = 1;
+               sep = "";
+               errdos = 0;
+               for(sep = ""; (line = agets(ferr)) != NULL; free(line)) {
+                   if (line[0] == '\0')
+                       continue;
+                   strappend(extra_info, sep);
+                   strappend(extra_info, line);
+                   sep = ": ";
+                   if(strstr(line, "ERRDOS") != NULL) {
+                       errdos = 1;
+                   }
                }
-           }
-           if (errdos != 0 || rc != 0) {
-               if (extra_info) {
-                   err = newvstrallocf(err,
-                                  _("samba access error: %s: %s %s"),
-                                  amdevice, extra_info, err);
-                   amfree(extra_info);
-               } else {
-                   err = newvstrallocf(err, _("samba access error: %s: %s"),
-                                  amdevice, err);
+               afclose(ferr);
+               checkerr = -1;
+               rc = 0;
+               sep = "";
+               while ((wpid = wait(&retstat)) != -1) {
+                   if (!WIFEXITED(retstat) || WEXITSTATUS(retstat) != 0) {
+                       char *exitstr = str_exit_status("smbclient", retstat);
+                       strappend(err, sep);
+                       strappend(err, exitstr);
+                       sep = "\n";
+                       amfree(exitstr);
+
+                       rc = 1;
+                   }
+               }
+               if (errdos != 0 || rc != 0) {
+                   if (extra_info) {
+                       err = newvstrallocf(err,
+                                           _("samba access error: %s: %s %s"),
+                                           dle->device, extra_info, err);
+                       amfree(extra_info);
+                   } else {
+                       err = newvstrallocf(err,
+                                           _("samba access error: %s: %s"),
+                                          dle->device, err);
+                   }
                }
-           }
 #else
-           err = vstrallocf(_("This client is not configured for samba: %s"),
-                       qdisk);
+               err = vstrallocf(
+                             _("This client is not configured for samba: %s"),
+                             qdisk);
 #endif
-           goto common_exit;
-       }
-       amode = F_OK;
-       amfree(device);
-       device = amname_to_dirname(amdevice);
-    } else if (strcmp(myprogram, "DUMP") == 0) {
-       if(amdevice[0] == '/' && amdevice[1] == '/') {
-           err = vstrallocf(
+               goto common_exit;
+           }
+           amode = F_OK;
+           amfree(device);
+           device = amname_to_dirname(dle->device);
+       } else if (strcmp(dle->program, "DUMP") == 0) {
+           if(dle->device[0] == '/' && dle->device[1] == '/') {
+               err = vstrallocf(
                  _("The DUMP program cannot handle samba shares, use GNUTAR: %s"),
                  qdisk);
-           goto common_exit;
-       }
+               goto common_exit;
+           }
 #ifdef VDUMP                                                           /* { */
 #ifdef DUMP                                                            /* { */
-        if (strcmp(amname_to_fstype(amdevice), "advfs") == 0)
-#else                                                                  /* }{ */
-       if (1)
+            if (strcmp(amname_to_fstype(dle->device), "advfs") == 0)
+#else                                                                  /* }{*/
+           if (1)
 #endif                                                                 /* } */
-       {
-           amfree(device);
-           device = amname_to_dirname(amdevice);
-           amode = F_OK;
-       } else
+           {
+               amfree(device);
+               device = amname_to_dirname(dle->device);
+               amode = F_OK;
+           } else
 #endif                                                                 /* } */
-       {
-           amfree(device);
-           device = amname_to_devname(amdevice);
+           {
+               amfree(device);
+               device = amname_to_devname(dle->device);
 #ifdef USE_RUNDUMP
-           amode = F_OK;
+               amode = F_OK;
 #else
-           amode = R_OK;
+               amode = R_OK;
 #endif
+           }
        }
     }
-    else { /* program_is_backup_api==1 */
-       pid_t  backup_api_pid;
-       int    property_pipe[2];
+    if (dle->program_is_application_api) {
+       pid_t                    application_api_pid;
        backup_support_option_t *bsu;
+       int                      app_err[2];
+       GPtrArray               *errarray;
+
+       bsu = backup_support_option(dle->program, g_options, dle->disk,
+                                   dle->device, &errarray);
+
+       if (!bsu) {
+           char  *line;
+           guint  i;
+           for (i=0; i < errarray->len; i++) {
+               line = g_ptr_array_index(errarray, i);
+               fprintf(stdout, _("ERROR Application '%s': %s\n"),
+                       dle->program, line);
+               amfree(line);
+           }
+           err = vstrallocf(_("Application '%s': can't run support command"),
+                            dle->program);
+           goto common_exit;
+       }
 
-       bsu = backup_support_option(program, g_options, disk, amdevice);
+       if (dle->data_path == DATA_PATH_AMANDA &&
+           (bsu->data_path_set & DATA_PATH_AMANDA)==0) {
+           g_printf("ERROR application %s doesn't support amanda data-path\n",
+                    dle->program);
+       }
+       if (dle->data_path == DATA_PATH_DIRECTTCP &&
+           (bsu->data_path_set & DATA_PATH_DIRECTTCP)==0) {
+           g_printf("ERROR application %s doesn't support directtcp data-path\n",
+                    dle->program);
+       }
+       if (GPOINTER_TO_INT(dle->estimatelist->data) == ES_CALCSIZE &&
+                           !bsu->calcsize) {
+           g_printf("ERROR application %s doesn't support calcsize estimate\n",
+                    dle->program);
+       }
+       if (dle->include_file && dle->include_file->nb_element > 0 &&
+           !bsu->include_file) {
+           g_printf("ERROR application %s doesn't support include-file\n",
+                  dle->program);
+       }
+       if (dle->include_list && dle->include_list->nb_element > 0 &&
+           !bsu->include_list) {
+           g_printf("ERROR application %s doesn't support include-list\n",
+                  dle->program);
+       }
+       if (dle->include_optional && !bsu->include_optional) {
+           g_printf("ERROR application %s doesn't support optional include\n",
+                  dle->program);
+       }
+       if (dle->exclude_file && dle->exclude_file->nb_element > 0 &&
+           !bsu->exclude_file) {
+           g_printf("ERROR application %s doesn't support exclude-file\n",
+                  dle->program);
+       }
+       if (dle->exclude_list && dle->exclude_list->nb_element > 0 &&
+           !bsu->exclude_list) {
+           g_printf("ERROR application %s doesn't support exclude-list\n",
+                  dle->program);
+       }
+       if (dle->exclude_optional && !bsu->exclude_optional) {
+           g_printf("ERROR application %s doesn't support optional exclude\n",
+                  dle->program);
+       }
+       fflush(stdout);fflush(stderr);
 
-       if (pipe(property_pipe) < 0) {
-           err = vstrallocf(_("pipe failed: %s"), strerror(errno));
+       if (pipe(app_err) < 0) {
+           err = vstrallocf(_("Application '%s': can't create pipe"),
+                            dle->program);
            goto common_exit;
        }
-       fflush(stdout);fflush(stderr);
-       
-       switch (backup_api_pid = fork()) {
+
+       switch (application_api_pid = fork()) {
        case -1:
            err = vstrallocf(_("fork failed: %s"), strerror(errno));
            goto common_exit;
 
        case 0: /* child */
            {
-               char *argvchild[14];
-               char *cmd = vstralloc(DUMPER_DIR, "/", program, NULL);
-               int j=0;
-               argvchild[j++] = program;
-               argvchild[j++] = "selfcheck";
+               GPtrArray *argv_ptr = g_ptr_array_new();
+               guint i;
+               char *cmd = vstralloc(APPLICATION_DIR, "/", dle->program, NULL);
+               GSList   *scriptlist;
+               script_t *script;
+               estimatelist_t el;
+               char *cmdline;
+
+               aclose(app_err[0]);
+               dup2(app_err[1], 2);
+
+               g_ptr_array_add(argv_ptr, stralloc(dle->program));
+               g_ptr_array_add(argv_ptr, stralloc("selfcheck"));
                if (bsu->message_line == 1) {
-                   argvchild[j++] = "--message";
-                   argvchild[j++] = "line";
+                   g_ptr_array_add(argv_ptr, stralloc("--message"));
+                   g_ptr_array_add(argv_ptr, stralloc("line"));
                }
                if (g_options->config != NULL && bsu->config == 1) {
-                   argvchild[j++] = "--config";
-                   argvchild[j++] = g_options->config;
+                   g_ptr_array_add(argv_ptr, stralloc("--config"));
+                   g_ptr_array_add(argv_ptr, stralloc(g_options->config));
                }
                if (g_options->hostname != NULL && bsu->host == 1) {
-                   argvchild[j++] = "--host";
-                   argvchild[j++] = g_options->hostname;
+                   g_ptr_array_add(argv_ptr, stralloc("--host"));
+                   g_ptr_array_add(argv_ptr, stralloc(g_options->hostname));
                }
-               if (disk != NULL && bsu->disk == 1) {
-                   argvchild[j++] = "--disk";
-                   argvchild[j++] = disk;
+               if (dle->disk != NULL && bsu->disk == 1) {
+                   g_ptr_array_add(argv_ptr, stralloc("--disk"));
+                   g_ptr_array_add(argv_ptr, stralloc(dle->disk));
                }
-               argvchild[j++] = "--device";
-               argvchild[j++] = amdevice;
-               if(options && options->createindex && bsu->index_line == 1) {
-                   argvchild[j++] = "--index";
-                   argvchild[j++] = "line";
+               if (dle->device) {
+                   g_ptr_array_add(argv_ptr, stralloc("--device"));
+                   g_ptr_array_add(argv_ptr, stralloc(dle->device));
                }
-               if (!options->no_record && bsu->record == 1) {
-                   argvchild[j++] = "--record";
+               if (dle->create_index && bsu->index_line == 1) {
+                   g_ptr_array_add(argv_ptr, stralloc("--index"));
+                   g_ptr_array_add(argv_ptr, stralloc("line"));
                }
-               argvchild[j++] = NULL;
-               dup2(property_pipe[0], 0);
-               aclose(property_pipe[1]);
+               if (dle->record && bsu->record == 1) {
+                   g_ptr_array_add(argv_ptr, stralloc("--record"));
+               }
+               
+               for (el = dle->estimatelist; el != NULL; el=el->next) {
+                   estimate_t estimate = (estimate_t)GPOINTER_TO_INT(el->data);
+                   if (estimate == ES_CALCSIZE && bsu->calcsize == 1) {
+                       g_ptr_array_add(argv_ptr, stralloc("--calcsize"));
+                   }
+               }
+               application_property_add_to_argv(argv_ptr, dle, bsu,
+                                                g_options->features);
+
+               for (scriptlist = dle->scriptlist; scriptlist != NULL;
+                    scriptlist = scriptlist->next) {
+                   script = (script_t *)scriptlist->data;
+                   if (script->result && script->result->proplist) {
+                       property_add_to_argv(argv_ptr,
+                                            script->result->proplist);
+                   }
+               }
+
+               g_ptr_array_add(argv_ptr, NULL);
+
+               cmdline = stralloc(cmd);
+               for (i = 0; i < argv_ptr->len-1; i++) {
+                   char *quoted = quote_string(
+                                       (char *)g_ptr_array_index(argv_ptr,i));
+                   cmdline = vstrextend(&cmdline, " ", quoted, NULL);
+                   amfree(quoted);
+               }
+               dbprintf(_("Spawning \"%s\" in pipeline\n"), cmdline);
+               amfree(cmdline);
+
                safe_fd(-1, 0);
-               execve(cmd,argvchild,safe_env());
+               execve(cmd, (char **)argv_ptr->pdata, safe_env());
                g_printf(_("ERROR [Can't execute %s: %s]\n"), cmd, strerror(errno));
                exit(127);
            }
        default: /* parent */
            {
-               int status;
-               aclose(property_pipe[0]);
-               toolin = fdopen(property_pipe[1],"w");
-               if (!toolin) {
-                   err = vstrallocf(_("Can't fdopen: %s"), strerror(errno));
-                   goto common_exit;
-               }
-               output_tool_property(toolin, options);
-               fflush(toolin);
-               fclose(toolin);
-               if (waitpid(backup_api_pid, &status, 0) < 0) {
-                   if (!WIFEXITED(status)) {
-                       err = vstrallocf(_("Tool exited with signal %d"),
-                                        WTERMSIG(status));
-                   } else if (WEXITSTATUS(status) != 0) {
-                       err = vstrallocf(_("Tool exited with status %d"),
-                                        WEXITSTATUS(status));
-                   } else {
-                       err = vstrallocf(_("waitpid returned negative value"));
+               int   status;
+               FILE *app_stderr;
+               char *line;
+
+               aclose(app_err[1]);
+               app_stderr = fdopen(app_err[0], "r");
+               while((line = agets(app_stderr)) != NULL) {
+                   if (strlen(line) > 0) {
+                       fprintf(stdout, "ERROR Application '%s': %s\n",
+                               dle->program, line);
+                       dbprintf("ERROR %s\n", line);
                    }
+                   amfree(line);
+               }
+               fclose(app_stderr);
+               if (waitpid(application_api_pid, &status, 0) < 0) {
+                   err = vstrallocf(_("waitpid failed: %s"),
+                                        strerror(errno));
+                   goto common_exit;
+               } else if (!WIFEXITED(status)) {
+                   err = vstrallocf(_("Application '%s': exited with signal %d"),
+                                    dle->program, WTERMSIG(status));
+                   goto common_exit;
+               } else if (WEXITSTATUS(status) != 0) {
+                   err = vstrallocf(_("Application '%s': exited with status %d"),
+                                    dle->program, WEXITSTATUS(status));
                    goto common_exit;
                }
            }
@@ -778,29 +917,34 @@ check_disk(
        return;
     }
 
-    qdevice = quote_string(device);
-    dbprintf(_("device %s\n"), qdevice);
+    if (device) {
+       qdevice = quote_string(device);
+       dbprintf(_("device %s\n"), qdevice);
 
-    /* skip accessability test if this is an AFS entry */
-    if(strncmp_const(device, "afs:") != 0) {
+       /* skip accessability test if this is an AFS entry */
+       if(strncmp_const(device, "afs:") != 0) {
 #ifdef CHECK_FOR_ACCESS_WITH_OPEN
-       access_result = open(device, O_RDONLY);
-       access_type = "open";
+           access_result = open(device, O_RDONLY);
+           access_type = "open";
 #else
-       access_result = access(device, amode);
-       access_type = "access";
+           access_result = access(device, amode);
+           access_type = "access";
 #endif
-       if(access_result == -1) {
-           err = vstrallocf(_("Could not access %s (%s): %s"),
-                       qdevice, qdisk, strerror(errno));
-       }
+           if(access_result == -1) {
+               err = vstrallocf(_("Could not %s %s (%s): %s"),
+                                access_type, qdevice, qdisk, strerror(errno));
+           }
 #ifdef CHECK_FOR_ACCESS_WITH_OPEN
-       aclose(access_result);
+           aclose(access_result);
 #endif
+       }
     }
 
 common_exit:
 
+    if (!qdevice)
+       qdevice = quote_string(device);
+
     amfree(share);
     amfree(subdir);
     if(user_and_password) {
@@ -810,16 +954,22 @@ common_exit:
     amfree(domain);
 
     if(err) {
-       g_printf(_("ERROR [%s]\n"), err);
+       g_printf(_("ERROR %s\n"), err);
        dbprintf(_("%s\n"), err);
        amfree(err);
     } else {
-       g_printf("OK %s\n", qdisk);
-       dbprintf(_("disk %s OK\n"), qdisk);
-       g_printf("OK %s\n", qamdevice);
-       dbprintf(_("amdevice %s OK\n"), qamdevice);
-       g_printf("OK %s\n", qdevice);
-       dbprintf(_("device %s OK\n"), qdevice);
+       if (dle->disk) {
+           g_printf("OK %s\n", qdisk);
+           dbprintf(_("disk %s OK\n"), qdisk);
+       }
+       if (dle->device) {
+           g_printf("OK %s\n", qamdevice);
+           dbprintf(_("amdevice %s OK\n"), qamdevice);
+       }
+       if (device) {
+           g_printf("OK %s\n", qdevice);
+           dbprintf(_("device %s OK\n"), qdevice);
+       }
     }
     if(extra_info) {
        dbprintf(_("extra info: %s\n"), extra_info);
@@ -844,7 +994,7 @@ check_overall(void)
 
     if( need_runtar )
     {
-       cmd = vstralloc(amlibexecdir, "/", "runtar", versionsuffix(), NULL);
+       cmd = vstralloc(amlibexecdir, "/", "runtar", NULL);
        check_file(cmd,X_OK);
        check_suid(cmd);
        amfree(cmd);
@@ -852,7 +1002,7 @@ check_overall(void)
 
     if( need_rundump )
     {
-       cmd = vstralloc(amlibexecdir, "/", "rundump", versionsuffix(), NULL);
+       cmd = vstralloc(amlibexecdir, "/", "rundump", NULL);
        check_file(cmd,X_OK);
        check_suid(cmd);
        amfree(cmd);
@@ -928,27 +1078,35 @@ check_overall(void)
 #else
        g_printf(_("ERROR [GNUTAR program not available]\n"));
 #endif
-       need_amandates = 1;
        gnutar_list_dir = getconf_str(CNF_GNUTAR_LIST_DIR);
        if (strlen(gnutar_list_dir) == 0)
            gnutar_list_dir = NULL;
-       if (gnutar_list_dir) 
+       if (gnutar_list_dir) {
+           /* make sure our listed-incremental dir is ready */
            check_dir(gnutar_list_dir, R_OK|W_OK);
+       } else {
+           /* no listed-incremental dir, so check that amandates is ready */
+           need_amandates = 1;
+       }
     }
 
-    if (need_amandates) {
-       char *amandates_file;
-       amandates_file = getconf_str(CNF_AMANDATES);
-       check_file(amandates_file, R_OK|W_OK);
-    }
     if( need_calcsize ) {
        char *cmd;
 
-       cmd = vstralloc(amlibexecdir, "/", "calcsize", versionsuffix(), NULL);
+       cmd = vstralloc(amlibexecdir, "/", "calcsize", NULL);
 
        check_file(cmd, X_OK);
 
        amfree(cmd);
+
+       /* calcsize uses amandates */
+       need_amandates = 1;
+    }
+
+    if (need_amandates) {
+       char *amandates_file;
+       amandates_file = getconf_str(CNF_AMANDATES);
+       check_file(amandates_file, R_OK|W_OK);
     }
 
     if( need_samba ) {
@@ -980,8 +1138,8 @@ check_overall(void)
        check_file(COMPRESS_PATH, X_OK);
 
     if (need_dump || need_xfsdump ) {
-       if (check_file_exist("/etc/dumpdates")) {
-           check_file("/etc/dumpdates",
+       if (check_file_exist("/var/lib/dumpdates")) {
+           check_file("/var/lib/dumpdates",
 #ifdef USE_RUNDUMP
                       F_OK
 #else
@@ -991,18 +1149,19 @@ check_overall(void)
        } else {
 #ifndef USE_RUNDUMP
            if (access("/etc", R_OK|W_OK) == -1) {
-               g_printf(_("ERROR [dump will not be able to create the /etc/dumpdates file: %s]\n"), strerror(errno));
+               g_printf(_("ERROR [dump will not be able to create the /var/lib/dumpdates file: %s]\n"), strerror(errno));
            }
 #endif
        }
     }
 
     if (need_vdump) {
-       if (check_file_exist("/etc/vdumpdates")) {
-            check_file("/etc/vdumpdates", F_OK);
+       if (check_file_exist("/var/lib/vdumpdates")) {
+            check_file("/var/lib/vdumpdates", F_OK);
        }
     }
 
+    if (need_global_check) {
     check_access("/dev/null", R_OK|W_OK);
     check_space(AMANDA_TMPDIR, (off_t)64);     /* for amandad i/o */
 
@@ -1010,7 +1169,9 @@ check_overall(void)
     check_space(AMANDA_DBGDIR, (off_t)64);     /* for amandad i/o */
 #endif
 
+    check_space("/var/lib", (off_t)64);                /* for /var/lib/dumpdates writing */
     check_space("/etc", (off_t)64);            /* for /etc/dumpdates writing */
+    }
 }
 
 static void
@@ -1045,30 +1206,6 @@ check_space(
     amfree(quoted);
 }
 
-static void
-check_access(
-    char *     filename,
-    int                mode)
-{
-    char *noun, *adjective;
-    char *quoted = quote_string(filename);
-
-    if(mode == F_OK)
-        noun = "find", adjective = "exists";
-    else if((mode & X_OK) == X_OK)
-       noun = "execute", adjective = "executable";
-    else if((mode & (W_OK|R_OK)) == (W_OK|R_OK))
-       noun = "read/write", adjective = "read/writable";
-    else 
-       noun = "access", adjective = "accessible";
-
-    if(access(filename, mode) == -1)
-       g_printf(_("ERROR [can not %s %s: %s]\n"), noun, quoted, strerror(errno));
-    else
-       g_printf(_("OK %s %s\n"), quoted, adjective);
-    amfree(quoted);
-}
-
 static int
 check_file_exist(
     char *filename)
@@ -1084,65 +1221,83 @@ check_file_exist(
 }
 
 static void
-check_file(
-    char *     filename,
-    int                mode)
+print_platform(void)
 {
     struct stat stat_buf;
-    char *quoted;
-
-    if(!stat(filename, &stat_buf)) {
-       if(!S_ISREG(stat_buf.st_mode)) {
-           quoted = quote_string(filename);
-           g_printf(_("ERROR [%s is not a file]\n"), quoted);
-           amfree(quoted);
+    char *uname;
+    char *distro = NULL;
+    char *platform = NULL;
+    char  line[1025];
+    GPtrArray *argv_ptr;
+
+    if (stat("/etc/lsb-release", &stat_buf) == 0) {
+       FILE *release = fopen("/etc/lsb-release", "r");
+       distro = "Ubuntu";
+       if (release) {
+           while (fgets(line, 1024, release)) {
+               if (strstr(line, "DESCRIPTION")) {
+                   platform = strchr(line, '=');
+                   if (platform) platform++;
+               }
+           }
+           fclose(release);
        }
-    }
-    check_access(filename, mode);
-}
-
-static void
-check_dir(
-    char *     dirname,
-    int                mode)
-{
-    struct stat stat_buf;
-    char *quoted;
-    char *dir;
-
-    if(!stat(dirname, &stat_buf)) {
-       if(!S_ISDIR(stat_buf.st_mode)) {
-           quoted = quote_string(dirname);
-           g_printf(_("ERROR [%s is not a directory]\n"), quoted);
-           amfree(quoted);
+    } else if (stat("/etc/redhat-release", &stat_buf) == 0) {
+       FILE *release = fopen("/etc/redhat-release", "r");
+       distro = "RPM";
+       if (release) {
+           char *result;
+           result = fgets(line, 1024, release);
+           if (result) {
+               platform = line;
+           }
+           fclose(release);
        }
-    }
-    dir = stralloc2(dirname, "/.");
-    check_access(dir, mode);
-    amfree(dir);
-}
-
-static void
-check_suid(
-    char *     filename)
-{
-#ifndef SINGLE_USERID
-    struct stat stat_buf;
-    char *quoted = quote_string(filename);
-
-    if(!stat(filename, &stat_buf)) {
-       if(stat_buf.st_uid != 0 ) {
-           g_printf(_("ERROR [%s is not owned by root]\n"), quoted);
+    } else if (stat("/etc/debian_version", &stat_buf) == 0) {
+       FILE *release = fopen("/etc/debian_version", "r");
+       distro = "Debian";
+       if (release) {
+           char *result;
+           result = fgets(line, 1024, release);
+           if (result) {
+               platform = line;
+           }
+           fclose(release);
        }
-       if((stat_buf.st_mode & S_ISUID) != S_ISUID) {
-           g_printf(_("ERROR [%s is not SUID root]\n"), quoted);
+    } else {
+       argv_ptr = g_ptr_array_new();
+
+       g_ptr_array_add(argv_ptr, UNAME_PATH);
+       g_ptr_array_add(argv_ptr, "-s");
+       g_ptr_array_add(argv_ptr, NULL);
+       uname = get_first_line(argv_ptr);
+       if (uname) {
+           if (strncmp(uname, "SunOS", 5) == 0) {
+               FILE *release = fopen("/etc/release", "r");
+               distro = "Solaris";
+               if (release) {
+                   char *result;
+                   result = fgets(line, 1024, release);
+                   if (result) {
+                       platform = line;
+                   }
+                   fclose(release);
+               }
+           }
+           amfree(uname);
        }
+       g_ptr_array_free(argv_ptr, TRUE);
     }
-    else {
-       g_printf(_("ERROR [can not stat %s]\n"), quoted);
+
+    if (!distro) {
+       distro = "Unknown";
     }
-    amfree(quoted);
-#else
-    (void)filename;    /* Quiet unused parameter warning */
-#endif
+    if (!platform) {
+       platform = "Unknown";
+    }
+    if (platform[strlen(platform) -1] == '\n') {
+       platform[strlen(platform) -1] = '\0';
+    }
+    g_fprintf(stdout, "OK distro %s\n", distro);
+    g_fprintf(stdout, "OK platform %s\n", platform);
 }