4 * Copyright (c) 1997-2009 Erez Zadok
5 * Copyright (c) 1989 Jan-Simon Pendry
6 * Copyright (c) 1989 Imperial College of Science, Technology & Medicine
7 * Copyright (c) 1989 The Regents of the University of California.
10 * This code is derived from software contributed to Berkeley by
11 * Jan-Simon Pendry at Imperial College, London.
13 * Redistribution and use in source and binary forms, with or without
14 * modification, are permitted provided that the following conditions
16 * 1. Redistributions of source code must retain the above copyright
17 * notice, this list of conditions and the following disclaimer.
18 * 2. Redistributions in binary form must reproduce the above copyright
19 * notice, this list of conditions and the following disclaimer in the
20 * documentation and/or other materials provided with the distribution.
21 * 3. All advertising materials mentioning features or use of this software
22 * must display the following acknowledgment:
23 * This product includes software developed by the University of
24 * California, Berkeley and its contributors.
25 * 4. Neither the name of the University nor the names of its contributors
26 * may be used to endorse or promote products derived from this software
27 * without specific prior written permission.
29 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
30 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
31 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
32 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
33 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
34 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
35 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
36 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
37 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
38 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
42 * File: am-utils/libamu/mtab.c
48 #endif /* HAVE_CONFIG_H */
54 * Firewall /etc/mtab entries
57 mnt_free(mntent_t
*mp
)
59 XFREE(mp
->mnt_fsname
);
64 #ifdef HAVE_MNTENT_T_MNT_TIME
65 # ifdef HAVE_MNTENT_T_MNT_TIME_STRING
67 # endif /* HAVE_MNTENT_T_MNT_TIME_STRING */
68 #endif /* HAVE_MNTENT_T_MNT_TIME */
75 * Discard memory allocated for mount list
78 discard_mntlist(mntlist
*mp
)
92 * Throw away a mount list
95 free_mntlist(mntlist
*mp
)
98 #ifdef MOUNT_TABLE_ON_FILE
100 #endif /* MOUNT_TABLE_ON_FILE */
105 * Utility routine which returns a pointer to whatever follows an = in a
106 * string. Returns null if = is not found in the string.
112 char *eq
= strchr(instr
, '=');
120 * Utility routine which returns a pointer to whatever
121 * follows an = in a mount option. Returns null if option
122 * doesn't exist or doesn't have an '='. Won't fail for opt,foo=.
125 hasmnteq(mntent_t
*mnt
, char *opt
)
127 if (mnt
&& opt
) { /* disallow null input pointers */
128 if ( *opt
) { /* disallow the null string as an opt */
129 char *str
= amu_hasmntopt(mnt
, opt
);
130 if ( str
) { /* option was there */
131 char *eq
= str
+ strlen(opt
); /* Look at char just after option */
132 if (*eq
== '=') /* Is it '=' ? */
133 return ++eq
; /* If so, return pointer to remaining str */
142 * Wrapper around hasmntvalerr(), which retains backwards compatibiliy with
143 * older use of hasmntval().
145 * XXX: eventually, all use of hasmntval() should be replaced with
149 hasmntval(mntent_t
*mnt
, char *opt
)
153 err
= hasmntvalerr(mnt
, opt
, &val
);
154 if (err
) /* if there was an error (hasmntvalerr returned 1) */
155 return 0; /* redundant: val==0 above, but leave here for clarity */
156 /* otherwise there was no error */
162 * Utility routine which determines the value of a numeric option in the
163 * mount options (such as port=%d), and fills in the value in the argument
164 * valp (argument won't be touched if no value is set, for example due to an
167 * Returns non-zero (1) on error; returns 0 on success.
169 * XXX: eventually, all use of hasmntval() should be replaced with
173 hasmntvalerr(mntent_t
*mnt
, char *opt
, int *valp
)
175 char *str
= amu_hasmntopt(mnt
, opt
);
176 int err
= 1; /* 1 means no good value was set (an error) */
180 /* exit if no option specificed */
185 eq
= hasmnteq(mnt
, opt
);
187 if (!eq
) { /* no argument to option ('=' sign was missing) */
188 plog(XLOG_MAP
, "numeric option to \"%s\" missing", opt
);
192 /* if got here, then we had an '=' after option name */
194 i
= strtol(eq
, &endptr
, 0); /* hex and octal allowed ;-) */
196 (endptr
!= eq
&& (*endptr
== ',' || *endptr
== '\0'))) {
198 * endptr set means strtol saw a non-digit. If the non-digit is a
199 * comma, it's probably the start of the next option. If the comma is
200 * the first char though, complain about it (foo=,bar is made
201 * noticeable by this).
203 * Similar reasoning for '\0' instead of comma, it's the end of the
206 *valp
= (int) i
; /* set good value */
207 err
= 0; /* no error */
209 /* whatever was after the '=' sign wasn't a number */
210 plog(XLOG_MAP
, "invalid numeric option in \"%s\": \"%s\"", opt
, str
);
211 /* fall through to error/exit processing */
220 * Utility routine which returns the string value of
221 * an option in the mount options (such as proto=udp).
222 * Returns NULL if the option is not specified.
223 * Returns malloc'ed string (caller must free!)
226 hasmntstr(mntent_t
*mnt
, char *opt
)
228 char *str
= amu_hasmntopt(mnt
, opt
);
230 if (str
) { /* The option was there */
232 char *eq
= hasmnteq(mnt
, opt
);
234 if (eq
) { /* and had an = after it */
236 char *endptr
= strchr(eq
, ',');
238 /* if saw no comma, return strdup'd string */
242 /* else we need to copy only the chars needed */
243 int len
= endptr
- eq
;
244 char *buf
= xmalloc(len
+ 1);
245 strncpy(buf
, eq
, len
);