1175061Sobrien/*	$NetBSD: compat_passwd.c,v 1.1.2.1 2008/12/28 01:14:32 christos Exp $	*/
21590Srgrimes
31590Srgrimes/*-
41590Srgrimes * Copyright (c) 2008 The NetBSD Foundation, Inc.
51590Srgrimes * All rights reserved.
61590Srgrimes *
71590Srgrimes * This code is derived from software contributed to The NetBSD Foundation
81590Srgrimes * by Christos Zoulas.
91590Srgrimes *
101590Srgrimes * Redistribution and use in source and binary forms, with or without
111590Srgrimes * modification, are permitted provided that the following conditions
121590Srgrimes * are met:
131590Srgrimes * 1. Redistributions of source code must retain the above copyright
141590Srgrimes *    notice, this list of conditions and the following disclaimer.
151590Srgrimes * 2. Redistributions in binary form must reproduce the above copyright
161590Srgrimes *    notice, this list of conditions and the following disclaimer in the
171590Srgrimes *    documentation and/or other materials provided with the distribution.
181590Srgrimes * 3. All advertising materials mentioning features or use of this software
191590Srgrimes *    must display the following acknowledgement:
201590Srgrimes *        This product includes software developed by the NetBSD
211590Srgrimes *        Foundation, Inc. and its contributors.
221590Srgrimes * 4. Neither the name of The NetBSD Foundation nor the names of its
231590Srgrimes *    contributors may be used to endorse or promote products derived
241590Srgrimes *    from this software without specific prior written permission.
251590Srgrimes *
261590Srgrimes * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
271590Srgrimes * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
281590Srgrimes * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
291590Srgrimes * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
301590Srgrimes * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
311590Srgrimes * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
321590Srgrimes * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
331590Srgrimes * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
341590Srgrimes * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
351590Srgrimes * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
361590Srgrimes * POSSIBILITY OF SUCH DAMAGE.
3713430Speter */
381590Srgrimes#include <sys/cdefs.h>
391590Srgrimes#if defined(LIBC_SCCS) && !defined(lint)
40132671Scharnier__RCSID("$NetBSD: compat_passwd.c,v 1.1.2.1 2008/12/28 01:14:32 christos Exp $");
41132671Scharnier#endif /* LIBC_SCCS and not lint */
4252415Sjulian
431590Srgrimes#define __LIBC12_SOURCE__
44118502Shsu
451590Srgrimes#include <stdint.h>
461590Srgrimes#include <stdlib.h>
471590Srgrimes#include <string.h>
481590Srgrimes#include <pwd.h>
491590Srgrimes#include <compat/include/pwd.h>
5014543Sdg#include <util.h>
511590Srgrimes#include <compat/util.h>
521590Srgrimes
5380351Sfenner__warn_references(pw_scan,
541590Srgrimes    "warning: reference to compatibility pw_scan(); "
559215Swollman    "include <pwd.h> to generate correct reference")
5620287Swollman__warn_references(pw_copy,
571590Srgrimes    "warning: reference to compatibility pw_copy(); "
582553Swollman    "include <util.h> to generate correct reference")
591590Srgrimes__warn_references(pw_copyx,
601590Srgrimes    "warning: reference to compatibility pw_copyx(); "
619215Swollman    "include <util.h> to generate correct reference")
62191356Sbms__warn_references(pw_getpwconf,
63191356Sbms    "warning: reference to compatibility pw_getpwconf(); "
641590Srgrimes    "include <pwd.h> to generate correct reference")
65191356Sbms
661590Srgrimesint
6780351Sfennerpw_scan(char *buf, struct passwd50 *p, int *flags)
68160787Syar{
691590Srgrimes	struct passwd px;
701590Srgrimes	int rv = __pw_scan50(buf, &px, flags);
711590Srgrimes	passwd_to_passwd50(&px, p);
721590Srgrimes	return rv;
73118627Shsu}
74190012Sbms
75190012Sbmsvoid
761590Srgrimespw_copy(int ffd, int tfd, struct passwd50 *pw50, struct passwd50 *opw50)
77118627Shsu{
78118627Shsu	struct passwd pw, opw;
79118627Shsu	passwd50_to_passwd(pw50, &pw);
80118627Shsu	if (opw50)
81118627Shsu		passwd50_to_passwd(opw50, &opw);
821590Srgrimes	__pw_copy50(ffd, tfd, &pw, opw50 ? &opw : NULL);
83118627Shsu}
84118627Shsu
85118627Shsuint
86118627Shsupw_copyx(int ffd, int tfd, struct passwd50 *pw50, struct passwd50 *opw50,
87118627Shsu    char *errbuf, size_t errbufsiz)
88118627Shsu{
89118627Shsu	struct passwd pw, opw;
90118627Shsu	passwd50_to_passwd(pw50, &pw);
91118627Shsu	if (opw50)
92118627Shsu		passwd50_to_passwd(opw50, &opw);
93118627Shsu	return __pw_copyx50(ffd, tfd, &pw, opw50 ? &opw : NULL, errbuf,
94118627Shsu	    errbufsiz);
95118627Shsu}
96118627Shsu
97160787Syarvoid
98118627Shsupw_getpwconf(char *buf, size_t len, const struct passwd50 *p, const char *opt)
99118627Shsu{
100118627Shsu	struct passwd px;
101160787Syar	passwd50_to_passwd(p, &px);
102118627Shsu	__pw_getpwconf50(buf, len, &px, opt);
103118627Shsu}
104118627Shsu