1 /* $NetBSD: perm.c,v 1.2 2000/10/04 19:24:59 mjl Exp $ */
4 * perm.c - check user permission for at(1)
5 * Copyright (C) 1994 Thomas Koenig
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. The name of the author(s) may not be used to endorse or promote
13 * products derived from this software without specific prior written
16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR
17 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
18 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
19 * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT,
20 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
21 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
22 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
23 * THEORY OF LIABILITY, WETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
25 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 #include <sys/types.h>
44 #include "pathnames.h"
48 /* File scope variables */
52 static char rcsid
[] = "$OpenBSD: perm.c,v 1.1 1997/03/01 23:40:12 millert Exp $";
54 __RCSID("$NetBSD: perm.c,v 1.2 2000/10/04 19:24:59 mjl Exp $");
61 check_for_user(FILE *fp
, const char *name
)
68 if ((buffer
= malloc(len
+ 2)) == NULL
)
69 panic("Insufficient virtual memory");
71 while (fgets(buffer
, (int)len
+ 2, fp
) != NULL
) {
72 if (strncmp(name
, buffer
, len
) == 0 && buffer
[len
] == '\n') {
82 /* Global functions */
85 check_permission(void)
88 uid_t uid
= geteuid();
89 struct passwd
*pentry
;
94 if ((pentry
= getpwuid(uid
)) == NULL
) {
95 perror("Cannot access user database");
101 fp
= fopen(_PATH_AT_ALLOW
, "r");
106 return check_for_user(fp
, pentry
->pw_name
);
110 fp
= fopen(_PATH_AT_DENY
, "r");
115 return !check_for_user(fp
, pentry
->pw_name
);