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