1e0b8e63eSJohn Marino /*-
2e0b8e63eSJohn Marino * Copyright (c) 1992, 1993, 1994
3e0b8e63eSJohn Marino * The Regents of the University of California. All rights reserved.
4e0b8e63eSJohn Marino * Copyright (c) 1992, 1993, 1994, 1995, 1996
5e0b8e63eSJohn Marino * Keith Bostic. All rights reserved.
6e0b8e63eSJohn Marino *
7e0b8e63eSJohn Marino * See the LICENSE file for redistribution information.
8e0b8e63eSJohn Marino */
9e0b8e63eSJohn Marino
10e0b8e63eSJohn Marino #include "config.h"
11e0b8e63eSJohn Marino
12e0b8e63eSJohn Marino #include <sys/types.h>
13e0b8e63eSJohn Marino #include <sys/queue.h>
14e0b8e63eSJohn Marino #include <sys/stat.h>
15e0b8e63eSJohn Marino
16e0b8e63eSJohn Marino #include <bitstring.h>
17e0b8e63eSJohn Marino #include <fcntl.h>
18e0b8e63eSJohn Marino #include <limits.h>
19e0b8e63eSJohn Marino #include <stdio.h>
20e0b8e63eSJohn Marino #include <stdlib.h>
21e0b8e63eSJohn Marino #include <string.h>
22e0b8e63eSJohn Marino #include <unistd.h>
23e0b8e63eSJohn Marino
24e0b8e63eSJohn Marino #include "../common/common.h"
25e0b8e63eSJohn Marino #include "tag.h"
26e0b8e63eSJohn Marino #include "pathnames.h"
27e0b8e63eSJohn Marino
28e0b8e63eSJohn Marino enum rc { NOEXIST, NOPERM, RCOK };
29e0b8e63eSJohn Marino static enum rc exrc_isok(SCR *, struct stat *, char *, int, int);
30e0b8e63eSJohn Marino
31e0b8e63eSJohn Marino static int ex_run_file(SCR *, char *);
32e0b8e63eSJohn Marino
33e0b8e63eSJohn Marino /*
34e0b8e63eSJohn Marino * ex_screen_copy --
35e0b8e63eSJohn Marino * Copy ex screen.
36e0b8e63eSJohn Marino *
37e0b8e63eSJohn Marino * PUBLIC: int ex_screen_copy(SCR *, SCR *);
38e0b8e63eSJohn Marino */
39e0b8e63eSJohn Marino int
ex_screen_copy(SCR * orig,SCR * sp)40e0b8e63eSJohn Marino ex_screen_copy(SCR *orig, SCR *sp)
41e0b8e63eSJohn Marino {
42e0b8e63eSJohn Marino EX_PRIVATE *oexp, *nexp;
43e0b8e63eSJohn Marino
44e0b8e63eSJohn Marino /* Create the private ex structure. */
45*b1ac2ebbSDaniel Fojt CALLOC_RET(orig, nexp, 1, sizeof(EX_PRIVATE));
46e0b8e63eSJohn Marino sp->ex_private = nexp;
47e0b8e63eSJohn Marino
48e0b8e63eSJohn Marino /* Initialize queues. */
49e0b8e63eSJohn Marino TAILQ_INIT(nexp->tq);
50e0b8e63eSJohn Marino TAILQ_INIT(nexp->tagfq);
51e0b8e63eSJohn Marino SLIST_INIT(nexp->cscq);
52e0b8e63eSJohn Marino
53e0b8e63eSJohn Marino if (orig == NULL) {
54e0b8e63eSJohn Marino } else {
55e0b8e63eSJohn Marino oexp = EXP(orig);
56e0b8e63eSJohn Marino
57e0b8e63eSJohn Marino if (oexp->lastbcomm != NULL &&
58e0b8e63eSJohn Marino (nexp->lastbcomm = v_wstrdup(sp, oexp->lastbcomm,
59e0b8e63eSJohn Marino STRLEN(oexp->lastbcomm))) == NULL) {
60e0b8e63eSJohn Marino msgq(sp, M_SYSERR, NULL);
61e0b8e63eSJohn Marino return(1);
62e0b8e63eSJohn Marino }
63e0b8e63eSJohn Marino if (ex_tag_copy(orig, sp))
64e0b8e63eSJohn Marino return (1);
65e0b8e63eSJohn Marino }
66e0b8e63eSJohn Marino return (0);
67e0b8e63eSJohn Marino }
68e0b8e63eSJohn Marino
69e0b8e63eSJohn Marino /*
70e0b8e63eSJohn Marino * ex_screen_end --
71e0b8e63eSJohn Marino * End a vi screen.
72e0b8e63eSJohn Marino *
73e0b8e63eSJohn Marino * PUBLIC: int ex_screen_end(SCR *);
74e0b8e63eSJohn Marino */
75e0b8e63eSJohn Marino int
ex_screen_end(SCR * sp)76e0b8e63eSJohn Marino ex_screen_end(SCR *sp)
77e0b8e63eSJohn Marino {
78e0b8e63eSJohn Marino EX_PRIVATE *exp;
79e0b8e63eSJohn Marino int rval;
80e0b8e63eSJohn Marino
81e0b8e63eSJohn Marino if ((exp = EXP(sp)) == NULL)
82e0b8e63eSJohn Marino return (0);
83e0b8e63eSJohn Marino
84e0b8e63eSJohn Marino rval = 0;
85e0b8e63eSJohn Marino
86e0b8e63eSJohn Marino /* Close down script connections. */
87e0b8e63eSJohn Marino if (F_ISSET(sp, SC_SCRIPT) && sscr_end(sp))
88e0b8e63eSJohn Marino rval = 1;
89e0b8e63eSJohn Marino
90e0b8e63eSJohn Marino if (argv_free(sp))
91e0b8e63eSJohn Marino rval = 1;
92e0b8e63eSJohn Marino
93e0b8e63eSJohn Marino free(exp->ibp);
94e0b8e63eSJohn Marino
95e0b8e63eSJohn Marino free(exp->lastbcomm);
96e0b8e63eSJohn Marino
97e0b8e63eSJohn Marino free(exp->ibcw.bp1.c);
98e0b8e63eSJohn Marino
99e0b8e63eSJohn Marino if (ex_tag_free(sp))
100e0b8e63eSJohn Marino rval = 1;
101e0b8e63eSJohn Marino
102e0b8e63eSJohn Marino if (cscope_end(sp))
103e0b8e63eSJohn Marino rval = 1;
104e0b8e63eSJohn Marino
105e0b8e63eSJohn Marino /* Free private memory. */
106e0b8e63eSJohn Marino free(exp);
107e0b8e63eSJohn Marino sp->ex_private = NULL;
108e0b8e63eSJohn Marino
109e0b8e63eSJohn Marino return (rval);
110e0b8e63eSJohn Marino }
111e0b8e63eSJohn Marino
112e0b8e63eSJohn Marino /*
113e0b8e63eSJohn Marino * ex_optchange --
114e0b8e63eSJohn Marino * Handle change of options for ex.
115e0b8e63eSJohn Marino *
116e0b8e63eSJohn Marino * PUBLIC: int ex_optchange(SCR *, int, char *, u_long *);
117e0b8e63eSJohn Marino */
118e0b8e63eSJohn Marino int
ex_optchange(SCR * sp,int offset,char * str,u_long * valp)119e0b8e63eSJohn Marino ex_optchange(SCR *sp, int offset, char *str, u_long *valp)
120e0b8e63eSJohn Marino {
121e0b8e63eSJohn Marino switch (offset) {
122e0b8e63eSJohn Marino case O_TAGS:
123e0b8e63eSJohn Marino return (ex_tagf_alloc(sp, str));
124e0b8e63eSJohn Marino }
125e0b8e63eSJohn Marino return (0);
126e0b8e63eSJohn Marino }
127e0b8e63eSJohn Marino
128e0b8e63eSJohn Marino /*
129e0b8e63eSJohn Marino * ex_exrc --
130e0b8e63eSJohn Marino * Read the EXINIT environment variable and the startup exrc files,
131e0b8e63eSJohn Marino * and execute their commands.
132e0b8e63eSJohn Marino *
133e0b8e63eSJohn Marino * PUBLIC: int ex_exrc(SCR *);
134e0b8e63eSJohn Marino */
135e0b8e63eSJohn Marino int
ex_exrc(SCR * sp)136e0b8e63eSJohn Marino ex_exrc(SCR *sp)
137e0b8e63eSJohn Marino {
138e0b8e63eSJohn Marino struct stat hsb, lsb;
139e0b8e63eSJohn Marino char *p, *path;
140e0b8e63eSJohn Marino CHAR_T *wp;
141e0b8e63eSJohn Marino size_t wlen;
142e0b8e63eSJohn Marino
143e0b8e63eSJohn Marino /*
144e0b8e63eSJohn Marino * Source the system, environment, $HOME and local .exrc values.
145e0b8e63eSJohn Marino * Vi historically didn't check $HOME/.exrc if the environment
146e0b8e63eSJohn Marino * variable EXINIT was set. This is all done before the file is
147e0b8e63eSJohn Marino * read in, because things in the .exrc information can set, for
148e0b8e63eSJohn Marino * example, the recovery directory.
149e0b8e63eSJohn Marino *
150e0b8e63eSJohn Marino * !!!
151e0b8e63eSJohn Marino * While nvi can handle any of the options settings of historic vi,
152e0b8e63eSJohn Marino * the converse is not true. Since users are going to have to have
153e0b8e63eSJohn Marino * files and environmental variables that work with both, we use nvi
154e0b8e63eSJohn Marino * versions of both the $HOME and local startup files if they exist,
155e0b8e63eSJohn Marino * otherwise the historic ones.
156e0b8e63eSJohn Marino *
157e0b8e63eSJohn Marino * !!!
158e0b8e63eSJohn Marino * For a discussion of permissions and when what .exrc files are
159e0b8e63eSJohn Marino * read, see the comment above the exrc_isok() function below.
160e0b8e63eSJohn Marino *
161e0b8e63eSJohn Marino * !!!
162e0b8e63eSJohn Marino * If the user started the historic of vi in $HOME, vi read the user's
163e0b8e63eSJohn Marino * .exrc file twice, as $HOME/.exrc and as ./.exrc. We avoid this, as
164e0b8e63eSJohn Marino * it's going to make some commands behave oddly, and I can't imagine
165e0b8e63eSJohn Marino * anyone depending on it.
166e0b8e63eSJohn Marino */
167e0b8e63eSJohn Marino switch (exrc_isok(sp, &hsb, _PATH_SYSEXRC, 1, 0)) {
168e0b8e63eSJohn Marino case NOEXIST:
169e0b8e63eSJohn Marino case NOPERM:
170e0b8e63eSJohn Marino break;
171e0b8e63eSJohn Marino case RCOK:
172e0b8e63eSJohn Marino if (ex_run_file(sp, _PATH_SYSEXRC))
173e0b8e63eSJohn Marino return (1);
174e0b8e63eSJohn Marino break;
175e0b8e63eSJohn Marino }
176e0b8e63eSJohn Marino
177e0b8e63eSJohn Marino /* Run the commands. */
178e0b8e63eSJohn Marino if (EXCMD_RUNNING(sp->gp))
179e0b8e63eSJohn Marino (void)ex_cmd(sp);
180e0b8e63eSJohn Marino if (F_ISSET(sp, SC_EXIT | SC_EXIT_FORCE))
181e0b8e63eSJohn Marino return (0);
182e0b8e63eSJohn Marino
183e0b8e63eSJohn Marino if ((p = getenv("NEXINIT")) != NULL) {
184e0b8e63eSJohn Marino CHAR2INT(sp, p, strlen(p) + 1, wp, wlen);
185e0b8e63eSJohn Marino if (ex_run_str(sp, "NEXINIT", wp, wlen - 1, 1, 0))
186e0b8e63eSJohn Marino return (1);
187e0b8e63eSJohn Marino } else if ((p = getenv("EXINIT")) != NULL) {
188e0b8e63eSJohn Marino CHAR2INT(sp, p, strlen(p) + 1, wp, wlen);
189e0b8e63eSJohn Marino if (ex_run_str(sp, "EXINIT", wp, wlen - 1, 1, 0))
190e0b8e63eSJohn Marino return (1);
191e0b8e63eSJohn Marino } else if ((p = getenv("HOME")) != NULL && *p) {
192e0b8e63eSJohn Marino int st = 0;
193e0b8e63eSJohn Marino
194e0b8e63eSJohn Marino if ((path = join(p, _PATH_NEXRC)) == NULL) {
195e0b8e63eSJohn Marino msgq(sp, M_SYSERR, NULL);
196e0b8e63eSJohn Marino return (1);
197e0b8e63eSJohn Marino }
198e0b8e63eSJohn Marino switch (exrc_isok(sp, &hsb, path, 0, 1)) {
199e0b8e63eSJohn Marino case NOEXIST:
200e0b8e63eSJohn Marino free(path);
201e0b8e63eSJohn Marino if ((path = join(p, _PATH_EXRC)) == NULL) {
202e0b8e63eSJohn Marino msgq(sp, M_SYSERR, NULL);
203e0b8e63eSJohn Marino return (1);
204e0b8e63eSJohn Marino }
205e0b8e63eSJohn Marino if (exrc_isok(sp,
206e0b8e63eSJohn Marino &hsb, path, 0, 1) == RCOK && ex_run_file(sp, path))
207e0b8e63eSJohn Marino st = 1;
208e0b8e63eSJohn Marino break;
209e0b8e63eSJohn Marino case NOPERM:
210e0b8e63eSJohn Marino break;
211e0b8e63eSJohn Marino case RCOK:
212e0b8e63eSJohn Marino if (ex_run_file(sp, path))
213e0b8e63eSJohn Marino st = 1;
214e0b8e63eSJohn Marino break;
215e0b8e63eSJohn Marino }
216e0b8e63eSJohn Marino free(path);
217e0b8e63eSJohn Marino if (st)
218e0b8e63eSJohn Marino return st;
219e0b8e63eSJohn Marino }
220e0b8e63eSJohn Marino
221e0b8e63eSJohn Marino /* Run the commands. */
222e0b8e63eSJohn Marino if (EXCMD_RUNNING(sp->gp))
223e0b8e63eSJohn Marino (void)ex_cmd(sp);
224e0b8e63eSJohn Marino if (F_ISSET(sp, SC_EXIT | SC_EXIT_FORCE))
225e0b8e63eSJohn Marino return (0);
226e0b8e63eSJohn Marino
227e0b8e63eSJohn Marino /* Previous commands may have set the exrc option. */
228e0b8e63eSJohn Marino if (O_ISSET(sp, O_EXRC)) {
229e0b8e63eSJohn Marino switch (exrc_isok(sp, &lsb, _PATH_NEXRC, 0, 0)) {
230e0b8e63eSJohn Marino case NOEXIST:
231e0b8e63eSJohn Marino if (exrc_isok(sp, &lsb, _PATH_EXRC, 0, 0) == RCOK &&
232e0b8e63eSJohn Marino (lsb.st_dev != hsb.st_dev ||
233e0b8e63eSJohn Marino lsb.st_ino != hsb.st_ino) &&
234e0b8e63eSJohn Marino ex_run_file(sp, _PATH_EXRC))
235e0b8e63eSJohn Marino return (1);
236e0b8e63eSJohn Marino break;
237e0b8e63eSJohn Marino case NOPERM:
238e0b8e63eSJohn Marino break;
239e0b8e63eSJohn Marino case RCOK:
240e0b8e63eSJohn Marino if ((lsb.st_dev != hsb.st_dev ||
241e0b8e63eSJohn Marino lsb.st_ino != hsb.st_ino) &&
242e0b8e63eSJohn Marino ex_run_file(sp, _PATH_NEXRC))
243e0b8e63eSJohn Marino return (1);
244e0b8e63eSJohn Marino break;
245e0b8e63eSJohn Marino }
246e0b8e63eSJohn Marino /* Run the commands. */
247e0b8e63eSJohn Marino if (EXCMD_RUNNING(sp->gp))
248e0b8e63eSJohn Marino (void)ex_cmd(sp);
249e0b8e63eSJohn Marino if (F_ISSET(sp, SC_EXIT | SC_EXIT_FORCE))
250e0b8e63eSJohn Marino return (0);
251e0b8e63eSJohn Marino }
252e0b8e63eSJohn Marino
253e0b8e63eSJohn Marino return (0);
254e0b8e63eSJohn Marino }
255e0b8e63eSJohn Marino
256e0b8e63eSJohn Marino /*
257e0b8e63eSJohn Marino * ex_run_file --
258e0b8e63eSJohn Marino * Set up a file of ex commands to run.
259e0b8e63eSJohn Marino */
260e0b8e63eSJohn Marino static int
ex_run_file(SCR * sp,char * name)261e0b8e63eSJohn Marino ex_run_file(SCR *sp, char *name)
262e0b8e63eSJohn Marino {
263e0b8e63eSJohn Marino EXCMD cmd;
264e0b8e63eSJohn Marino CHAR_T *wp;
265e0b8e63eSJohn Marino size_t wlen;
266e0b8e63eSJohn Marino
267e0b8e63eSJohn Marino ex_cinit(sp, &cmd, C_SOURCE, 0, OOBLNO, OOBLNO, 0);
268e0b8e63eSJohn Marino CHAR2INT(sp, name, strlen(name)+1, wp, wlen);
269e0b8e63eSJohn Marino argv_exp0(sp, &cmd, wp, wlen - 1);
270e0b8e63eSJohn Marino return (ex_source(sp, &cmd));
271e0b8e63eSJohn Marino }
272e0b8e63eSJohn Marino
273e0b8e63eSJohn Marino /*
274e0b8e63eSJohn Marino * ex_run_str --
275e0b8e63eSJohn Marino * Set up a string of ex commands to run.
276e0b8e63eSJohn Marino *
277e0b8e63eSJohn Marino * PUBLIC: int ex_run_str(SCR *, char *, CHAR_T *, size_t, int, int);
278e0b8e63eSJohn Marino */
279e0b8e63eSJohn Marino int
ex_run_str(SCR * sp,char * name,CHAR_T * str,size_t len,int ex_flags,int nocopy)280e0b8e63eSJohn Marino ex_run_str(SCR *sp, char *name, CHAR_T *str, size_t len, int ex_flags, int nocopy)
281e0b8e63eSJohn Marino {
282e0b8e63eSJohn Marino GS *gp;
283e0b8e63eSJohn Marino EXCMD *ecp;
284e0b8e63eSJohn Marino
285e0b8e63eSJohn Marino gp = sp->gp;
286e0b8e63eSJohn Marino if (EXCMD_RUNNING(gp)) {
287*b1ac2ebbSDaniel Fojt CALLOC_RET(sp, ecp, 1, sizeof(EXCMD));
288e0b8e63eSJohn Marino SLIST_INSERT_HEAD(gp->ecq, ecp, q);
289e0b8e63eSJohn Marino } else
290e0b8e63eSJohn Marino ecp = &gp->excmd;
291e0b8e63eSJohn Marino
292e0b8e63eSJohn Marino F_INIT(ecp,
293e0b8e63eSJohn Marino ex_flags ? E_BLIGNORE | E_NOAUTO | E_NOPRDEF | E_VLITONLY : 0);
294e0b8e63eSJohn Marino
295e0b8e63eSJohn Marino if (nocopy)
296e0b8e63eSJohn Marino ecp->cp = str;
297e0b8e63eSJohn Marino else
298e0b8e63eSJohn Marino if ((ecp->cp = v_wstrdup(sp, str, len)) == NULL)
299e0b8e63eSJohn Marino return (1);
300e0b8e63eSJohn Marino ecp->clen = len;
301e0b8e63eSJohn Marino
302e0b8e63eSJohn Marino if (name == NULL)
303e0b8e63eSJohn Marino ecp->if_name = NULL;
304e0b8e63eSJohn Marino else {
305e0b8e63eSJohn Marino if ((ecp->if_name = v_strdup(sp, name, strlen(name))) == NULL)
306e0b8e63eSJohn Marino return (1);
307e0b8e63eSJohn Marino ecp->if_lno = 1;
308e0b8e63eSJohn Marino F_SET(ecp, E_NAMEDISCARD);
309e0b8e63eSJohn Marino }
310e0b8e63eSJohn Marino
311e0b8e63eSJohn Marino return (0);
312e0b8e63eSJohn Marino }
313e0b8e63eSJohn Marino
314e0b8e63eSJohn Marino /*
315e0b8e63eSJohn Marino * exrc_isok --
316e0b8e63eSJohn Marino * Check a .exrc file for source-ability.
317e0b8e63eSJohn Marino *
318e0b8e63eSJohn Marino * !!!
319e0b8e63eSJohn Marino * Historically, vi read the $HOME and local .exrc files if they were owned
320e0b8e63eSJohn Marino * by the user's real ID, or the "sourceany" option was set, regardless of
321e0b8e63eSJohn Marino * any other considerations. We no longer support the sourceany option as
322e0b8e63eSJohn Marino * it's a security problem of mammoth proportions. We require the system
323e0b8e63eSJohn Marino * .exrc file to be owned by root, the $HOME .exrc file to be owned by the
324e0b8e63eSJohn Marino * user's effective ID (or that the user's effective ID be root) and the
325e0b8e63eSJohn Marino * local .exrc files to be owned by the user's effective ID. In all cases,
326e0b8e63eSJohn Marino * the file cannot be writeable by anyone other than its owner.
327e0b8e63eSJohn Marino *
328e0b8e63eSJohn Marino * In O'Reilly ("Learning the VI Editor", Fifth Ed., May 1992, page 106),
329e0b8e63eSJohn Marino * it notes that System V release 3.2 and later has an option "[no]exrc".
330e0b8e63eSJohn Marino * The behavior is that local .exrc files are read only if the exrc option
331e0b8e63eSJohn Marino * is set. The default for the exrc option was off, so, by default, local
332e0b8e63eSJohn Marino * .exrc files were not read. The problem this was intended to solve was
333e0b8e63eSJohn Marino * that System V permitted users to give away files, so there's no possible
334e0b8e63eSJohn Marino * ownership or writeability test to ensure that the file is safe.
335e0b8e63eSJohn Marino *
336e0b8e63eSJohn Marino * POSIX 1003.2-1992 standardized exrc as an option. It required the exrc
337e0b8e63eSJohn Marino * option to be off by default, thus local .exrc files are not to be read
338e0b8e63eSJohn Marino * by default. The Rationale noted (incorrectly) that this was a change
339e0b8e63eSJohn Marino * to historic practice, but correctly noted that a default of off improves
340e0b8e63eSJohn Marino * system security. POSIX also required that vi check the effective user
341e0b8e63eSJohn Marino * ID instead of the real user ID, which is why we've switched from historic
342e0b8e63eSJohn Marino * practice.
343e0b8e63eSJohn Marino *
344e0b8e63eSJohn Marino * We initialize the exrc variable to off. If it's turned on by the system
345e0b8e63eSJohn Marino * or $HOME .exrc files, and the local .exrc file passes the ownership and
346e0b8e63eSJohn Marino * writeability tests, then we read it. This breaks historic 4BSD practice,
347e0b8e63eSJohn Marino * but it gives us a measure of security on systems where users can give away
348e0b8e63eSJohn Marino * files.
349e0b8e63eSJohn Marino */
350e0b8e63eSJohn Marino static enum rc
exrc_isok(SCR * sp,struct stat * sbp,char * path,int rootown,int rootid)351e0b8e63eSJohn Marino exrc_isok(SCR *sp, struct stat *sbp, char *path, int rootown, int rootid)
352e0b8e63eSJohn Marino {
353e0b8e63eSJohn Marino enum { ROOTOWN, OWN, WRITER } etype;
354e0b8e63eSJohn Marino uid_t euid;
355e0b8e63eSJohn Marino int nf1, nf2;
356e0b8e63eSJohn Marino char *a, *b, *buf;
357e0b8e63eSJohn Marino
358e0b8e63eSJohn Marino /* Check for the file's existence. */
359e0b8e63eSJohn Marino if (stat(path, sbp))
360e0b8e63eSJohn Marino return (NOEXIST);
361e0b8e63eSJohn Marino
362e0b8e63eSJohn Marino /* Check ownership permissions. */
363e0b8e63eSJohn Marino euid = geteuid();
364e0b8e63eSJohn Marino if (!(rootown && sbp->st_uid == 0) &&
365e0b8e63eSJohn Marino !(rootid && euid == 0) && sbp->st_uid != euid) {
366e0b8e63eSJohn Marino etype = rootown ? ROOTOWN : OWN;
367e0b8e63eSJohn Marino goto denied;
368e0b8e63eSJohn Marino }
369e0b8e63eSJohn Marino
370e0b8e63eSJohn Marino /* Check writeability. */
371e0b8e63eSJohn Marino if (sbp->st_mode & (S_IWGRP | S_IWOTH)) {
372e0b8e63eSJohn Marino etype = WRITER;
373e0b8e63eSJohn Marino goto denied;
374e0b8e63eSJohn Marino }
375e0b8e63eSJohn Marino return (RCOK);
376e0b8e63eSJohn Marino
377e0b8e63eSJohn Marino denied: a = msg_print(sp, path, &nf1);
378e0b8e63eSJohn Marino if (strchr(path, '/') == NULL && (buf = getcwd(NULL, 0)) != NULL) {
379e0b8e63eSJohn Marino char *p;
380e0b8e63eSJohn Marino
381e0b8e63eSJohn Marino b = msg_print(sp, buf, &nf2);
382e0b8e63eSJohn Marino if ((p = join(b, a)) == NULL) {
383e0b8e63eSJohn Marino msgq(sp, M_SYSERR, NULL);
384e0b8e63eSJohn Marino goto err;
385e0b8e63eSJohn Marino }
386e0b8e63eSJohn Marino switch (etype) {
387e0b8e63eSJohn Marino case ROOTOWN:
388e0b8e63eSJohn Marino msgq(sp, M_ERR,
389e0b8e63eSJohn Marino "128|%s: not sourced: not owned by you or root", p);
390e0b8e63eSJohn Marino break;
391e0b8e63eSJohn Marino case OWN:
392e0b8e63eSJohn Marino msgq(sp, M_ERR,
393e0b8e63eSJohn Marino "129|%s: not sourced: not owned by you", p);
394e0b8e63eSJohn Marino break;
395e0b8e63eSJohn Marino case WRITER:
396e0b8e63eSJohn Marino msgq(sp, M_ERR,
397e0b8e63eSJohn Marino "130|%s: not sourced: writeable by a user other than the owner", p);
398e0b8e63eSJohn Marino break;
399e0b8e63eSJohn Marino }
400e0b8e63eSJohn Marino free(p);
401e0b8e63eSJohn Marino err: free(buf);
402e0b8e63eSJohn Marino if (nf2)
403e0b8e63eSJohn Marino FREE_SPACE(sp, b, 0);
404e0b8e63eSJohn Marino } else
405e0b8e63eSJohn Marino switch (etype) {
406e0b8e63eSJohn Marino case ROOTOWN:
407e0b8e63eSJohn Marino msgq(sp, M_ERR,
408e0b8e63eSJohn Marino "128|%s: not sourced: not owned by you or root", a);
409e0b8e63eSJohn Marino break;
410e0b8e63eSJohn Marino case OWN:
411e0b8e63eSJohn Marino msgq(sp, M_ERR,
412e0b8e63eSJohn Marino "129|%s: not sourced: not owned by you", a);
413e0b8e63eSJohn Marino break;
414e0b8e63eSJohn Marino case WRITER:
415e0b8e63eSJohn Marino msgq(sp, M_ERR,
416e0b8e63eSJohn Marino "130|%s: not sourced: writeable by a user other than the owner", a);
417e0b8e63eSJohn Marino break;
418e0b8e63eSJohn Marino }
419e0b8e63eSJohn Marino
420e0b8e63eSJohn Marino if (nf1)
421e0b8e63eSJohn Marino FREE_SPACE(sp, a, 0);
422e0b8e63eSJohn Marino return (NOPERM);
423e0b8e63eSJohn Marino }
424