1 | /* Copyright 1998 by the Massachusetts Institute of Technology. |
---|
2 | * |
---|
3 | * Permission to use, copy, modify, and distribute this |
---|
4 | * software and its documentation for any purpose and without |
---|
5 | * fee is hereby granted, provided that the above copyright |
---|
6 | * notice appear in all copies and that both that copyright |
---|
7 | * notice and this permission notice appear in supporting |
---|
8 | * documentation, and that the name of M.I.T. not be used in |
---|
9 | * advertising or publicity pertaining to distribution of the |
---|
10 | * software without specific, written prior permission. |
---|
11 | * M.I.T. makes no representations about the suitability of |
---|
12 | * this software for any purpose. It is provided "as is" |
---|
13 | * without express or implied warranty. |
---|
14 | */ |
---|
15 | |
---|
16 | /* This file is part of liblocker. It implements some of the code for |
---|
17 | * MUL lockers. (Most of the code for MUL lockers is special-cased |
---|
18 | * into attachtab.c, attach.c, and detach.c.) |
---|
19 | */ |
---|
20 | |
---|
21 | static const char rcsid[] = "$Id: mul.c,v 1.2 1999-03-29 17:33:24 danw Exp $"; |
---|
22 | |
---|
23 | #include <sys/stat.h> |
---|
24 | #include <ctype.h> |
---|
25 | #include <errno.h> |
---|
26 | #include <stdlib.h> |
---|
27 | #include <string.h> |
---|
28 | #include <unistd.h> |
---|
29 | |
---|
30 | #include "locker.h" |
---|
31 | #include "locker_private.h" |
---|
32 | |
---|
33 | static int mul_parse(locker_context context, char *name, char *desc, |
---|
34 | char *mountpoint, locker_attachent **at); |
---|
35 | static int mul_attach(locker_context context, locker_attachent *at, |
---|
36 | char *mountoptions); |
---|
37 | static int mul_detach(locker_context context, locker_attachent *at); |
---|
38 | static int mul_auth(locker_context context, locker_attachent *at, |
---|
39 | int mode, int op); |
---|
40 | static int mul_zsubs(locker_context context, locker_attachent *at); |
---|
41 | |
---|
42 | struct locker_ops locker__mul_ops = { |
---|
43 | "MUL", |
---|
44 | 0, |
---|
45 | mul_parse, |
---|
46 | mul_attach, |
---|
47 | mul_detach, |
---|
48 | mul_auth, |
---|
49 | mul_zsubs |
---|
50 | }; |
---|
51 | |
---|
52 | static int mul_parse(locker_context context, char *name, char *desc, |
---|
53 | char *mountpoint, locker_attachent **atp) |
---|
54 | { |
---|
55 | int status; |
---|
56 | char *p, *q, *dup, *lasts = NULL; |
---|
57 | locker_attachent *at, *attmp; |
---|
58 | |
---|
59 | if (!name) |
---|
60 | { |
---|
61 | locker__error(context, "Cannot explicitly specify MUL locker.\n"); |
---|
62 | return LOCKER_EPARSE; |
---|
63 | } |
---|
64 | |
---|
65 | if (mountpoint) |
---|
66 | { |
---|
67 | locker__error(context, "%s: Explicit mountpoint is meaningless for " |
---|
68 | "MUL locker.\n", name); |
---|
69 | return LOCKER_EPARSE; |
---|
70 | } |
---|
71 | |
---|
72 | at = locker__new_attachent(context, &locker__mul_ops); |
---|
73 | if (!at) |
---|
74 | return LOCKER_ENOMEM; |
---|
75 | |
---|
76 | /* Skip "MUL". (But if this is called from read_attachent, the "MUL" |
---|
77 | * won't be there.) |
---|
78 | */ |
---|
79 | if (!strncmp(desc, "MUL ", 4)) |
---|
80 | { |
---|
81 | p = desc + 4; |
---|
82 | while (isspace(*p)) |
---|
83 | p++; |
---|
84 | } |
---|
85 | else |
---|
86 | p = desc; |
---|
87 | |
---|
88 | at->name = strdup(name); |
---|
89 | at->mountpoint = strdup(p); |
---|
90 | at->hostdir = strdup(""); |
---|
91 | at->mode = '-'; |
---|
92 | dup = strdup(p); |
---|
93 | if (!at->name || !at->mountpoint || !at->hostdir || !dup) |
---|
94 | { |
---|
95 | locker_free_attachent(context, at); |
---|
96 | locker__error(context, "Out of memory parsing locker description.\n"); |
---|
97 | return LOCKER_ENOMEM; |
---|
98 | } |
---|
99 | |
---|
100 | /* Read list of locker names. */ |
---|
101 | for (p = strtok_r(dup, " ", &lasts); p; p = strtok_r(NULL, " ", &lasts)) |
---|
102 | { |
---|
103 | status = locker__lookup_attachent(context, p, NULL, 1, &attmp); |
---|
104 | if (status) |
---|
105 | break; |
---|
106 | |
---|
107 | if (attmp->fs == at->fs) |
---|
108 | { |
---|
109 | locker__error(context, "%s: Cannot have MUL locker \"%s\" as a " |
---|
110 | "component of a MUL locker.\n", at->name, |
---|
111 | attmp->name); |
---|
112 | locker_free_attachent(context, attmp); |
---|
113 | status = LOCKER_EPARSE; |
---|
114 | break; |
---|
115 | } |
---|
116 | |
---|
117 | attmp->next = at->next; |
---|
118 | at->next = attmp; |
---|
119 | } |
---|
120 | |
---|
121 | free(dup); |
---|
122 | |
---|
123 | if (status) |
---|
124 | { |
---|
125 | for (; at; at = attmp) |
---|
126 | { |
---|
127 | attmp = at->next; |
---|
128 | locker_free_attachent(context, at); |
---|
129 | } |
---|
130 | } |
---|
131 | else |
---|
132 | *atp = at; |
---|
133 | |
---|
134 | return status; |
---|
135 | } |
---|
136 | |
---|
137 | static int mul_attach(locker_context context, locker_attachent *at, |
---|
138 | char *mountoptions) |
---|
139 | { |
---|
140 | return LOCKER_SUCCESS; |
---|
141 | } |
---|
142 | |
---|
143 | static int mul_detach(locker_context context, locker_attachent *at) |
---|
144 | { |
---|
145 | return LOCKER_SUCCESS; |
---|
146 | } |
---|
147 | |
---|
148 | static int mul_auth(locker_context context, locker_attachent *at, |
---|
149 | int mode, int op) |
---|
150 | { |
---|
151 | return LOCKER_SUCCESS; |
---|
152 | } |
---|
153 | |
---|
154 | static int mul_zsubs(locker_context context, locker_attachent *at) |
---|
155 | { |
---|
156 | return LOCKER_SUCCESS; |
---|
157 | } |
---|