]>
git.saurik.com Git - apple/system_cmds.git/blob - at.tproj/perm.c
a2df82096cbc567943df5436816bc95f4121d0fd
2 * Copyright (c) 1999 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_HEADER_START@
6 * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
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
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.
23 * @APPLE_LICENSE_HEADER_END@
26 * perm.c - check user permission for at(1)
27 * Copyright (C) 1994 Thomas Koenig
29 * Redistribution and use in source and binary forms, with or without
30 * modification, are permitted provided that the following conditions
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
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.
52 #include <sys/types.h>
65 #include "pathnames.h"
71 /* Structures and unions */
73 /* File scope variables */
75 static char rcsid
[] = "$Id: perm.c,v 1.1.1.2 2000/01/11 02:10:05 wsanchez Exp $";
77 /* Function declarations */
79 static int check_for_user(FILE *fp
,const char *name
);
83 static int check_for_user(FILE *fp
,const char *name
)
90 if ((buffer
= malloc(sizeof (char) * (len
+2))) == NULL
) {
91 fprintf(stderr
, "malloc error!");
95 while(fgets(buffer
, len
+2, fp
) != NULL
)
97 if ((strncmp(name
, buffer
, len
) == 0) &&
98 (buffer
[len
] == '\n'))
108 /* Global functions */
109 int check_permission()
112 uid_t uid
= geteuid();
113 struct passwd
*pentry
;
118 if ((pentry
= getpwuid(uid
)) == NULL
)
120 perror("Cannot access user database");
126 fp
=fopen(_PATH_AT
"at.allow","r");
132 return check_for_user(fp
, pentry
->pw_name
);
139 fp
=fopen(_PATH_AT
"at.deny", "r");
145 return !check_for_user(fp
, pentry
->pw_name
);