Deleted Added
full compact
mountd.c (292864) mountd.c (293305)
1/*
2 * Copyright (c) 1989, 1993
3 * The Regents of the University of California. All rights reserved.
4 *
5 * This code is derived from software contributed to Berkeley by
6 * Herb Hasler and Rick Macklem at The University of Guelph.
7 *
8 * Redistribution and use in source and binary forms, with or without

--- 29 unchanged lines hidden (view full) ---

38
39#if 0
40#ifndef lint
41static char sccsid[] = "@(#)mountd.c 8.15 (Berkeley) 5/1/95";
42#endif /*not lint*/
43#endif
44
45#include <sys/cdefs.h>
1/*
2 * Copyright (c) 1989, 1993
3 * The Regents of the University of California. All rights reserved.
4 *
5 * This code is derived from software contributed to Berkeley by
6 * Herb Hasler and Rick Macklem at The University of Guelph.
7 *
8 * Redistribution and use in source and binary forms, with or without

--- 29 unchanged lines hidden (view full) ---

38
39#if 0
40#ifndef lint
41static char sccsid[] = "@(#)mountd.c 8.15 (Berkeley) 5/1/95";
42#endif /*not lint*/
43#endif
44
45#include <sys/cdefs.h>
46__FBSDID("$FreeBSD: head/usr.sbin/mountd/mountd.c 292864 2015-12-29 11:24:41Z uqs $");
46__FBSDID("$FreeBSD: head/usr.sbin/mountd/mountd.c 293305 2016-01-07 05:34:39Z jpaetzel $");
47
48#include <sys/param.h>
49#include <sys/fcntl.h>
50#include <sys/linker.h>
51#include <sys/module.h>
52#include <sys/mount.h>
53#include <sys/stat.h>
54#include <sys/sysctl.h>

--- 114 unchanged lines hidden (view full) ---

169static void add_dlist(struct dirlist **, struct dirlist *,
170 struct grouplist *, int, struct exportlist *);
171static void add_mlist(char *, char *);
172static int check_dirpath(char *);
173static int check_options(struct dirlist *);
174static int checkmask(struct sockaddr *sa);
175static int chk_host(struct dirlist *, struct sockaddr *, int *, int *,
176 int *, int **);
47
48#include <sys/param.h>
49#include <sys/fcntl.h>
50#include <sys/linker.h>
51#include <sys/module.h>
52#include <sys/mount.h>
53#include <sys/stat.h>
54#include <sys/sysctl.h>

--- 114 unchanged lines hidden (view full) ---

