1 1.21 mlelstv /* $NetBSD: mount_filecore.c,v 1.21 2020/07/26 08:20:22 mlelstv Exp $ */ 2 1.1 mark 3 1.1 mark /* 4 1.1 mark * Copyright (c) 1992, 1993, 1994 The Regents of the University of California. 5 1.1 mark * All rights reserved. 6 1.8 agc * 7 1.8 agc * This code is contains code contributed to the NetBSD project by 8 1.8 agc * Christopher G. Demetriou 9 1.8 agc * 10 1.8 agc * Redistribution and use in source and binary forms, with or without 11 1.8 agc * modification, are permitted provided that the following conditions 12 1.8 agc * are met: 13 1.8 agc * 1. Redistributions of source code must retain the above copyright 14 1.8 agc * notice, this list of conditions and the following disclaimer. 15 1.8 agc * 2. Redistributions in binary form must reproduce the above copyright 16 1.8 agc * notice, this list of conditions and the following disclaimer in the 17 1.8 agc * documentation and/or other materials provided with the distribution. 18 1.8 agc * 3. Neither the name of the University nor the names of its contributors 19 1.8 agc * may be used to endorse or promote products derived from this software 20 1.8 agc * without specific prior written permission. 21 1.8 agc * 22 1.8 agc * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 23 1.8 agc * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 24 1.8 agc * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 25 1.8 agc * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 26 1.8 agc * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 27 1.8 agc * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 28 1.8 agc * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 29 1.8 agc * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 30 1.8 agc * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 31 1.8 agc * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 32 1.8 agc * SUCH DAMAGE. 33 1.8 agc * 34 1.8 agc * mount_filecore.c 1.1 1998/6/26 35 1.8 agc */ 36 1.8 agc 37 1.8 agc /* 38 1.8 agc * Copyright (c) 1998 Andrew McMurry 39 1.1 mark * 40 1.1 mark * This code is contains code contributed to the NetBSD project by 41 1.1 mark * Christopher G. Demetriou 42 1.1 mark * 43 1.1 mark * Redistribution and use in source and binary forms, with or without 44 1.1 mark * modification, are permitted provided that the following conditions 45 1.1 mark * are met: 46 1.1 mark * 1. Redistributions of source code must retain the above copyright 47 1.1 mark * notice, this list of conditions and the following disclaimer. 48 1.1 mark * 2. Redistributions in binary form must reproduce the above copyright 49 1.1 mark * notice, this list of conditions and the following disclaimer in the 50 1.1 mark * documentation and/or other materials provided with the distribution. 51 1.1 mark * 3. All advertising materials mentioning features or use of this software 52 1.1 mark * must display the following acknowledgement: 53 1.1 mark * This product includes software developed by the University of 54 1.1 mark * California, Berkeley and its contributors. 55 1.1 mark * 4. Neither the name of the University nor the names of its contributors 56 1.1 mark * may be used to endorse or promote products derived from this software 57 1.1 mark * without specific prior written permission. 58 1.1 mark * 59 1.1 mark * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 60 1.1 mark * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 61 1.1 mark * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 62 1.1 mark * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 63 1.1 mark * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 64 1.1 mark * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 65 1.1 mark * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 66 1.1 mark * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 67 1.1 mark * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 68 1.1 mark * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 69 1.1 mark * SUCH DAMAGE. 70 1.1 mark * 71 1.1 mark * mount_filecore.c 1.1 1998/6/26 72 1.1 mark */ 73 1.1 mark 74 1.1 mark #include <sys/cdefs.h> 75 1.1 mark #ifndef lint 76 1.1 mark __COPYRIGHT("@(#) Copyright (c) 1992, 1993, 1994\ 77 1.18 lukem The Regents of the University of California.\ 78 1.18 lukem Copyright (c) 1998 Andrew McMurry. All rights reserved."); 79 1.1 mark #endif /* not lint */ 80 1.1 mark 81 1.1 mark #include <sys/param.h> 82 1.1 mark #include <sys/mount.h> 83 1.1 mark 84 1.1 mark #include <err.h> 85 1.1 mark #include <grp.h> 86 1.1 mark #include <pwd.h> 87 1.1 mark #include <stdlib.h> 88 1.1 mark #include <stdio.h> 89 1.1 mark #include <string.h> 90 1.1 mark #include <unistd.h> 91 1.5 christos #include <util.h> 92 1.1 mark 93 1.1 mark #include <filecorefs/filecore_mount.h> 94 1.1 mark 95 1.7 jdolecek #include <mntopts.h> 96 1.19 pooka 97 1.19 pooka #include "mountprog.h" 98 1.1 mark 99 1.4 jdolecek static const struct mntopt mopts[] = { 100 1.1 mark MOPT_STDOPTS, 101 1.1 mark MOPT_UPDATE, 102 1.5 christos MOPT_GETARGS, 103 1.14 christos MOPT_NULL, 104 1.1 mark }; 105 1.1 mark 106 1.11 xtraeme int mount_filecore(int argc, char **argv); 107 1.20 joerg __dead static void usage(void); 108 1.1 mark 109 1.4 jdolecek #ifndef MOUNT_NOMAIN 110 1.1 mark int 111 1.11 xtraeme main(int argc, char **argv) 112 1.1 mark { 113 1.4 jdolecek return mount_filecore(argc, argv); 114 1.4 jdolecek } 115 1.4 jdolecek #endif 116 1.4 jdolecek 117 1.4 jdolecek int 118 1.11 xtraeme mount_filecore(int argc, char **argv) 119 1.4 jdolecek { 120 1.1 mark struct filecore_args args; 121 1.1 mark int ch, mntflags, opts, useuid; 122 1.10 erh char *dev, *dir, canon_dev[MAXPATHLEN], canon_dir[MAXPATHLEN]; 123 1.13 christos mntoptparse_t mp; 124 1.1 mark 125 1.1 mark mntflags = opts = 0; 126 1.1 mark useuid = 1; 127 1.1 mark args.uid = 0; 128 1.1 mark args.gid = 0; 129 1.1 mark 130 1.1 mark while ((ch = getopt(argc, argv, "anRfu:g:o:")) != -1) 131 1.1 mark switch (ch) { 132 1.1 mark case 'a': 133 1.1 mark args.flags |= FILECOREMNT_ALLACCESS; 134 1.1 mark break; 135 1.1 mark case 'n': 136 1.1 mark args.flags |= FILECOREMNT_OWNACCESS; 137 1.1 mark break; 138 1.1 mark case 'R': 139 1.1 mark args.flags |= FILECOREMNT_OWNREAD; 140 1.1 mark break; 141 1.1 mark case 'f': 142 1.1 mark args.flags |= FILECOREMNT_FILETYPE; 143 1.1 mark break; 144 1.1 mark case 'u': 145 1.1 mark args.uid = a_uid(optarg); 146 1.1 mark useuid = 0; 147 1.1 mark break; 148 1.1 mark case 'g': 149 1.1 mark args.gid = a_gid(optarg); 150 1.1 mark useuid = 0; 151 1.1 mark break; 152 1.1 mark case 'o': 153 1.13 christos mp = getmntopts(optarg, mopts, &mntflags, 0); 154 1.13 christos if (mp == NULL) 155 1.13 christos err(1, "getmntopts"); 156 1.13 christos freemntopts(mp); 157 1.1 mark break; 158 1.1 mark case '?': 159 1.1 mark default: 160 1.1 mark usage(); 161 1.1 mark } 162 1.1 mark argc -= optind; 163 1.1 mark argv += optind; 164 1.1 mark 165 1.1 mark if (argc != 2) 166 1.1 mark usage(); 167 1.1 mark 168 1.21 mlelstv pathadj(argv[0], canon_dev); 169 1.21 mlelstv dev = canon_dev; 170 1.1 mark 171 1.21 mlelstv pathadj(argv[0], canon_dir); 172 1.21 mlelstv dir = canon_dir; 173 1.10 erh 174 1.1 mark #define DEFAULT_ROOTUID -2 175 1.1 mark /* 176 1.6 wiz * FILECORE filesystems are not writable. 177 1.1 mark */ 178 1.1 mark mntflags |= MNT_RDONLY; 179 1.1 mark if (useuid) args.flags |= FILECOREMNT_USEUID; 180 1.1 mark args.fspec = dev; 181 1.1 mark args.flags = opts; 182 1.1 mark 183 1.17 pooka if (mount(MOUNT_FILECORE, dir, mntflags, &args, sizeof args) == -1) 184 1.2 perseant err(1, "%s on %s", dev, dir); 185 1.5 christos if (mntflags & MNT_GETARGS) { 186 1.5 christos char buf[1024]; 187 1.5 christos (void)snprintb(buf, sizeof(buf), FILECOREMNT_BITS, args.flags); 188 1.5 christos printf("uid=%d, gid=%d, flags=%s\n", args.uid, args.gid, buf); 189 1.5 christos } 190 1.1 mark exit(0); 191 1.1 mark } 192 1.1 mark 193 1.4 jdolecek static void 194 1.11 xtraeme usage(void) 195 1.1 mark { 196 1.1 mark (void)fprintf(stderr, 197 1.9 wiz "usage: mount_filecore [-afnR] [-g gid] [-o options] [-u uid] special node\n"); 198 1.1 mark exit(1); 199 1.1 mark } 200