xref: /titanic_51/usr/src/cmd/projects/projects.c (revision 7c478bd95313f5f23a4c958a745db2134aa03244)
1*7c478bd9Sstevel@tonic-gate /*
2*7c478bd9Sstevel@tonic-gate  * CDDL HEADER START
3*7c478bd9Sstevel@tonic-gate  *
4*7c478bd9Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
5*7c478bd9Sstevel@tonic-gate  * Common Development and Distribution License, Version 1.0 only
6*7c478bd9Sstevel@tonic-gate  * (the "License").  You may not use this file except in compliance
7*7c478bd9Sstevel@tonic-gate  * with the License.
8*7c478bd9Sstevel@tonic-gate  *
9*7c478bd9Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10*7c478bd9Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
11*7c478bd9Sstevel@tonic-gate  * See the License for the specific language governing permissions
12*7c478bd9Sstevel@tonic-gate  * and limitations under the License.
13*7c478bd9Sstevel@tonic-gate  *
14*7c478bd9Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
15*7c478bd9Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16*7c478bd9Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
17*7c478bd9Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
18*7c478bd9Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
19*7c478bd9Sstevel@tonic-gate  *
20*7c478bd9Sstevel@tonic-gate  * CDDL HEADER END
21*7c478bd9Sstevel@tonic-gate  */
22*7c478bd9Sstevel@tonic-gate /*
23*7c478bd9Sstevel@tonic-gate  * Copyright 2004 Sun Microsystems, Inc.  All rights reserved.
24*7c478bd9Sstevel@tonic-gate  * Use is subject to license terms.
25*7c478bd9Sstevel@tonic-gate  */
26*7c478bd9Sstevel@tonic-gate 
27*7c478bd9Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
28*7c478bd9Sstevel@tonic-gate 
29*7c478bd9Sstevel@tonic-gate #include <sys/types.h>
30*7c478bd9Sstevel@tonic-gate #include <sys/termio.h>
31*7c478bd9Sstevel@tonic-gate #include <unistd.h>
32*7c478bd9Sstevel@tonic-gate #include <stdlib.h>
33*7c478bd9Sstevel@tonic-gate #include <stdio.h>
34*7c478bd9Sstevel@tonic-gate #include <pwd.h>
35*7c478bd9Sstevel@tonic-gate #include <string.h>
36*7c478bd9Sstevel@tonic-gate #include <errno.h>
37*7c478bd9Sstevel@tonic-gate #include <project.h>
38*7c478bd9Sstevel@tonic-gate #include <locale.h>
39*7c478bd9Sstevel@tonic-gate #include <libintl.h>
40*7c478bd9Sstevel@tonic-gate 
41*7c478bd9Sstevel@tonic-gate struct projlist {
42*7c478bd9Sstevel@tonic-gate 	void *pl_next;
43*7c478bd9Sstevel@tonic-gate 	char *pl_name;
44*7c478bd9Sstevel@tonic-gate 	char *pl_comm;
45*7c478bd9Sstevel@tonic-gate };
46*7c478bd9Sstevel@tonic-gate 
47*7c478bd9Sstevel@tonic-gate static struct projlist *projects;
48*7c478bd9Sstevel@tonic-gate static char *progname;
49*7c478bd9Sstevel@tonic-gate 
50*7c478bd9Sstevel@tonic-gate static void *
51*7c478bd9Sstevel@tonic-gate safe_malloc(size_t size)
52*7c478bd9Sstevel@tonic-gate {
53*7c478bd9Sstevel@tonic-gate 	void *buf;
54*7c478bd9Sstevel@tonic-gate 
55*7c478bd9Sstevel@tonic-gate 	if ((buf = malloc(size)) == NULL) {
56*7c478bd9Sstevel@tonic-gate 		(void) fprintf(stderr, gettext("%s: not enough memory\n"),
57*7c478bd9Sstevel@tonic-gate 		    progname);
58*7c478bd9Sstevel@tonic-gate 		exit(1);
59*7c478bd9Sstevel@tonic-gate 	}
60*7c478bd9Sstevel@tonic-gate 	return (buf);
61*7c478bd9Sstevel@tonic-gate }
62*7c478bd9Sstevel@tonic-gate 
63*7c478bd9Sstevel@tonic-gate static int
64*7c478bd9Sstevel@tonic-gate find_projects(char *name, int default_only)
65*7c478bd9Sstevel@tonic-gate {
66*7c478bd9Sstevel@tonic-gate 	struct projlist *tail, *prev;
67*7c478bd9Sstevel@tonic-gate 	char *projname, *projcomm;
68*7c478bd9Sstevel@tonic-gate 	struct project proj;
69*7c478bd9Sstevel@tonic-gate 	void *buffer, *tmp;
70*7c478bd9Sstevel@tonic-gate 	int found = 0;
71*7c478bd9Sstevel@tonic-gate 
72*7c478bd9Sstevel@tonic-gate 	tmp = safe_malloc(PROJECT_BUFSZ);
73*7c478bd9Sstevel@tonic-gate 
74*7c478bd9Sstevel@tonic-gate 	if (default_only) {
75*7c478bd9Sstevel@tonic-gate 		if (getdefaultproj(name, &proj, tmp, PROJECT_BUFSZ) != NULL) {
76*7c478bd9Sstevel@tonic-gate 			projects = safe_malloc(sizeof (struct projlist));
77*7c478bd9Sstevel@tonic-gate 			projname = safe_malloc(strlen(proj.pj_name) + 1);
78*7c478bd9Sstevel@tonic-gate 			projcomm = safe_malloc(strlen(proj.pj_comment) + 1);
79*7c478bd9Sstevel@tonic-gate 			(void) strcpy(projname, proj.pj_name);
80*7c478bd9Sstevel@tonic-gate 			(void) strcpy(projcomm, proj.pj_comment);
81*7c478bd9Sstevel@tonic-gate 			projects->pl_next = NULL;
82*7c478bd9Sstevel@tonic-gate 			projects->pl_name = projname;
83*7c478bd9Sstevel@tonic-gate 			projects->pl_comm = projcomm;
84*7c478bd9Sstevel@tonic-gate 			found = 1;
85*7c478bd9Sstevel@tonic-gate 		}
86*7c478bd9Sstevel@tonic-gate 	} else {
87*7c478bd9Sstevel@tonic-gate 		buffer = safe_malloc(PROJECT_BUFSZ);
88*7c478bd9Sstevel@tonic-gate 		setprojent();
89*7c478bd9Sstevel@tonic-gate 		while (getprojent(&proj, tmp, PROJECT_BUFSZ) != NULL) {
90*7c478bd9Sstevel@tonic-gate 			if (inproj(name, proj.pj_name, buffer, PROJECT_BUFSZ)) {
91*7c478bd9Sstevel@tonic-gate 				tail = safe_malloc(sizeof (struct projlist));
92*7c478bd9Sstevel@tonic-gate 				projname =
93*7c478bd9Sstevel@tonic-gate 				    safe_malloc(strlen(proj.pj_name) + 1);
94*7c478bd9Sstevel@tonic-gate 				projcomm =
95*7c478bd9Sstevel@tonic-gate 				    safe_malloc(strlen(proj.pj_comment) + 1);
96*7c478bd9Sstevel@tonic-gate 				(void) strcpy(projname, proj.pj_name);
97*7c478bd9Sstevel@tonic-gate 				(void) strcpy(projcomm, proj.pj_comment);
98*7c478bd9Sstevel@tonic-gate 				tail->pl_next = NULL;
99*7c478bd9Sstevel@tonic-gate 				tail->pl_name = projname;
100*7c478bd9Sstevel@tonic-gate 				tail->pl_comm = projcomm;
101*7c478bd9Sstevel@tonic-gate 				if (!projects) {
102*7c478bd9Sstevel@tonic-gate 					projects = tail;
103*7c478bd9Sstevel@tonic-gate 					prev = projects;
104*7c478bd9Sstevel@tonic-gate 				} else {
105*7c478bd9Sstevel@tonic-gate 					prev->pl_next = tail;
106*7c478bd9Sstevel@tonic-gate 					prev = tail;
107*7c478bd9Sstevel@tonic-gate 				}
108*7c478bd9Sstevel@tonic-gate 				found = 1;
109*7c478bd9Sstevel@tonic-gate 			}
110*7c478bd9Sstevel@tonic-gate 		}
111*7c478bd9Sstevel@tonic-gate 		endprojent();
112*7c478bd9Sstevel@tonic-gate 		free(buffer);
113*7c478bd9Sstevel@tonic-gate 	}
114*7c478bd9Sstevel@tonic-gate 	free(tmp);
115*7c478bd9Sstevel@tonic-gate 	return (found);
116*7c478bd9Sstevel@tonic-gate }
117*7c478bd9Sstevel@tonic-gate 
118*7c478bd9Sstevel@tonic-gate /*
119*7c478bd9Sstevel@tonic-gate  * Get the maximum length of the project name string.
120*7c478bd9Sstevel@tonic-gate  */
121*7c478bd9Sstevel@tonic-gate static int
122*7c478bd9Sstevel@tonic-gate max_projname()
123*7c478bd9Sstevel@tonic-gate {
124*7c478bd9Sstevel@tonic-gate 	struct projlist *pl;
125*7c478bd9Sstevel@tonic-gate 	int max = 0;
126*7c478bd9Sstevel@tonic-gate 	int len;
127*7c478bd9Sstevel@tonic-gate 
128*7c478bd9Sstevel@tonic-gate 	for (pl = projects; pl; pl = pl->pl_next)
129*7c478bd9Sstevel@tonic-gate 		if ((len = strlen(pl->pl_name)) > max)
130*7c478bd9Sstevel@tonic-gate 			max = len;
131*7c478bd9Sstevel@tonic-gate 	return (max);
132*7c478bd9Sstevel@tonic-gate }
133*7c478bd9Sstevel@tonic-gate 
134*7c478bd9Sstevel@tonic-gate static int
135*7c478bd9Sstevel@tonic-gate print_projects(char *name, int verbose, int default_only)
136*7c478bd9Sstevel@tonic-gate {
137*7c478bd9Sstevel@tonic-gate 	struct projlist *pl, *next;
138*7c478bd9Sstevel@tonic-gate 	struct winsize ws;
139*7c478bd9Sstevel@tonic-gate 	int length = 0;
140*7c478bd9Sstevel@tonic-gate 	int smart = isatty(STDOUT_FILENO);
141*7c478bd9Sstevel@tonic-gate 	int columns;
142*7c478bd9Sstevel@tonic-gate 
143*7c478bd9Sstevel@tonic-gate 	if (!find_projects(name, default_only)) {
144*7c478bd9Sstevel@tonic-gate 		if (default_only)
145*7c478bd9Sstevel@tonic-gate 			(void) fprintf(stderr,
146*7c478bd9Sstevel@tonic-gate 			    gettext("%s: no default project for user %s\n"),
147*7c478bd9Sstevel@tonic-gate 			    progname, name);
148*7c478bd9Sstevel@tonic-gate 		else
149*7c478bd9Sstevel@tonic-gate 			(void) fprintf(stderr,
150*7c478bd9Sstevel@tonic-gate 			    gettext("%s: no projects for user %s\n"),
151*7c478bd9Sstevel@tonic-gate 			    progname, name);
152*7c478bd9Sstevel@tonic-gate 		return (1);
153*7c478bd9Sstevel@tonic-gate 	}
154*7c478bd9Sstevel@tonic-gate 
155*7c478bd9Sstevel@tonic-gate 	if (verbose)
156*7c478bd9Sstevel@tonic-gate 		length = max_projname();
157*7c478bd9Sstevel@tonic-gate 
158*7c478bd9Sstevel@tonic-gate 	if (smart) {
159*7c478bd9Sstevel@tonic-gate 		/*
160*7c478bd9Sstevel@tonic-gate 		 * Get the number of columns.
161*7c478bd9Sstevel@tonic-gate 		 */
162*7c478bd9Sstevel@tonic-gate 		if (ioctl(STDOUT_FILENO, TIOCGWINSZ, &ws) != -1 &&
163*7c478bd9Sstevel@tonic-gate 		    ws.ws_col > 0)
164*7c478bd9Sstevel@tonic-gate 			columns = ws.ws_col;
165*7c478bd9Sstevel@tonic-gate 		else
166*7c478bd9Sstevel@tonic-gate 			columns = 80;
167*7c478bd9Sstevel@tonic-gate 	}
168*7c478bd9Sstevel@tonic-gate 
169*7c478bd9Sstevel@tonic-gate 	for (pl = projects; pl; ) {
170*7c478bd9Sstevel@tonic-gate 		/*
171*7c478bd9Sstevel@tonic-gate 		 * Display information about projects.
172*7c478bd9Sstevel@tonic-gate 		 */
173*7c478bd9Sstevel@tonic-gate 		if (verbose) {
174*7c478bd9Sstevel@tonic-gate 			(void) printf("%1-*3$s %s\n",
175*7c478bd9Sstevel@tonic-gate 			    pl->pl_name, pl->pl_comm, length);
176*7c478bd9Sstevel@tonic-gate 		} else {
177*7c478bd9Sstevel@tonic-gate 			if (smart &&
178*7c478bd9Sstevel@tonic-gate 			    length + strlen(pl->pl_name) >= columns) {
179*7c478bd9Sstevel@tonic-gate 				(void) printf("\n");
180*7c478bd9Sstevel@tonic-gate 				length = 0;
181*7c478bd9Sstevel@tonic-gate 			}
182*7c478bd9Sstevel@tonic-gate 			(void) printf("%s ", pl->pl_name);
183*7c478bd9Sstevel@tonic-gate 			length += strlen(pl->pl_name) + 1;
184*7c478bd9Sstevel@tonic-gate 		}
185*7c478bd9Sstevel@tonic-gate 		/*
186*7c478bd9Sstevel@tonic-gate 		 * Free previously allocated buffers.
187*7c478bd9Sstevel@tonic-gate 		 */
188*7c478bd9Sstevel@tonic-gate 		next = pl->pl_next;
189*7c478bd9Sstevel@tonic-gate 		free(pl->pl_name);
190*7c478bd9Sstevel@tonic-gate 		free(pl->pl_comm);
191*7c478bd9Sstevel@tonic-gate 		free(pl);
192*7c478bd9Sstevel@tonic-gate 		pl = next;
193*7c478bd9Sstevel@tonic-gate 	}
194*7c478bd9Sstevel@tonic-gate 	if (!verbose && length != 0)
195*7c478bd9Sstevel@tonic-gate 		(void) printf("\n");
196*7c478bd9Sstevel@tonic-gate 
197*7c478bd9Sstevel@tonic-gate 	return (0);
198*7c478bd9Sstevel@tonic-gate }
199*7c478bd9Sstevel@tonic-gate 
200*7c478bd9Sstevel@tonic-gate void
201*7c478bd9Sstevel@tonic-gate print_projent(struct project *projent)
202*7c478bd9Sstevel@tonic-gate {
203*7c478bd9Sstevel@tonic-gate 	char **next;
204*7c478bd9Sstevel@tonic-gate 	char *nextc;
205*7c478bd9Sstevel@tonic-gate 	char *nextsemi;
206*7c478bd9Sstevel@tonic-gate 
207*7c478bd9Sstevel@tonic-gate 	(void) fprintf(stdout, "%s\n", projent->pj_name);
208*7c478bd9Sstevel@tonic-gate 	(void) fprintf(stdout, "\tprojid : %d\n", projent->pj_projid);
209*7c478bd9Sstevel@tonic-gate 	(void) fprintf(stdout, "\tcomment: \"%s\"\n", projent->pj_comment);
210*7c478bd9Sstevel@tonic-gate 
211*7c478bd9Sstevel@tonic-gate 	(void) fprintf(stdout, "\tusers  : ");
212*7c478bd9Sstevel@tonic-gate 	next = projent->pj_users;
213*7c478bd9Sstevel@tonic-gate 	if (*next == NULL) {
214*7c478bd9Sstevel@tonic-gate 		(void) fprintf(stdout, "(none)\n");
215*7c478bd9Sstevel@tonic-gate 	} else {
216*7c478bd9Sstevel@tonic-gate 		(void) fprintf(stdout, "%s\n", *next);
217*7c478bd9Sstevel@tonic-gate 		for (next++; *next != NULL; next++) {
218*7c478bd9Sstevel@tonic-gate 			(void) fprintf(stdout, "\t         %s\n", *next);
219*7c478bd9Sstevel@tonic-gate 		}
220*7c478bd9Sstevel@tonic-gate 	}
221*7c478bd9Sstevel@tonic-gate 
222*7c478bd9Sstevel@tonic-gate 	(void) fprintf(stdout, "\tgroups : ");
223*7c478bd9Sstevel@tonic-gate 	next = projent->pj_groups;
224*7c478bd9Sstevel@tonic-gate 	if (*next == NULL) {
225*7c478bd9Sstevel@tonic-gate 		(void) fprintf(stdout, "(none)\n");
226*7c478bd9Sstevel@tonic-gate 	} else {
227*7c478bd9Sstevel@tonic-gate 		(void) fprintf(stdout, "%s\n", *next);
228*7c478bd9Sstevel@tonic-gate 		for (next++; *next != NULL; next++) {
229*7c478bd9Sstevel@tonic-gate 			(void) fprintf(stdout, "\t         %s\n", *next);
230*7c478bd9Sstevel@tonic-gate 		}
231*7c478bd9Sstevel@tonic-gate 	}
232*7c478bd9Sstevel@tonic-gate 
233*7c478bd9Sstevel@tonic-gate 	(void) fprintf(stdout, "\tattribs: ");
234*7c478bd9Sstevel@tonic-gate 
235*7c478bd9Sstevel@tonic-gate 	nextc = projent->pj_attr;
236*7c478bd9Sstevel@tonic-gate 	if (nextc == NULL) {
237*7c478bd9Sstevel@tonic-gate 		(void) fprintf(stdout, "(none)\n");
238*7c478bd9Sstevel@tonic-gate 	} else {
239*7c478bd9Sstevel@tonic-gate 		/* print first attribute */
240*7c478bd9Sstevel@tonic-gate 		nextsemi = strchr(nextc, ';');
241*7c478bd9Sstevel@tonic-gate 		if (nextsemi)
242*7c478bd9Sstevel@tonic-gate 			*nextsemi = '\0';
243*7c478bd9Sstevel@tonic-gate 		(void) fprintf(stdout, "%s\n", nextc);
244*7c478bd9Sstevel@tonic-gate 
245*7c478bd9Sstevel@tonic-gate 		while (nextsemi) {
246*7c478bd9Sstevel@tonic-gate 			nextc = nextsemi + 1;
247*7c478bd9Sstevel@tonic-gate 			nextsemi = strchr(nextc, ';');
248*7c478bd9Sstevel@tonic-gate 			if (nextsemi)
249*7c478bd9Sstevel@tonic-gate 				*nextsemi = '\0';
250*7c478bd9Sstevel@tonic-gate 			(void) fprintf(stdout, "\t         %s\n", nextc);
251*7c478bd9Sstevel@tonic-gate 		}
252*7c478bd9Sstevel@tonic-gate 	}
253*7c478bd9Sstevel@tonic-gate }
254*7c478bd9Sstevel@tonic-gate 
255*7c478bd9Sstevel@tonic-gate static int
256*7c478bd9Sstevel@tonic-gate print_projents(char **projlist)
257*7c478bd9Sstevel@tonic-gate {
258*7c478bd9Sstevel@tonic-gate 	struct project projent;
259*7c478bd9Sstevel@tonic-gate 	char buf[PROJECT_BUFSZ];
260*7c478bd9Sstevel@tonic-gate 
261*7c478bd9Sstevel@tonic-gate 	if (*projlist == NULL) {
262*7c478bd9Sstevel@tonic-gate 		setprojent();
263*7c478bd9Sstevel@tonic-gate 
264*7c478bd9Sstevel@tonic-gate 		while (getprojent(&projent, buf, sizeof (buf)) != NULL) {
265*7c478bd9Sstevel@tonic-gate 			print_projent(&projent);
266*7c478bd9Sstevel@tonic-gate 		}
267*7c478bd9Sstevel@tonic-gate 		endprojent();
268*7c478bd9Sstevel@tonic-gate 		return (0);
269*7c478bd9Sstevel@tonic-gate 	}
270*7c478bd9Sstevel@tonic-gate 
271*7c478bd9Sstevel@tonic-gate 	while (*projlist != NULL) {
272*7c478bd9Sstevel@tonic-gate 
273*7c478bd9Sstevel@tonic-gate 		if (getprojbyname(*projlist, &projent, buf, sizeof (buf))
274*7c478bd9Sstevel@tonic-gate 		    == NULL) {
275*7c478bd9Sstevel@tonic-gate 			(void) fprintf(stderr, "%s: project \"%s\" does "
276*7c478bd9Sstevel@tonic-gate 			    "not exist\n", progname, *projlist);
277*7c478bd9Sstevel@tonic-gate 			exit(1);
278*7c478bd9Sstevel@tonic-gate 		}
279*7c478bd9Sstevel@tonic-gate 		print_projent(&projent);
280*7c478bd9Sstevel@tonic-gate 		projlist++;
281*7c478bd9Sstevel@tonic-gate 	}
282*7c478bd9Sstevel@tonic-gate 
283*7c478bd9Sstevel@tonic-gate 	return (0);
284*7c478bd9Sstevel@tonic-gate }
285*7c478bd9Sstevel@tonic-gate 
286*7c478bd9Sstevel@tonic-gate int
287*7c478bd9Sstevel@tonic-gate main(int argc, char *argv[])
288*7c478bd9Sstevel@tonic-gate {
289*7c478bd9Sstevel@tonic-gate 	struct passwd *pwd;
290*7c478bd9Sstevel@tonic-gate 	char *name;
291*7c478bd9Sstevel@tonic-gate 	int c;
292*7c478bd9Sstevel@tonic-gate 	int verbose = 0;
293*7c478bd9Sstevel@tonic-gate 	int default_only = 0;
294*7c478bd9Sstevel@tonic-gate 	int listmode = 0;
295*7c478bd9Sstevel@tonic-gate 	uid_t uid;
296*7c478bd9Sstevel@tonic-gate 
297*7c478bd9Sstevel@tonic-gate 	(void) setlocale(LC_ALL, "");
298*7c478bd9Sstevel@tonic-gate 	(void) textdomain(TEXT_DOMAIN);
299*7c478bd9Sstevel@tonic-gate 	progname = argv[0];
300*7c478bd9Sstevel@tonic-gate 	while ((c = getopt(argc, argv, "dvl")) != EOF) {
301*7c478bd9Sstevel@tonic-gate 		switch (c) {
302*7c478bd9Sstevel@tonic-gate 		case 'd':
303*7c478bd9Sstevel@tonic-gate 			default_only = 1;
304*7c478bd9Sstevel@tonic-gate 			break;
305*7c478bd9Sstevel@tonic-gate 		case 'v':
306*7c478bd9Sstevel@tonic-gate 			verbose = 1;
307*7c478bd9Sstevel@tonic-gate 			break;
308*7c478bd9Sstevel@tonic-gate 		case 'l':
309*7c478bd9Sstevel@tonic-gate 			listmode = 1;
310*7c478bd9Sstevel@tonic-gate 			break;
311*7c478bd9Sstevel@tonic-gate 		default:
312*7c478bd9Sstevel@tonic-gate 			(void) fprintf(stderr, gettext(
313*7c478bd9Sstevel@tonic-gate 			    "Usage: %s [-dv] [user]\n"
314*7c478bd9Sstevel@tonic-gate 			    "       %s -l [project [project...]]\n"),
315*7c478bd9Sstevel@tonic-gate 			    progname, progname);
316*7c478bd9Sstevel@tonic-gate 			return (2);
317*7c478bd9Sstevel@tonic-gate 		}
318*7c478bd9Sstevel@tonic-gate 	}
319*7c478bd9Sstevel@tonic-gate 
320*7c478bd9Sstevel@tonic-gate 	/* just list projects if -l is specified */
321*7c478bd9Sstevel@tonic-gate 	if (listmode) {
322*7c478bd9Sstevel@tonic-gate 		if (default_only || verbose) {
323*7c478bd9Sstevel@tonic-gate 			(void) fprintf(stderr, gettext(
324*7c478bd9Sstevel@tonic-gate 			    "%s: -l incompatible with -d and -v\n"),
325*7c478bd9Sstevel@tonic-gate 			    progname);
326*7c478bd9Sstevel@tonic-gate 			(void) fprintf(stderr, gettext(
327*7c478bd9Sstevel@tonic-gate 			    "Usage: %s [-dv] [user]\n"
328*7c478bd9Sstevel@tonic-gate 			    "       %s -l [project [project...]]\n"),
329*7c478bd9Sstevel@tonic-gate 			    progname, progname);
330*7c478bd9Sstevel@tonic-gate 		}
331*7c478bd9Sstevel@tonic-gate 		exit(print_projents(argv + optind));
332*7c478bd9Sstevel@tonic-gate 	}
333*7c478bd9Sstevel@tonic-gate 	if (optind == argc) {
334*7c478bd9Sstevel@tonic-gate 		uid = getuid();
335*7c478bd9Sstevel@tonic-gate 		if ((pwd = getpwuid(uid)) == NULL) {
336*7c478bd9Sstevel@tonic-gate 			(void) fprintf(stderr,
337*7c478bd9Sstevel@tonic-gate 			    gettext("%s: getpwuid failed (%s)\n"),
338*7c478bd9Sstevel@tonic-gate 			    progname, strerror(errno));
339*7c478bd9Sstevel@tonic-gate 			return (1);
340*7c478bd9Sstevel@tonic-gate 		}
341*7c478bd9Sstevel@tonic-gate 		name = pwd->pw_name;
342*7c478bd9Sstevel@tonic-gate 	} else {
343*7c478bd9Sstevel@tonic-gate 		name = argv[optind];
344*7c478bd9Sstevel@tonic-gate 		if (getpwnam(name) == NULL) {
345*7c478bd9Sstevel@tonic-gate 			(void) fprintf(stderr,
346*7c478bd9Sstevel@tonic-gate 			    gettext("%s: user %s does not exist\n"),
347*7c478bd9Sstevel@tonic-gate 			    progname, name);
348*7c478bd9Sstevel@tonic-gate 			return (1);
349*7c478bd9Sstevel@tonic-gate 		}
350*7c478bd9Sstevel@tonic-gate 	}
351*7c478bd9Sstevel@tonic-gate 	return (print_projects(name, verbose, default_only));
352*7c478bd9Sstevel@tonic-gate }
353