/* * Mount the root... */ static int amfs_root_mount(am_node *mp, mntfs *mf) { mf->mf_mount = strealloc(mf->mf_mount, pid_fsname); mf->mf_private = (voidp) mapc_find(mf->mf_info, "", NULL); mf->mf_prfree = mapc_free; return 0; }
/* * Normalize a host name */ void host_normalize(char **chp) { /* * Normalize hosts is used to resolve host name aliases * and replace them with the standard-form name. * Invoked with "-n" command line option. */ if (gopt.flags & CFM_NORMALIZE_HOSTNAMES) { struct hostent *hp; clock_valid = 0; hp = gethostbyname(*chp); if (hp && hp->h_addrtype == AF_INET) { dlog("Hostname %s normalized to %s", *chp, hp->h_name); *chp = strealloc(*chp, (char *) hp->h_name); } } domain_strip(*chp, hostd); }
static char * amfs_parse_defaults(am_node *mp, mntfs *mf, char *def_opts) { char *dflts; char *dfl; char **rvec = NULL; struct mnt_map *mm = (mnt_map *) mf->mf_private; dlog("determining /defaults entry value"); /* * Find out if amd.conf overrode any map-specific /defaults. */ if (mm->cfm && mm->cfm->cfm_defaults) { dlog("map %s map_defaults override: %s", mf->mf_mount, mm->cfm->cfm_defaults); dflts = xstrdup(mm->cfm->cfm_defaults); } else if (mapc_search(mm, "/defaults", &dflts) == 0) { dlog("/defaults gave %s", dflts); } else { return def_opts; /* if nothing found */ } /* trim leading '-' in case thee's one */ if (*dflts == '-') dfl = dflts + 1; else dfl = dflts; /* * Chop the defaults up */ rvec = strsplit(dfl, ' ', '\"'); if (gopt.flags & CFM_SELECTORS_IN_DEFAULTS) { /* * Pick whichever first entry matched the list of selectors. * Strip the selectors from the string, and assign to dfl the * rest of the string. */ if (rvec) { am_opts ap; am_ops *pt; char **sp = rvec; while (*sp) { /* loop until you find something, if any */ memset((char *) &ap, 0, sizeof(am_opts)); /* * This next routine cause many spurious "expansion of ... is" * messages, which are ignored, b/c all we need out of this * routine is to match selectors. These spurious messages may * be wrong, esp. if they try to expand ${key} b/c it will * get expanded to "/defaults" */ pt = ops_match(&ap, *sp, "", mp->am_path, "/defaults", mp->am_parent->am_al->al_mnt->mf_info); free_opts(&ap); /* don't leak */ if (pt == &amfs_error_ops) { plog(XLOG_MAP, "did not match defaults for \"%s\"", *sp); } else { dfl = strip_selectors(*sp, "/defaults"); plog(XLOG_MAP, "matched default selectors \"%s\"", dfl); break; } ++sp; } } } else { /* not selectors_in_defaults */ /* * Extract first value */ dfl = rvec[0]; } /* * If there were any values at all... */ if (dfl) { /* * Log error if there were other values */ if (!(gopt.flags & CFM_SELECTORS_IN_DEFAULTS) && rvec[1]) { dlog("/defaults chopped into %s", dfl); plog(XLOG_USER, "More than a single value for /defaults in %s", mf->mf_info); } /* * Prepend to existing defaults if they exist, * otherwise just use these defaults. */ if (*def_opts && *dfl) { size_t l = strlen(def_opts) + strlen(dfl) + 2; char *nopts = (char *) xmalloc(l); xsnprintf(nopts, l, "%s;%s", dfl, def_opts); XFREE(def_opts); def_opts = nopts; } else if (*dfl) { def_opts = strealloc(def_opts, dfl); } } XFREE(dflts); /* don't need info vector any more */ if (rvec) XFREE(rvec); return def_opts; }
/* * Mount a sub-mount */ static int amfs_auto_mount(am_node *mp, mntfs *mf) { /* * Pseudo-directories are used to provide some structure * to the automounted directories instead * of putting them all in the top-level automount directory. * * Here, just increment the parent's link count. */ mp->am_parent->am_fattr.na_nlink++; /* * Info field of . means use parent's info field. * Historical - not documented. */ if (mf->mf_info[0] == '.' && mf->mf_info[1] == '\0') mf->mf_info = strealloc(mf->mf_info, mp->am_parent->am_mnt->mf_info); /* * Compute prefix: * * If there is an option prefix then use that else * If the parent had a prefix then use that with name * of this node appended else * Use the name of this node. * * That means if you want no prefix you must say so * in the map. */ if (mf->mf_fo->opt_pref) { /* allow pref:=null to set a real null prefix */ if (STREQ(mf->mf_fo->opt_pref, "null")) { mp->am_pref = strdup(""); } else { /* * the prefix specified as an option */ mp->am_pref = strdup(mf->mf_fo->opt_pref); } } else { /* * else the parent's prefix * followed by the name * followed by / */ char *ppref = mp->am_parent->am_pref; if (ppref == 0) ppref = ""; mp->am_pref = str3cat((char *) 0, ppref, mp->am_name, "/"); } #ifdef HAVE_FS_AUTOFS if (mf->mf_flags & MFF_IS_AUTOFS) { char opts[SIZEOF_OPTS]; int error; autofs_get_opts(opts, sizeof(opts), mp->am_autofs_fh); /* now do the mount */ error = amfs_mount(mp, mf, opts); if (error) { errno = error; plog(XLOG_FATAL, "amfs_auto_mount: amfs_mount failed: %m"); return error; } } #endif /* HAVE_FS_AUTOFS */ /* * Attach a map cache */ amfs_mkcacheref(mf); return 0; }