xref: /onnv-gate/usr/src/lib/libc/port/gen/putpwent.c (revision 8040:42abce45ef67)
10Sstevel@tonic-gate /*
20Sstevel@tonic-gate  * CDDL HEADER START
30Sstevel@tonic-gate  *
40Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
56812Sraf  * Common Development and Distribution License (the "License").
66812Sraf  * You may not use this file except in compliance with the License.
70Sstevel@tonic-gate  *
80Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
90Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
100Sstevel@tonic-gate  * See the License for the specific language governing permissions
110Sstevel@tonic-gate  * and limitations under the License.
120Sstevel@tonic-gate  *
130Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
140Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
150Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
160Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
170Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
180Sstevel@tonic-gate  *
190Sstevel@tonic-gate  * CDDL HEADER END
200Sstevel@tonic-gate  */
216812Sraf 
220Sstevel@tonic-gate /*
236812Sraf  * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
240Sstevel@tonic-gate  * Use is subject to license terms.
250Sstevel@tonic-gate  */
260Sstevel@tonic-gate 
270Sstevel@tonic-gate /*	Copyright (c) 1988 AT&T	*/
280Sstevel@tonic-gate /*	  All Rights Reserved  	*/
290Sstevel@tonic-gate 
300Sstevel@tonic-gate /*
310Sstevel@tonic-gate  * format a password file entry
320Sstevel@tonic-gate  */
336812Sraf 
346812Sraf #include "lint.h"
350Sstevel@tonic-gate #include <sys/types.h>
360Sstevel@tonic-gate #include <stdio.h>
370Sstevel@tonic-gate #include <pwd.h>
380Sstevel@tonic-gate 
390Sstevel@tonic-gate int
putpwent(const struct passwd * p,FILE * f)400Sstevel@tonic-gate putpwent(const struct passwd *p, FILE *f)
410Sstevel@tonic-gate {
420Sstevel@tonic-gate 	int black_magic;
430Sstevel@tonic-gate 
440Sstevel@tonic-gate 	(void) fprintf(f, "%s:%s", p->pw_name,
450Sstevel@tonic-gate 	    p->pw_passwd ? p->pw_passwd : "");
460Sstevel@tonic-gate 	if (((p->pw_age) != NULL) && ((*p->pw_age) != '\0'))
470Sstevel@tonic-gate 		(void) fprintf(f, ",%s", p->pw_age); /* fatal "," */
480Sstevel@tonic-gate 	black_magic = (*p->pw_name == '+' || *p->pw_name == '-');
490Sstevel@tonic-gate 	/* leading "+/-"  taken from getpwnam_r.c */
500Sstevel@tonic-gate 	if (black_magic) {
510Sstevel@tonic-gate 		(void) fprintf(f, ":::%s:%s:%s",
526812Sraf 		    p->pw_gecos ? p->pw_gecos : "",
536812Sraf 		    p->pw_dir ? p->pw_dir : "",
546812Sraf 		    p->pw_shell ? p->pw_shell : "");
550Sstevel@tonic-gate 	} else { /* "normal case" */
56*8040SBaban.Kenkre@Sun.COM 		(void) fprintf(f, ":%u:%u:%s:%s:%s",
576812Sraf 		    p->pw_uid,
586812Sraf 		    p->pw_gid,
596812Sraf 		    p->pw_gecos,
606812Sraf 		    p->pw_dir,
616812Sraf 		    p->pw_shell);
620Sstevel@tonic-gate 	}
630Sstevel@tonic-gate 	(void) putc('\n', f);
640Sstevel@tonic-gate 	(void) fflush(f);
650Sstevel@tonic-gate 	return (ferror(f));
660Sstevel@tonic-gate }
67