]>
Commit | Line | Data |
---|---|---|
83f6dbe8 A |
1 | /* |
2 | * Copyright (c) 1999 Apple Computer, Inc. All rights reserved. | |
3 | * | |
4 | * @APPLE_LICENSE_HEADER_START@ | |
5 | * | |
6 | * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved. | |
7 | * | |
8 | * This file contains Original Code and/or Modifications of Original Code | |
9 | * as defined in and that are subject to the Apple Public Source License | |
10 | * Version 2.0 (the 'License'). You may not use this file except in | |
11 | * compliance with the License. Please obtain a copy of the License at | |
12 | * http://www.opensource.apple.com/apsl/ and read it before using this | |
13 | * file. | |
14 | * | |
15 | * The Original Code and all software distributed under the License are | |
16 | * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER | |
17 | * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, | |
18 | * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, | |
19 | * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. | |
20 | * Please see the License for the specific language governing rights and | |
21 | * limitations under the License. | |
22 | * | |
23 | * @APPLE_LICENSE_HEADER_END@ | |
24 | */ | |
1815bff5 A |
25 | /* |
26 | * perm.c - check user permission for at(1) | |
27 | * Copyright (C) 1994 Thomas Koenig | |
28 | * | |
29 | * Redistribution and use in source and binary forms, with or without | |
30 | * modification, are permitted provided that the following conditions | |
31 | * are met: | |
32 | * 1. Redistributions of source code must retain the above copyright | |
33 | * notice, this list of conditions and the following disclaimer. | |
34 | * 2. The name of the author(s) may not be used to endorse or promote | |
35 | * products derived from this software without specific prior written | |
36 | * permission. | |
37 | * | |
38 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR | |
39 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES | |
40 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. | |
41 | * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT, | |
42 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT | |
43 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | |
44 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | |
45 | * THEORY OF LIABILITY, WETHER IN CONTRACT, STRICT LIABILITY, OR TORT | |
46 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF | |
47 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |
48 | */ | |
49 | ||
50 | /* System Headers */ | |
51 | ||
52 | #include <sys/types.h> | |
53 | #include <errno.h> | |
54 | #include <pwd.h> | |
55 | #include <stddef.h> | |
56 | #include <stdio.h> | |
57 | #include <stdlib.h> | |
58 | #include <string.h> | |
59 | #include <unistd.h> | |
60 | ||
61 | /* Local headers */ | |
62 | ||
0e393d50 | 63 | #include "privs.h" |
83f6dbe8 A |
64 | #include "at.h" |
65 | #include "pathnames.h" | |
1815bff5 A |
66 | |
67 | /* Macros */ | |
68 | ||
69 | #define MAXUSERID 10 | |
70 | ||
71 | /* Structures and unions */ | |
72 | ||
83f6dbe8 A |
73 | /* File scope variables */ |
74 | ||
75 | static char rcsid[] = "$Id: perm.c,v 1.1.1.2 2000/01/11 02:10:05 wsanchez Exp $"; | |
76 | ||
1815bff5 A |
77 | /* Function declarations */ |
78 | ||
79 | static int check_for_user(FILE *fp,const char *name); | |
80 | ||
81 | /* Local functions */ | |
82 | ||
83 | static int check_for_user(FILE *fp,const char *name) | |
84 | { | |
85 | char *buffer; | |
86 | size_t len; | |
87 | int found = 0; | |
88 | ||
89 | len = strlen(name); | |
83f6dbe8 A |
90 | if ((buffer = malloc(sizeof (char) * (len+2))) == NULL) { |
91 | fprintf(stderr, "malloc error!"); | |
92 | exit(EXIT_FAILURE); | |
93 | } | |
1815bff5 A |
94 | |
95 | while(fgets(buffer, len+2, fp) != NULL) | |
96 | { | |
97 | if ((strncmp(name, buffer, len) == 0) && | |
98 | (buffer[len] == '\n')) | |
99 | { | |
100 | found = 1; | |
101 | break; | |
102 | } | |
103 | } | |
104 | fclose(fp); | |
105 | free(buffer); | |
106 | return found; | |
107 | } | |
108 | /* Global functions */ | |
83f6dbe8 | 109 | int check_permission() |
1815bff5 A |
110 | { |
111 | FILE *fp; | |
112 | uid_t uid = geteuid(); | |
113 | struct passwd *pentry; | |
114 | ||
115 | if (uid==0) | |
116 | return 1; | |
117 | ||
118 | if ((pentry = getpwuid(uid)) == NULL) | |
83f6dbe8 A |
119 | { |
120 | perror("Cannot access user database"); | |
121 | exit(EXIT_FAILURE); | |
122 | } | |
1815bff5 A |
123 | |
124 | PRIV_START | |
125 | ||
83f6dbe8 | 126 | fp=fopen(_PATH_AT "at.allow","r"); |
1815bff5 A |
127 | |
128 | PRIV_END | |
129 | ||
130 | if (fp != NULL) | |
131 | { | |
132 | return check_for_user(fp, pentry->pw_name); | |
133 | } | |
83f6dbe8 | 134 | else |
1815bff5 A |
135 | { |
136 | ||
137 | PRIV_START | |
138 | ||
83f6dbe8 | 139 | fp=fopen(_PATH_AT "at.deny", "r"); |
1815bff5 A |
140 | |
141 | PRIV_END | |
142 | ||
143 | if (fp != NULL) | |
144 | { | |
145 | return !check_for_user(fp, pentry->pw_name); | |
146 | } | |
83f6dbe8 | 147 | perror("at.deny"); |
1815bff5 A |
148 | } |
149 | return 0; | |
150 | } |