OSDN Git Service

Fix no pic
[uclinux-h8/uClinux-dist.git] / user / at / perm.c
1 /* 
2  *  perm.c - check user permission for at(1)
3  *  Copyright (C) 1994  Thomas Koenig
4  *
5  *  This program is free software; you can redistribute it and/or modify
6  *  it under the terms of the GNU General Public License as published by
7  *  the Free Software Foundation; either version 2 of the License, or
8  *  (at your option) any later version.
9  *
10  *  This program is distributed in the hope that it will be useful,
11  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  *  GNU General Public License for more details.
14  *
15  *  You should have received a copy of the GNU General Public License
16  *  along with this program; if not, write to the Free Software
17  *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18  */
19
20 #ifdef HAVE_CONFIG_H
21 #include "config.h"
22 #endif
23
24 /* System Headers */
25
26 #include <sys/types.h>
27
28 #ifdef HAVE_ERRNO_H
29 #include <errno.h>
30 #endif
31
32 #include <pwd.h>
33 #include <stddef.h>
34 #include <stdio.h>
35 #include <stdlib.h>
36 #include <string.h>
37 #include <unistd.h>
38
39 /* Local headers */
40
41 #include "privs.h"
42 #include "at.h"
43
44 /* Macros */
45
46 #define MAXUSERID 10
47
48 /* Structures and unions */
49
50
51 /* File scope variables */
52
53 static char rcsid[] = "$Id: perm.c,v 1.4 1997/03/12 19:36:06 ig25 Exp $";
54
55 /* Function declarations */
56
57 static int check_for_user(FILE * fp, const char *name);
58
59 /* Local functions */
60
61 static int 
62 check_for_user(FILE * fp, const char *name)
63 {
64     char *buffer;
65     size_t len;
66     int found = 0;
67
68     len = strlen(name);
69     buffer = mymalloc(len + 2);
70
71     while (fgets(buffer, len + 2, fp) != NULL) {
72         if ((strncmp(name, buffer, len) == 0) &&
73             (buffer[len] == '\n')) {
74             found = 1;
75             break;
76         }
77     }
78     fclose(fp);
79     free(buffer);
80     return found;
81 }
82 /* Global functions */
83 int 
84 check_permission()
85 {
86     FILE *fp;
87     uid_t uid = geteuid();
88     struct passwd *pentry;
89
90     if (uid == 0)
91         return 1;
92
93     if ((pentry = getpwuid(uid)) == NULL) {
94         perror("Cannot access user database");
95         exit(EXIT_FAILURE);
96     }
97     PRIV_START
98
99         fp = fopen(ETCDIR "/at.allow", "r");
100
101     PRIV_END
102
103     if (fp != NULL) {
104         return check_for_user(fp, pentry->pw_name);
105     } else {
106
107         PRIV_START
108
109             fp = fopen(ETCDIR "/at.deny", "r");
110
111         PRIV_END
112
113         if (fp != NULL) {
114             return !check_for_user(fp, pentry->pw_name);
115         }
116         perror("at.deny");
117     }
118     return 0;
119 }