Exemple #1
0
/*
 * Process one collected map.
 */
static int
process_one_regular_map(const cf_map_t *cfm)
{
  if (!cfm->cfm_name) {
    fprintf(stderr, "conf: map_name must be defined for map \"%s\"\n", cfm->cfm_dir);
    return 1;
  }
  /*
   * If map has no tag defined, process the map.
   * If no conf_tag was set in amd -T, process all untagged entries.
   * If a tag is defined, then process it only if it matches the map tag.
   */
  if (!cfm->cfm_tag ||
      (conf_tag && STREQ(cfm->cfm_tag, conf_tag))) {
#ifdef DEBUG_CONF
    fprintf(stderr, "processing map %s (flags=0x%x)...\n",
	    cfm->cfm_dir, cfm->cfm_flags);
#endif /* DEBUG_CONF */
    root_newmap(cfm->cfm_dir,
		cfm->cfm_opts ? cfm->cfm_opts : "",
		cfm->cfm_name,
		cfm);
  } else {
    fprintf(stderr, "skipping map %s...\n", cfm->cfm_dir);
  }

  return 0;
}
Exemple #2
0
void
get_args(int argc, char *argv[])
{
    int opt_ch;
    FILE *fp = stdin;
    char getopt_arguments[] = "+nprvSa:c:d:k:l:o:t:w:x:y:C:D:F:T:O:HA:";
    char *getopt_args;

#ifdef HAVE_GNU_GETOPT
    getopt_args = getopt_arguments;
#else /* ! HAVE_GNU_GETOPT */
    getopt_args = &getopt_arguments[1];
#endif /* HAVE_GNU_GETOPT */

    /* if no arguments were passed, try to use /etc/amd.conf file */
    if (argc <= 1)
        use_conf_file = 1;

    while ((opt_ch = getopt(argc, argv, getopt_args)) != -1)
        switch (opt_ch) {

        case 'a':
            if (*optarg != '/') {
                fprintf(stderr, "%s: -a option must begin with a '/'\n",
                        am_get_progname());
                exit(1);
            }
            gopt.auto_dir = optarg;
            break;

        case 'c':
            gopt.am_timeo = atoi(optarg);
            if (gopt.am_timeo <= 0)
                gopt.am_timeo = AM_TTL;
            break;

        case 'd':
            gopt.sub_domain = optarg;
            break;

        case 'k':
            gopt.karch = optarg;
            break;

        case 'l':
            gopt.logfile = optarg;
            break;

        case 'n':
            gopt.flags |= CFM_NORMALIZE_HOSTNAMES;
            break;

        case 'o':
            gopt.op_sys_ver = optarg;
            break;

        case 'p':
            gopt.flags |= CFM_PRINT_PID;
            break;

        case 'r':
            gopt.flags |= CFM_RESTART_EXISTING_MOUNTS;
            break;

        case 't':
            /* timeo.retrans */
        {
            char *dot = strchr(optarg, '.');
            if (dot)
                *dot = '\0';
            if (*optarg) {
                gopt.amfs_auto_timeo = atoi(optarg);
            }
            if (dot) {
                gopt.amfs_auto_retrans = atoi(dot + 1);
                *dot = '.';
            }
        }
        break;

        case 'v':
            fputs(get_version_string(), stderr);
            exit(0);
            break;

        case 'w':
            gopt.am_timeo_w = atoi(optarg);
            if (gopt.am_timeo_w <= 0)
                gopt.am_timeo_w = AM_TTL_W;
            break;

        case 'x':
            usage += switch_option(optarg);
            break;

        case 'y':
#ifdef HAVE_MAP_NIS
            gopt.nis_domain = optarg;
#else /* not HAVE_MAP_NIS */
            plog(XLOG_USER, "-y: option ignored.  No NIS support available.");
#endif /* not HAVE_MAP_NIS */
            break;

        case 'A':
            gopt.arch = optarg;
            break;

        case 'C':
            gopt.cluster = optarg;
            break;

        case 'D':
#ifdef DEBUG
            usage += debug_option(optarg);
#else /* not DEBUG */
            fprintf(stderr, "%s: not compiled with DEBUG option -- sorry.\n",
                    am_get_progname());
#endif /* not DEBUG */
            break;

        case 'F':
            conf_file = optarg;
            use_conf_file = 1;
            break;

        case 'H':
            goto show_usage;
            break;

        case 'O':
            gopt.op_sys = optarg;
            break;

        case 'S':
            gopt.flags &= ~CFM_PROCESS_LOCK; /* turn process locking off */
            break;

        case 'T':
            conf_tag = optarg;
            break;

        default:
            usage = 1;
            break;
        }

    /*
     * amd.conf file: if not command-line arguments were used, or if -F was
     * specified, then use that amd.conf file.  If the file cannot be opened,
     * abort amd.  If it can be found, open it, parse it, and then close it.
     */
    if (use_conf_file && conf_file) {
        fp = fopen(conf_file, "r");
        if (!fp) {
            char buf[128];
            sprintf(buf, "Amd configuration file (%s)", conf_file);
            perror(buf);
            exit(1);
        }
        yyin = fp;
        yyparse();
        fclose(fp);
        if (process_last_regular_map() != 0)
            exit(1);
    }

    /* make sure there are some default options defined */
    if (xlog_level_init == ~0) {
        switch_option("");
    }
#ifdef DEBUG
    usage += switch_option("debug");
#endif /* DEBUG */

    /* log information regarding amd.conf file */
    if (use_conf_file && conf_file)
        plog(XLOG_INFO, "using configuration file %s", conf_file);

#ifdef HAVE_MAP_LDAP
    /* ensure that if ldap_base is specified, that also ldap_hostports is */
    if (gopt.ldap_hostports && !gopt.ldap_base) {
        fprintf(stderr, "must specify both ldap_hostports and ldap_base\n");
        exit(1);
    }
#endif /* HAVE_MAP_LDAP */

    if (usage)
        goto show_usage;

    while (optind <= argc - 2) {
        char *dir = argv[optind++];
        char *map = argv[optind++];
        char *opts = "";
        if (argv[optind] && *argv[optind] == '-')
            opts = &argv[optind++][1];

        root_newmap(dir, opts, map, NULL);
    }

    if (optind == argc) {
        /*
         * Append domain name to hostname.
         * sub_domain overrides hostdomain
         * if given.
         */
        if (gopt.sub_domain)
            hostdomain = gopt.sub_domain;
        if (*hostdomain == '.')
            hostdomain++;
        strcat(hostd, ".");
        strcat(hostd, hostdomain);

#ifdef MOUNT_TABLE_ON_FILE
#ifdef DEBUG
        amuDebug(D_MTAB)
        mnttab_file_name = DEBUG_MNTTAB;
        else
#endif /* DEBUG */
            mnttab_file_name = MNTTAB_FILE_NAME;
#else /* not MOUNT_TABLE_ON_FILE */
        amuDebug(D_MTAB)
        dlog("-D mtab option ignored");
# ifdef MNTTAB_FILE_NAME
        mnttab_file_name = MNTTAB_FILE_NAME;
# endif /* MNTTAB_FILE_NAME */
#endif /* not MOUNT_TABLE_ON_FILE */

        if (switch_to_logfile(gopt.logfile, orig_umask) != 0)
            plog(XLOG_USER, "Cannot switch logfile");

        /*
         * If the kernel architecture was not specified
         * then use the machine architecture.
         */
        if (gopt.karch == 0)
            gopt.karch = gopt.arch;

        if (gopt.cluster == 0)
            gopt.cluster = hostdomain;

        if (gopt.amfs_auto_timeo <= 0)
            gopt.amfs_auto_timeo = AMFS_AUTO_TIMEO;
        if (gopt.amfs_auto_retrans <= 0)
            gopt.amfs_auto_retrans = AMFS_AUTO_RETRANS;
        if (gopt.amfs_auto_retrans <= 0)
            gopt.amfs_auto_retrans = 3;	/* XXX */
        return;
    }