auto_subr.c revision dd51520e127b452179a2ce4ea3bd8dee949f9afe
199767f8919635c4928607450d9e0abb932109ceToomas Soome * CDDL HEADER START
199767f8919635c4928607450d9e0abb932109ceToomas Soome * The contents of this file are subject to the terms of the
199767f8919635c4928607450d9e0abb932109ceToomas Soome * Common Development and Distribution License (the "License").
199767f8919635c4928607450d9e0abb932109ceToomas Soome * You may not use this file except in compliance with the License.
199767f8919635c4928607450d9e0abb932109ceToomas Soome * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
199767f8919635c4928607450d9e0abb932109ceToomas Soome * See the License for the specific language governing permissions
199767f8919635c4928607450d9e0abb932109ceToomas Soome * and limitations under the License.
199767f8919635c4928607450d9e0abb932109ceToomas Soome * When distributing Covered Code, include this CDDL HEADER in each
199767f8919635c4928607450d9e0abb932109ceToomas Soome * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
199767f8919635c4928607450d9e0abb932109ceToomas Soome * If applicable, add the following below this CDDL HEADER, with the
199767f8919635c4928607450d9e0abb932109ceToomas Soome * fields enclosed by brackets "[]" replaced with your own identifying
199767f8919635c4928607450d9e0abb932109ceToomas Soome * information: Portions Copyright [yyyy] [name of copyright owner]
199767f8919635c4928607450d9e0abb932109ceToomas Soome * CDDL HEADER END
199767f8919635c4928607450d9e0abb932109ceToomas Soome * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
199767f8919635c4928607450d9e0abb932109ceToomas Soomestatic char *check_hier(char *);
199767f8919635c4928607450d9e0abb932109ceToomas Soome * If the system is labeled then we need to
199767f8919635c4928607450d9e0abb932109ceToomas Soome * have a uniquely-named auto_home map for each zone.
199767f8919635c4928607450d9e0abb932109ceToomas Soome * The maps are made unique by appending the zonename.
199767f8919635c4928607450d9e0abb932109ceToomas Soome * The home directory is made unique by prepending /zone/<zonename>
199767f8919635c4928607450d9e0abb932109ceToomas Soome * for each zone that is dominated by the current zone.
199767f8919635c4928607450d9e0abb932109ceToomas Soome * The current zone's home directory mount point is not changed.
199767f8919635c4928607450d9e0abb932109ceToomas Soome * For each auto_home_<zonename> a default template map is created
199767f8919635c4928607450d9e0abb932109ceToomas Soome * only if it doesn't exist yet. The default entry is used to declare
199767f8919635c4928607450d9e0abb932109ceToomas Soome * local home directories created within each zone. For example:
199767f8919635c4928607450d9e0abb932109ceToomas Soome * +auto_home_public
199767f8919635c4928607450d9e0abb932109ceToomas Soome * * -fstype=lofs :/zone/public/export/home/&
199767f8919635c4928607450d9e0abb932109ceToomas Soomeloadzone_maps(char *mntpnt, char *map, char *opts, char **stack, char ***stkptr)
199767f8919635c4928607450d9e0abb932109ceToomas Soome /* list changed, try again */
199767f8919635c4928607450d9e0abb932109ceToomas Soome for (i = 0; i < nzents; i++) {
199767f8919635c4928607450d9e0abb932109ceToomas Soome if (getzonenamebyid(zids[i], zonename, ZONENAME_MAX) != -1) {
199767f8919635c4928607450d9e0abb932109ceToomas Soome (void) snprintf(appended_map, sizeof (appended_map),
199767f8919635c4928607450d9e0abb932109ceToomas Soome /* for current zone, leave mntpnt alone */
199767f8919635c4928607450d9e0abb932109ceToomas Soome dirinit(prepended_mntpnt, appended_map, opts, 0, stack,
199767f8919635c4928607450d9e0abb932109ceToomas Soome * Next create auto_home_<zone> maps for each zone
199767f8919635c4928607450d9e0abb932109ceToomas Soome * If the map file doesn't exist create a template
199767f8919635c4928607450d9e0abb932109ceToomas Soome if ((fd = open(map_path, O_RDWR | O_CREAT | O_EXCL,
199767f8919635c4928607450d9e0abb932109ceToomas Soome S_IRUSR | S_IWUSR | S_IRGRP| S_IROTH)) != -1) {
199767f8919635c4928607450d9e0abb932109ceToomas Soome "+%s\n*\t-fstype=lofs\t:%s/export/home/&\n",
199767f8919635c4928607450d9e0abb932109ceToomas Soomedirinit(char *mntpnt, char *map, char *opts, int direct, char **stack,
199767f8919635c4928607450d9e0abb932109ceToomas Soome if (*p == '/')
199767f8919635c4928607450d9e0abb932109ceToomas Soome * If it's a direct map then call dirinit
199767f8919635c4928607450d9e0abb932109ceToomas Soome * for every map entry.
199767f8919635c4928607450d9e0abb932109ceToomas Soome if ((strcmp(mntpnt, "/-") == 0) && !(nodirect_map)) {
199767f8919635c4928607450d9e0abb932109ceToomas Soome (void) loaddirect_map(map, map, opts, stack, stkptr);
199767f8919635c4928607450d9e0abb932109ceToomas Soome * Home directories are polyinstantiated on
199767f8919635c4928607450d9e0abb932109ceToomas Soome * labeled systems.
199767f8919635c4928607450d9e0abb932109ceToomas Soome (void) loadzone_maps(mntpnt, map, opts, stack, stkptr);
199767f8919635c4928607450d9e0abb932109ceToomas Soome * Append to dir chain
199767f8919635c4928607450d9e0abb932109ceToomas Soome * Check whether the mount point is a
199767f8919635c4928607450d9e0abb932109ceToomas Soome * subdirectory or a parent directory
199767f8919635c4928607450d9e0abb932109ceToomas Soome * of any previously mounted automount
199767f8919635c4928607450d9e0abb932109ceToomas Soome * mount point.
199767f8919635c4928607450d9e0abb932109ceToomas Soomestatic char *
199767f8919635c4928607450d9e0abb932109ceToomas Soome register char *p, *q;
199767f8919635c4928607450d9e0abb932109ceToomas Soome for (dir = dir_head; dir; dir = dir->dir_next) {
199767f8919635c4928607450d9e0abb932109ceToomas Soome for (; *p == *q; p++, q++)
199767f8919635c4928607450d9e0abb932109ceToomas Soome if (*p == '\0')
199767f8919635c4928607450d9e0abb932109ceToomas Soome return (NULL); /* it's not a subdir or parent */
199767f8919635c4928607450d9e0abb932109ceToomas Soome * Gets the next token from the string "p" and copies it into "w". The "wq" is
199767f8919635c4928607450d9e0abb932109ceToomas Soome * a quote vector for "w" and is derived from "pq", which is a quote vector for
199767f8919635c4928607450d9e0abb932109ceToomas Soome * "p". Delim is the character to be used as a delimiter for the scan. A space
199767f8919635c4928607450d9e0abb932109ceToomas Soome * means "whitespace". The call to getword must provide buffers w and wq of size
199767f8919635c4928607450d9e0abb932109ceToomas Soome * at least wordsz. getword() will pass strings of maximum length (wordsz-1),
199767f8919635c4928607450d9e0abb932109ceToomas Soome * since it needs to null terminate the string.
199767f8919635c4928607450d9e0abb932109ceToomas Soome * Returns 0 on ok and -1 on error.
199767f8919635c4928607450d9e0abb932109ceToomas Soomegetword(char *w, char *wq, char **p, char **pq, char delim, int wordsz)
199767f8919635c4928607450d9e0abb932109ceToomas Soome "getword: input word size %d must be > 0", wordsz);
199767f8919635c4928607450d9e0abb932109ceToomas Soome return (-1);
199767f8919635c4928607450d9e0abb932109ceToomas Soome while ((delim == ' ' ? isspace(**p) : **p == delim) && **pq == ' ')
199767f8919635c4928607450d9e0abb932109ceToomas Soome (*p)++, (*pq)++;
199767f8919635c4928607450d9e0abb932109ceToomas Soome while (**p &&
199767f8919635c4928607450d9e0abb932109ceToomas Soome !((delim == ' ' ? isspace(**p) : **p == delim) &&
199767f8919635c4928607450d9e0abb932109ceToomas Soome if (--count <= 0) {
199767f8919635c4928607450d9e0abb932109ceToomas Soome return (-1);
199767f8919635c4928607450d9e0abb932109ceToomas Soome *w++ = *(*p)++;
199767f8919635c4928607450d9e0abb932109ceToomas Soome * get_line attempts to get a line from the map, upto LINESZ. A line in
199767f8919635c4928607450d9e0abb932109ceToomas Soome * the map is a concatenation of lines if the continuation symbol '\'
199767f8919635c4928607450d9e0abb932109ceToomas Soome * is used at the end of the line. Returns line on success, a NULL on
199767f8919635c4928607450d9e0abb932109ceToomas Soome * EOF, and an empty string on lines > linesz.
199767f8919635c4928607450d9e0abb932109ceToomas Soomeget_line(FILE *fp, char *map, char *line, int linesz)
199767f8919635c4928607450d9e0abb932109ceToomas Soome register char *p = line;
199767f8919635c4928607450d9e0abb932109ceToomas Soome register int len;
199767f8919635c4928607450d9e0abb932109ceToomas Soome * Is input line too long?
199767f8919635c4928607450d9e0abb932109ceToomas Soome if (*p != '\n') {
199767f8919635c4928607450d9e0abb932109ceToomas Soome * Perhaps last char read was '\'. Reinsert it
199767f8919635c4928607450d9e0abb932109ceToomas Soome * into the stream to ease the parsing when we
199767f8919635c4928607450d9e0abb932109ceToomas Soome * read the rest of the line to discard.
199767f8919635c4928607450d9e0abb932109ceToomas Soome /* trim trailing white space */
199767f8919635c4928607450d9e0abb932109ceToomas Soome *p-- = '\0';
199767f8919635c4928607450d9e0abb932109ceToomas Soome * Ignore comments. Comments start with '#'
199767f8919635c4928607450d9e0abb932109ceToomas Soome * which must be preceded by a whitespace, unless
199767f8919635c4928607450d9e0abb932109ceToomas Soome * if '#' is the first character in the line.
199767f8919635c4928607450d9e0abb932109ceToomas Soome *p-- = '\0';
199767f8919635c4928607450d9e0abb932109ceToomas Soome * discard rest of line and return an empty string.
199767f8919635c4928607450d9e0abb932109ceToomas Soome * done to set the stream to the correct place when
199767f8919635c4928607450d9e0abb932109ceToomas Soome * we are done with this line.
199767f8919635c4928607450d9e0abb932109ceToomas Soome "map %s: line too long (max %d chars)",
199767f8919635c4928607450d9e0abb932109ceToomas Soome * Gets the retry=n entry from opts.
199767f8919635c4928607450d9e0abb932109ceToomas Soome * Returns 0 if retry=n is not present in option string,
199767f8919635c4928607450d9e0abb932109ceToomas Soome * retry=n is invalid, or when option string is NULL.
199767f8919635c4928607450d9e0abb932109ceToomas Soome while (p = (char *)strtok_r(pb, ",", &lasts)) {
199767f8919635c4928607450d9e0abb932109ceToomas Soome * Returns zero if "opt" is found in mnt->mnt_opts, setting
199767f8919635c4928607450d9e0abb932109ceToomas Soome * *sval to whatever follows the equal sign after "opt".
199767f8919635c4928607450d9e0abb932109ceToomas Soome * str_opt allocates a string long enough to store the value of
199767f8919635c4928607450d9e0abb932109ceToomas Soome * "opt" plus a terminating null character and returns it as *sval.
199767f8919635c4928607450d9e0abb932109ceToomas Soome * It is the responsability of the caller to deallocate *sval.
199767f8919635c4928607450d9e0abb932109ceToomas Soome * *sval will be equal to NULL upon return if either "opt=" is not found,
199767f8919635c4928607450d9e0abb932109ceToomas Soome * or "opt=" has no value associated with it.
199767f8919635c4928607450d9e0abb932109ceToomas Soome * stropt will return -1 on error.
199767f8919635c4928607450d9e0abb932109ceToomas Soomestr_opt(struct mnttab *mnt, char *opt, char **sval)
199767f8919635c4928607450d9e0abb932109ceToomas Soome * is "opt" in the options field?
199767f8919635c4928607450d9e0abb932109ceToomas Soome return (-1);
199767f8919635c4928607450d9e0abb932109ceToomas Soome return (-1);
199767f8919635c4928607450d9e0abb932109ceToomas Soome * Performs text expansions in the string "pline".
199767f8919635c4928607450d9e0abb932109ceToomas Soome * "plineq" is the quote vector for "pline".
199767f8919635c4928607450d9e0abb932109ceToomas Soome * An identifier prefixed by "$" is replaced by the
199767f8919635c4928607450d9e0abb932109ceToomas Soome * corresponding environment variable string. A "&"
199767f8919635c4928607450d9e0abb932109ceToomas Soome * is replaced by the key string for the map entry.
199767f8919635c4928607450d9e0abb932109ceToomas Soome * This routine will return an error (non-zero) if *size* would be
199767f8919635c4928607450d9e0abb932109ceToomas Soome * exceeded after expansion, indicating that the macro_expand failed.
199767f8919635c4928607450d9e0abb932109ceToomas Soome * This is to prevent writing past the end of pline and plineq.
199767f8919635c4928607450d9e0abb932109ceToomas Soome * Both pline and plineq are left untouched in such error case.
199767f8919635c4928607450d9e0abb932109ceToomas Soome register char *p, *q;
199767f8919635c4928607450d9e0abb932109ceToomas Soome register char *s;
199767f8919635c4928607450d9e0abb932109ceToomas Soome while (*p) {
199767f8919635c4928607450d9e0abb932109ceToomas Soome * make sure we don't overflow buffer
199767f8919635c4928607450d9e0abb932109ceToomas Soome if ((int)((bp - buffp) + strlen(key)) < size) {
199767f8919635c4928607450d9e0abb932109ceToomas Soome for (s = key; *s; s++) {
199767f8919635c4928607450d9e0abb932109ceToomas Soome * line too long...
199767f8919635c4928607450d9e0abb932109ceToomas Soome if (*p == '$' && *q == ' ') { /* insert env var */
199767f8919635c4928607450d9e0abb932109ceToomas Soome if (*p == '{') {
199767f8919635c4928607450d9e0abb932109ceToomas Soome while (*p && *p != '}') {
FALSE))
s = procbuf;
s = procbuf;
TRUE))
s = procbuf;
s = isaname;
s = procbuf;
*bp++ = *s++;
expand++;
*bp++ = *p++;
*bq++ = *q++;
if (!expand)
if (!escaped) {
quoted++;
quoted++;
inbracket++;
quoted++;
escaped = 0;
if (quoted)
unbracket(s)
trim(s)
int again = 0;
if (again)
char *s2;
int again = 0;
if (again)
return (s2);
struct dir_entry *
register struct dir_entry *p;
register int direction;
if (direction == 0)
if (direction > 0)
p = p->right;
else p = p->left;
return (NULL);
register int direction;
prev = p;
if (direction == 0) {
if (direction > 0)
p = p->right;
else p = p->left;
if (direction > 0)
struct dir_entry *e, *l;
*last = l;
e = (struct dir_entry *)
if (e == NULL)
return (ENOMEM);
(void) memset((char *)e, 0, sizeof (*e));
free(e);
return (ENOMEM);
*last = e;
if (id) {
isalist(void)
char *buf;
long ret;
return (NULL);
return (buf);
long ret;
long ret;
int bits;
char *lasts;
long ret;
put_automountd_env(void)
a = c = defval;
if (*a == NULL)
if (*a != NULL) {