1 /* permsfile.c: implement SunOS /etc/fbtab and Solaris /etc/logindevperm
2 functionality to set device permissions on login
4 %%% portions-copyright-cmetz-96
5 Portions of this software are Copyright 1996-1999 by Craig Metz, All Rights
6 Reserved. The Inner Net License Version 2 applies to these portions of
8 You should have received a copy of the license with this software. If
9 you didn't get a copy, you may request one from <license@inner.net>.
11 Portions of this software are Copyright 1995 by Randall Atkinson and Dan
12 McDonald, All Rights Reserved. All Rights under this copyright are assigned
13 to the U.S. Naval Research Laboratory (NRL). The NRL Copyright Notice and
14 License Agreement applies to this software.
18 Modified by cmetz for OPIE 2.31. Include unistd.h.
19 Modified by cmetz for OPIE 2.3. Check for NULL return from
20 ftpglob(), combine some expressions, fix a typo. Made file
21 selection a bit more generic.
22 Modified by cmetz for OPIE 2.2. Use FUNCTION declaration et al.
23 Add opie.h. Ifdef around a header.
24 Written at NRL for OPIE 2.0.
28 #ifdef HAVE_LOGIN_PERMFILE
30 #include <sys/types.h>
33 #endif /* HAVE_STRING_H */
36 #endif /* HAVE_UNISTD_H */
40 /* Line buffer size (one more than max line length) */
42 /* Maximum number of list items in a field */
45 static char buf
[BUFSIZE
], buf2
[8];
47 char **ftpglob
__P((char *));
49 VOIDRET opiefatal
FUNCTION((x
), char *x
)
57 static int getalist
FUNCTION((string
, list
), char **string AND
char **list
)
62 while (*s
&& (*s
!= '\n') && (*s
!= ' ') && (*s
!= '\t'))
63 if ((*s
== ':') || (*s
== ',')) {
72 if ((int) (s
) - (int) (*string
)) {
81 static VOIDRET doaline
FUNCTION((line
, name
, ttyn
, uid
, gid
), char *line AND
char *name AND
char *ttyn AND uid_t uid AND gid_t gid
)
86 char *listbuf
[LISTSIZE
], **globlist
;
88 if (ptr
= strchr(buf
, '#'))
92 for (ptr
= buf
; *ptr
&& ((*ptr
== ' ') || (*ptr
== '\t'));
98 /* (Optional) Field 1: user name(s) */
99 if ((*ptr
!= '/') && (*ptr
!= '~')) {
100 llen
= getalist(&ptr
, listbuf
);
101 for (applies
= i
= 0; (i
< llen
) && !applies
; i
++)
102 if (!strcmp(listbuf
[i
], name
))
104 while (*ptr
&& ((*ptr
== ' ') || (*ptr
== '\t')))
106 if (!applies
|| !*ptr
)
109 /* Field 2: terminal(s) */
110 llen
= getalist(&ptr
, listbuf
);
111 for (applies
= i
= 0; (i
< llen
) && !applies
; i
++)
112 if (!strcmp(listbuf
[i
], ttyn
))
115 while (*ptr
&& ((*ptr
== ' ') || (*ptr
== '\t')))
118 if (!applies
|| !*ptr
)
122 for (applies
= 0; *ptr
&& (*ptr
>= '0') && (*ptr
<= '7');
123 applies
= (applies
<< 3) | (*(ptr
++) - '0'));
125 while (*ptr
&& ((*ptr
== ' ') || (*ptr
== '\t')))
131 /* Field 4: devices (the fun part...) */
132 llen
= getalist(&ptr
, listbuf
);
133 for (i
= 0; i
< llen
; i
++) {
134 if (globlist
= ftpglob(listbuf
[i
]))
137 syslog(LOG_DEBUG
, "setting %s to %d/%d %o", *globlist
, uid
, gid
, applies
);
139 if ((chown(*globlist
, uid
, gid
) < 0) && (errno
!= ENOENT
))
141 if ((chmod(*(globlist
++), applies
) < 0) && (errno
!= ENOENT
))
147 VOIDRET permsfile
FUNCTION((name
, ttyn
, uid
, gid
), char *name AND
char *ttyn AND uid_t uid AND gid_t gid
)
151 if (!(fh
= fopen(HAVE_LOGIN_PERMFILE
, "r"))) {
152 syslog(LOG_ERR
, "Can't open %s!", HAVE_LOGIN_PERMFILE
);
153 fprintf(stderr
, "Warning: Can't set device permissions.\n");
159 if (fgets(buf
, BUFSIZE
, fh
) == NULL
)
163 doaline(buf
, name
, ttyn
, uid
, gid
);
167 #endif /* HAVE_LOGIN_PERMFILE */