169static void add_dlist(struct dirlist **, struct dirlist *,
170 struct grouplist *, int, struct exportlist *);
171static void add_mlist(char *, char *);
172static int check_dirpath(char *);
173static int check_options(struct dirlist *);
174static int checkmask(struct sockaddr *sa);
175static int chk_host(struct dirlist *, struct sockaddr *, int *, int *,
176 int *, int **);
177static char *strsep_quote(char **stringp, const char *delim);
177static int create_service(struct netconfig *nconf);
178static void complete_service(struct netconfig *nconf, char *port_str);
179static void clearout_service(void);
180static void del_mlist(char *hostp, char *dirp);
181static struct dirlist *dirp_search(struct dirlist *, char *);
182static int do_mount(struct exportlist *, struct grouplist *, int,
183 struct xucred *, char *, int, struct statfs *);
184static int do_opt(char **, char **, struct exportlist *,

--- 88 unchanged lines hidden (view full) ---

273static int debug = 1;
274static void SYSLOG(int, const char *, ...) __printflike(2, 3);
275#define syslog SYSLOG
276#else
277static int debug = 0;
278#endif
279
280/*
178static int create_service(struct netconfig *nconf);
179static void complete_service(struct netconfig *nconf, char *port_str);
180static void clearout_service(void);
181static void del_mlist(char *hostp, char *dirp);
182static struct dirlist *dirp_search(struct dirlist *, char *);
183static int do_mount(struct exportlist *, struct grouplist *, int,
184 struct xucred *, char *, int, struct statfs *);
185static int do_opt(char **, char **, struct exportlist *,

--- 88 unchanged lines hidden (view full) ---

274static int debug = 1;
275static void SYSLOG(int, const char *, ...) __printflike(2, 3);
276#define syslog SYSLOG
277#else
278static int debug = 0;
279#endif
280
281/*
282 * Similar to strsep(), but it allows for quoted strings
283 * and escaped characters.
284 *
285 * It returns the string (or NULL, if *stringp is NULL),
286 * which is a de-quoted version of the string if necessary.
287 *
288 * It modifies *stringp in place.
289 */
290static char *
291strsep_quote(char **stringp, const char *delim)
292{
293 char *srcptr, *dstptr, *retval;
294 char quot = 0;
295
296 if (stringp == NULL || *stringp == NULL)
297 return (NULL);
298
299 srcptr = dstptr = retval = *stringp;
300
301 while (*srcptr) {
302 /*
303 * We're looking for several edge cases here.
304 * First: if we're in quote state (quot != 0),
305 * then we ignore the delim characters, but otherwise
306 * process as normal, unless it is the quote character.
307 * Second: if the current character is a backslash,
308 * we take the next character as-is, without checking
309 * for delim, quote, or backslash. Exception: if the
310 * next character is a NUL, that's the end of the string.
311 * Third: if the character is a quote character, we toggle
312 * quote state.
313 * Otherwise: check the current character for NUL, or
314 * being in delim, and end the string if either is true.
315 */
316 if (*srcptr == '\\') {
317 srcptr++;
318 /*
319 * The edge case here is if the next character
320 * is NUL, we want to stop processing. But if
321 * it's not NUL, then we simply want to copy it.
322 */
323 if (*srcptr) {
324 *dstptr++ = *srcptr++;
325 }
326 continue;
327 }
328 if (quot == 0 && (*srcptr == '\'' || *srcptr == '"')) {
329 quot = *srcptr++;
330 continue;
331 }
332 if (quot && *srcptr == quot) {
333 /* End of the quoted part */
334 quot = 0;
335 srcptr++;
336 continue;
337 }
338 if (!quot && strchr(delim, *srcptr))
339 break;
340 *dstptr++ = *srcptr++;
341 }
342
343 *dstptr = 0; /* Terminate the string */
344 *stringp = (*srcptr == '\0') ? NULL : srcptr + 1;
345 return (retval);
346}
347
348/*
281 * Mountd server for NFS mount protocol as described in:
282 * NFS: Network File System Protocol Specification, RFC1094, Appendix A
283 * The optional arguments are the exports file name
284 * default: _PATH_EXPORTS
285 * and "-n" to allow nonroot mount.
286 */
287int
288main(int argc, char **argv)

--- 2537 unchanged lines hidden (view full) ---

2826 * Set up the unprivileged user.
2827 */
2828 cr->cr_uid = -2;
2829 cr->cr_groups[0] = -2;
2830 cr->cr_ngroups = 1;
2831 /*
2832 * Get the user's password table entry.
2833 */
349 * Mountd server for NFS mount protocol as described in:
350 * NFS: Network File System Protocol Specification, RFC1094, Appendix A
351 * The optional arguments are the exports file name
352 * default: _PATH_EXPORTS
353 * and "-n" to allow nonroot mount.
354 */
355int
356main(int argc, char **argv)

--- 2537 unchanged lines hidden (view full) ---

2894 * Set up the unprivileged user.
2895 */
2896 cr->cr_uid = -2;
2897 cr->cr_groups[0] = -2;
2898 cr->cr_ngroups = 1;
2899 /*
2900 * Get the user's password table entry.
2901 */
2834 names = strsep(&namelist, " \t\n");
2902 names = strsep_quote(&namelist, " \t\n");
2835 name = strsep(&names, ":");
2903 name = strsep(&names, ":");
2904 /* Bug? name could be NULL here */
2836 if (isdigit(*name) || *name == '-')
2837 pw = getpwuid(atoi(name));
2838 else
2839 pw = getpwnam(name);
2840 /*
2841 * Credentials specified as those of a user.
2842 */
2843 if (names == NULL) {

--- 378 unchanged lines hidden ---
2905 if (isdigit(*name) || *name == '-')
2906 pw = getpwuid(atoi(name));
2907 else
2908 pw = getpwnam(name);
2909 /*
2910 * Credentials specified as those of a user.
2911 */
2912 if (names == NULL) {

--- 378 unchanged lines hidden ---