4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License, Version 1.0 only
6 * (the "License"). You may not use this file except in compliance
9 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10 * or http://www.opensolaris.org/os/licensing.
11 * See the License for the specific language governing permissions
12 * and limitations under the License.
14 * When distributing Covered Code, include this CDDL HEADER in each
15 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16 * If applicable, add the following below this CDDL HEADER, with the
17 * fields enclosed by brackets "[]" replaced with your own identifying
18 * information: Portions Copyright [yyyy] [name of copyright owner]
23 * Copyright 2005 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
30 #pragma ident "%Z%%M% %I% %E% SMI"
36 #include <sys/param.h>
38 #include <sys/mntent.h>
39 #include <sys/mnttab.h>
40 #include <sys/mount.h>
41 #include <sys/utsname.h>
42 #include <sys/tiuser.h>
46 #include <rpcsvc/daemon_utils.h>
47 #include "automount.h"
49 #define MNTTAB_OPTS "ignore,nest"
52 static void process_opts(char *options
, int *directp
);
53 static char *concat_opts(const char *opts1
, const char *opts2
);
54 static int ro_given(char *options
);
57 * list of support services needed
59 static char *service_list
[] = { AUTOMOUNTD
, NULL
};
62 main(int argc
, char *argv
[])
69 char *mntpnt
, *mapname
;
70 struct utsname utsname
;
71 char autofs_addr
[MAXADDRLEN
];
72 struct autofs_args fni
;
74 int mount_timeout
= AUTOFS_MOUNT_TIMEOUT
;
75 char obuf
[MAX_MNTOPT_STR
];
77 while ((c
= getopt(argc
, argv
, "o:mrq")) != EOF
) {
91 case 'r': /* converted to -o ro always */
95 * The "quiet" flag can be ignored, since this
96 * program never complains about invalid -o options
106 if (argc
- optind
!= 2)
109 mapname
= argv
[optind
];
110 mntpnt
= argv
[optind
+ 1];
112 if (strcmp(mntpnt
, "/-") == 0) {
113 (void) fprintf(stderr
, "invalid mountpoint: /-\n");
117 if (uname(&utsname
) < 0) {
121 (void) strcpy(autofs_addr
, utsname
.nodename
);
122 (void) strcat(autofs_addr
, ".autofs");
124 process_opts(options
, &fni
.direct
);
126 if (roflg
&& !ro_given(options
))
127 options
= concat_opts(options
, "ro");
129 fni
.addr
.buf
= autofs_addr
;
130 fni
.addr
.len
= strlen(fni
.addr
.buf
);
131 fni
.addr
.maxlen
= fni
.addr
.len
;
140 fni
.mount_to
= mount_timeout
;
141 fni
.rpc_to
= AUTOFS_RPC_TIMEOUT
;
143 strcpy(obuf
, options
);
147 fni
.direct
? MNTTAB_OPTS
",direct" : MNTTAB_OPTS
",indirect");
150 * enable services as needed.
152 _check_services(service_list
);
154 error
= mount(fni
.map
, mntpnt
, mntflags
| MS_DATA
| MS_OPTIONSTR
,
155 MNTTYPE_AUTOFS
, &fni
, sizeof (fni
), obuf
, MAX_MNTOPT_STR
);
157 perror("autofs mount");
166 (void) fprintf(stderr
,
167 "Usage: autofs mount [-r] [-o opts] map dir\n");
172 * Remove pseudo-options "direct", "indirect", "nest", and "ignore" from
173 * option list. Set *directp to 1 if "direct" is found, and 0 otherwise
174 * (mounts are indirect by default). If both "direct" and "indirect" are
175 * found, the last one wins.
178 process_opts(char *options
, int *directp
)
183 if ((opts
= strdup(options
)) == NULL
) {
184 (void) fprintf(stderr
,
185 "autofs mount: memory allocation failed\n");
191 while ((opt
= strtok(opts
, ",")) != NULL
) {
193 while (isspace(*opt
)) {
196 if (strcmp(opt
, "direct") == 0) {
198 } else if (strcmp(opt
, "indirect") == 0) {
200 } else if ((strcmp(opt
, "nest") != 0) &&
201 (strcmp(opt
, "ignore") != 0)) {
202 if (options
[0] != '\0') {
203 (void) strcat(options
, ",");
205 (void) strcat(options
, opt
);
211 * Concatenate two options strings, with a comma between them.
214 concat_opts(const char *opts1
, const char *opts2
)
216 char *opts
= malloc(strlen(opts1
) + strlen(opts2
) + 2);
218 (void) fprintf(stderr
,
219 "autofs mount: memory allocation failed\n");
223 if (opts1
[0] != '\0' && opts2
[0] != '\0') {
226 return (strcat(opts
, opts2
));
230 * check the options string for 'ro' options
231 * if present returns 1 otherwise return 0;
235 ro_given(char *options
)
243 if (*op
== 'r' && *(op
+1) == 'o' &&
244 (*(op
+2) == ',' || *(op
+2) == '\0'))
247 if ((op
= strchr(op
, ',')) != NULL
)