1 /* $NetBSD: compat_passwd.c,v 1.2 2009/01/11 02:57:18 christos Exp $ */ 2 3 /*- 4 * Copyright (c) 2008 The NetBSD Foundation, Inc. 5 * All rights reserved. 6 * 7 * This code is derived from software contributed to The NetBSD Foundation 8 * by Christos Zoulas. 9 * 10 * Redistribution and use in source and binary forms, with or without 11 * modification, are permitted provided that the following conditions 12 * are met: 13 * 1. Redistributions of source code must retain the above copyright 14 * notice, this list of conditions and the following disclaimer. 15 * 2. Redistributions in binary form must reproduce the above copyright 16 * notice, this list of conditions and the following disclaimer in the 17 * documentation and/or other materials provided with the distribution. 18 * 3. All advertising materials mentioning features or use of this software 19 * must display the following acknowledgement: 20 * This product includes software developed by the NetBSD 21 * Foundation, Inc. and its contributors. 22 * 4. Neither the name of The NetBSD Foundation nor the names of its 23 * contributors may be used to endorse or promote products derived 24 * from this software without specific prior written permission. 25 * 26 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 27 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 28 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 29 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 30 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 31 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 32 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 33 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 34 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 35 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 36 * POSSIBILITY OF SUCH DAMAGE. 37 */ 38 #include <sys/cdefs.h> 39 #if defined(LIBC_SCCS) && !defined(lint) 40 __RCSID("$NetBSD: compat_passwd.c,v 1.2 2009/01/11 02:57:18 christos Exp $"); 41 #endif /* LIBC_SCCS and not lint */ 42 43 #define __LIBC12_SOURCE__ 44 45 #include <stdint.h> 46 #include <stdlib.h> 47 #include <string.h> 48 #include <pwd.h> 49 #include <compat/include/pwd.h> 50 #include <util.h> 51 #include <compat/util.h> 52 53 __warn_references(pw_scan, 54 "warning: reference to compatibility pw_scan(); " 55 "include <pwd.h> to generate correct reference") 56 __warn_references(pw_copy, 57 "warning: reference to compatibility pw_copy(); " 58 "include <util.h> to generate correct reference") 59 __warn_references(pw_copyx, 60 "warning: reference to compatibility pw_copyx(); " 61 "include <util.h> to generate correct reference") 62 __warn_references(pw_getpwconf, 63 "warning: reference to compatibility pw_getpwconf(); " 64 "include <pwd.h> to generate correct reference") 65 66 int 67 pw_scan(char *buf, struct passwd50 *p, int *flags) 68 { 69 struct passwd px; 70 int rv = __pw_scan50(buf, &px, flags); 71 passwd_to_passwd50(&px, p); 72 return rv; 73 } 74 75 void 76 pw_copy(int ffd, int tfd, struct passwd50 *pw50, struct passwd50 *opw50) 77 { 78 struct passwd pw, opw; 79 passwd50_to_passwd(pw50, &pw); 80 if (opw50) 81 passwd50_to_passwd(opw50, &opw); 82 __pw_copy50(ffd, tfd, &pw, opw50 ? &opw : NULL); 83 } 84 85 int 86 pw_copyx(int ffd, int tfd, struct passwd50 *pw50, struct passwd50 *opw50, 87 char *errbuf, size_t errbufsiz) 88 { 89 struct passwd pw, opw; 90 passwd50_to_passwd(pw50, &pw); 91 if (opw50) 92 passwd50_to_passwd(opw50, &opw); 93 return __pw_copyx50(ffd, tfd, &pw, opw50 ? &opw : NULL, errbuf, 94 errbufsiz); 95 } 96 97 void 98 pw_getpwconf(char *buf, size_t len, const struct passwd50 *p, const char *opt) 99 { 100 struct passwd px; 101 passwd50_to_passwd(p, &px); 102 __pw_getpwconf50(buf, len, &px, opt); 103 } 104