xref: /titanic_50/usr/src/cmd/bnu/uuglist.c (revision bdfc6d18da790deeec2e0eb09c625902defe2498)
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 /*	Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T	*/
23 /*	  All Rights Reserved  	*/
24 
25 
26 #ident	"%Z%%M%	%I%	%E% SMI"	/* from SVR4 bnu:uuglist.c 1.6 */
27 
28 #include	"uucp.h"
29 
30 #define MAXLENGTH 256
31 #define C_MAX	  512
32 
33 static void insert();
34 void rproc(), uproc();
35 
36 static char  Nnament[MAXLENGTH][NAMESIZE];
37 static char *Nptr[MAXLENGTH];
38 static short Nnames = 0;
39 
40 main(argc, argv)
41 int argc;
42 char **argv;
43 {
44 	int c, i, uopt = 0;
45 	char prev[2 * NAMESIZE];
46 
47 	if (eaccess(GRADES, 04) == -1) {
48 		(void) fprintf(stderr, "No administrator defined service grades available on this machine, use single letter/number only\n");
49 		exit(0);
50 	}
51 
52 	while ((c = getopt(argc, argv, "x:u")) != EOF)
53 		switch(c) {
54 		case 'u':
55 			uopt++;
56 			break;
57 		case 'x':
58 			Debug = atoi(optarg);
59 			if (Debug < 0)
60 				Debug = 1;
61 			break;
62 		default:
63 			(void) fprintf(stderr, "usage: uuglist [-u] [-xLEVEL]\n");
64 			exit(-1);
65 		}
66 
67 	if (uopt) {
68 		Uid = getuid();
69 
70 		if (Uid == 0)
71 			(void) setuid(UUCPUID);
72 
73 		(void) guinfo(Uid, User);
74 
75 		uproc();
76 	} else
77 		rproc();
78 
79 	for (i = 0; i < Nnames; i++) {
80 
81 		if (EQUALS(Nptr[i], prev))
82 			continue;
83 
84 		puts(Nptr[i]);
85 		(void) strcpy(prev, Nptr[i]);
86 	}
87 	exit(0);
88 }
89 static void
90 insert(name)
91 char *name;
92 {
93 	register i,j;
94 	register char *p;
95 
96 	DEBUG(7, "insert(%s) ", name);
97 
98 	for (i = Nnames; i > 0; i--)
99 		if (strcmp(name, Nptr[i-1]) > 0)
100 			break;
101 
102 	if (i == MAXLENGTH)
103 		return;
104 
105 	if (Nnames == MAXLENGTH)
106 		p = strcpy(Nptr[--Nnames], name);
107 	else
108 		p = strcpy(Nnament[Nnames], name);
109 
110 	for (j = Nnames; j > i; j--)
111 		Nptr[j] = Nptr[j-1];
112 
113 	DEBUG(7, "insert %s ", p);
114 	DEBUG(7, "at %d\n", i);
115 	Nptr[i] = p;
116 	Nnames++;
117 	return;
118 }
119 
120 void
121 rproc()
122 {
123 	FILE *cfd;
124 	char line[BUFSIZ];
125 	char *carray[C_MAX];
126 	int na;
127 
128 	cfd = fopen(GRADES, "r");
129 
130 	while (rdfulline(cfd, line, BUFSIZ) != 0) {
131 
132 		na = getargs(line, carray, C_MAX);
133 		insert(carray[0]);
134 	}
135 
136 	(void) fclose(cfd);
137 	return;
138 }
139 
140 void
141 uproc()
142 {
143 	FILE *cfd;
144 	char line[BUFSIZ];
145 	char *carray[C_MAX];
146 	int na;
147 
148 	cfd = fopen(GRADES, "r");
149 
150 	while (rdfulline(cfd, line, BUFSIZ) != 0) {
151 
152 		na = getargs(line, carray, C_MAX);
153 
154 		if (upermit(carray, na) != FAIL)
155 			insert(carray[0]);
156 	}
157 
158 	(void) fclose(cfd);
159 	return;
160 }
161 
162 int Dfileused = FALSE;
163 wfcommit() {}
164 void cleanup() {}
165 gnamef() {}
166 gdirf() {}
167 cklock() {}
168 
169 /*VARARGS*/
170 /*ARGSUSED*/
171 void
172 assert (s1, s2, i1, s3, i2)
173 char *s1, *s2, *s3;
174 int i1, i2;
175 { }		/* for ASSERT in gnamef.c */
176 
177 /*VARARGS*/
178 /*ARGSUSED*/
179 void
180 errent(s1, s2, i1, file, line)
181 char *s1, *s2, *file;
182 { }
183