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