xref: /titanic_50/usr/src/cmd/bnu/uuglist.c (revision f38cb554a534c6df738be3f4d23327e69888e634)
1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License, Version 1.0 only
6  * (the "License").  You may not use this file except in compliance
7  * with the License.
8  *
9  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10  * or http://www.opensolaris.org/os/licensing.
11  * See the License for the specific language governing permissions
12  * and limitations under the License.
13  *
14  * When distributing Covered Code, include this CDDL HEADER in each
15  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16  * If applicable, add the following below this CDDL HEADER, with the
17  * fields enclosed by brackets "[]" replaced with your own identifying
18  * information: Portions Copyright [yyyy] [name of copyright owner]
19  *
20  * CDDL HEADER END
21  */
22 /*
23  * Copyright 2005 Sun Microsystems, Inc.  All rights reserved.
24  * Use is subject to license terms.
25  */
26 
27 /*	Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T	*/
28 /*	  All Rights Reserved  	*/
29 
30 
31 #pragma ident	"%Z%%M%	%I%	%E% SMI"
32 
33 #include	"uucp.h"
34 
35 #define MAXLENGTH 256
36 #define C_MAX	  512
37 
38 static void insert();
39 void rproc(), uproc();
40 
41 static char  Nnament[MAXLENGTH][NAMESIZE];
42 static char *Nptr[MAXLENGTH];
43 static short Nnames = 0;
44 
45 int
46 main(argc, argv)
47 int argc;
48 char **argv;
49 {
50 	int c, i, uopt = 0;
51 	char prev[2 * NAMESIZE];
52 
53 	if (eaccess(GRADES, 04) == -1) {
54 		(void) fprintf(stderr, "No administrator defined service grades available on this machine, use single letter/number only\n");
55 		exit(0);
56 	}
57 
58 	while ((c = getopt(argc, argv, "x:u")) != EOF)
59 		switch(c) {
60 		case 'u':
61 			uopt++;
62 			break;
63 		case 'x':
64 			Debug = atoi(optarg);
65 			if (Debug < 0)
66 				Debug = 1;
67 			break;
68 		default:
69 			(void) fprintf(stderr, "usage: uuglist [-u] [-xLEVEL]\n");
70 			exit(-1);
71 		}
72 
73 	if (uopt) {
74 		Uid = getuid();
75 
76 		if (Uid == 0)
77 			(void) setuid(UUCPUID);
78 
79 		(void) guinfo(Uid, User);
80 
81 		uproc();
82 	} else
83 		rproc();
84 
85 	for (i = 0; i < Nnames; i++) {
86 
87 		if (EQUALS(Nptr[i], prev))
88 			continue;
89 
90 		puts(Nptr[i]);
91 		(void) strcpy(prev, Nptr[i]);
92 	}
93 	return (0);
94 }
95 static void
96 insert(name)
97 char *name;
98 {
99 	int i,j;
100 	char *p;
101 
102 	DEBUG(7, "insert(%s) ", name);
103 
104 	for (i = Nnames; i > 0; i--)
105 		if (strcmp(name, Nptr[i-1]) > 0)
106 			break;
107 
108 	if (i == MAXLENGTH)
109 		return;
110 
111 	if (Nnames == MAXLENGTH)
112 		p = strcpy(Nptr[--Nnames], name);
113 	else
114 		p = strcpy(Nnament[Nnames], name);
115 
116 	for (j = Nnames; j > i; j--)
117 		Nptr[j] = Nptr[j-1];
118 
119 	DEBUG(7, "insert %s ", p);
120 	DEBUG(7, "at %d\n", i);
121 	Nptr[i] = p;
122 	Nnames++;
123 	return;
124 }
125 
126 void
127 rproc()
128 {
129 	FILE *cfd;
130 	char line[BUFSIZ];
131 	char *carray[C_MAX];
132 	int na;
133 
134 	cfd = fopen(GRADES, "r");
135 
136 	while (rdfulline(cfd, line, BUFSIZ) != 0) {
137 
138 		na = getargs(line, carray, C_MAX);
139 		insert(carray[0]);
140 	}
141 
142 	(void) fclose(cfd);
143 	return;
144 }
145 
146 void
147 uproc()
148 {
149 	FILE *cfd;
150 	char line[BUFSIZ];
151 	char *carray[C_MAX];
152 	int na;
153 
154 	cfd = fopen(GRADES, "r");
155 
156 	while (rdfulline(cfd, line, BUFSIZ) != 0) {
157 
158 		na = getargs(line, carray, C_MAX);
159 
160 		if (upermit(carray, na) != FAIL)
161 			insert(carray[0]);
162 	}
163 
164 	(void) fclose(cfd);
165 	return;
166 }
167 
168 int Dfileused = FALSE;
169 void wfcommit() {}
170 void cleanup() {}
171 int gnamef() { return (0); }
172 int gdirf() { return (0); }
173 int cklock() { return (0); }
174 
175 /*VARARGS*/
176 /*ARGSUSED*/
177 void
178 assert (s1, s2, i1, s3, i2)
179 char *s1, *s2, *s3;
180 int i1, i2;
181 { }		/* for ASSERT in gnamef.c */
182 
183 /*VARARGS*/
184 /*ARGSUSED*/
185 void
186 errent(s1, s2, i1, file, line)
187 char *s1, *s2, *file;
188 { }
189