Remove rk_getpw*_r() functions

This commit is contained in:
Luke Howard
2018-12-26 13:20:23 +11:00
committed by Nico Williams
parent 3f1451a4c3
commit 6ce1aa84c5
5 changed files with 2 additions and 187 deletions

1
.gitignore vendored
View File

@@ -365,7 +365,6 @@ asn1_*.[cx]
/lib/roken/base64-test
/lib/roken/getaddrinfo-test
/lib/roken/getifaddrs-test
/lib/roken/getxxyyy-test
/lib/roken/glob.h
/lib/roken/hex-test
/lib/roken/make-roken

View File

@@ -144,7 +144,7 @@ check_owner_dir(krb5_context context,
heim_assert(owner != NULL, "no directory owner ?");
if (rk_getpwnam_r(owner, &pw, pwbuf, sizeof(pwbuf), &pwd) != 0) {
if (getpwnam_r(owner, &pw, pwbuf, sizeof(pwbuf), &pwd) != 0) {
krb5_set_error_message(context, errno,
"User unknown %s (getpwnam_r())", owner);
return EACCES;
@@ -219,7 +219,7 @@ check_owner_file(krb5_context context,
if (owner == NULL)
return 0;
if (rk_getpwnam_r(owner, &pw, pwbuf, sizeof(pwbuf), &pwd) != 0) {
if (getpwnam_r(owner, &pw, pwbuf, sizeof(pwbuf), &pwd) != 0) {
krb5_set_error_message(context, errno,
"User unknown %s (getpwnam_r())", owner);
return EACCES;

View File

@@ -28,7 +28,6 @@ check_PROGRAMS = \
base64-test \
getaddrinfo-test \
getifaddrs-test \
getxxyyy-test \
hex-test \
test-auxval \
test-getuserinfo \
@@ -74,9 +73,6 @@ tsearch_test_SOURCES = tsearch-test.c
tsearch_test_LDADD = libtest.la $(LDADD)
tsearch_test_CFLAGS = -DTEST_TSEARCH
getxxyyy_test_SOURCES = getxxyyy.c
getxxyyy_test_CFLAGS = -DTEST_GETXXYYY
resolve_test_SOURCES = resolve-test.c
libroken_la_SOURCES = \
@@ -102,7 +98,6 @@ libroken_la_SOURCES = \
getnameinfo_verified.c \
getprogname.c \
getuserinfo.c \
getxxyyy.c \
h_errno.c \
hex.c \
hostent_find_fqdn.c \

View File

@@ -1,169 +0,0 @@
/*
* Copyright (c) 2011 Kungliga Tekniska Högskolan
* (Royal Institute of Technology, Stockholm, Sweden).
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* 3. Neither the name of the Institute nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
#include <config.h>
#include "roken.h"
#ifdef TEST_GETXXYYY
#undef rk_getpwnam_r
ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL
rk_getpwnam_r(const char *, struct passwd *, char *, size_t, struct passwd **);
ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL
rk_getpwuid_r(uid_t, struct passwd *, char *, size_t, struct passwd **);
#endif
#if !defined(POSIX_GETPWNAM_R) || defined(TEST_GETXXYYY)
/*
* At least limit the race between threads
*/
ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL
rk_getpwnam_r(const char *name, struct passwd *pwd, char *buffer,
size_t bufsize, struct passwd **result)
{
struct passwd *p;
size_t slen, n = 0;
*result = NULL;
p = getpwnam(name);
if(p == NULL)
return (errno = ENOENT);
memset(pwd, 0, sizeof(*pwd));
#define APPEND(el) \
do { \
slen = strlen(p->el) + 1; \
if (slen > bufsize) return (errno = ENOMEM); \
memcpy(buffer, p->el, slen); \
pwd->el = buffer; \
buffer += slen; \
bufsize -= slen; \
} while(0)
APPEND(pw_name);
if (p->pw_passwd)
APPEND(pw_name);
pwd->pw_uid = p->pw_uid;
pwd->pw_gid = p->pw_gid;
APPEND(pw_gecos);
APPEND(pw_dir);
APPEND(pw_shell);
*result = pwd;
return 0;
}
ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL
rk_getpwuid_r(uid_t uid, struct passwd *pwd, char *buffer,
size_t bufsize, struct passwd **result)
{
struct passwd *p;
size_t slen, n = 0;
*result = NULL;
p = getpwuid(uid);
if(p == NULL)
return (errno = ENOENT);
memset(pwd, 0, sizeof(*pwd));
APPEND(pw_name);
if (p->pw_passwd)
APPEND(pw_name);
pwd->pw_uid = p->pw_uid;
pwd->pw_gid = p->pw_gid;
APPEND(pw_gecos);
APPEND(pw_dir);
APPEND(pw_shell);
*result = pwd;
return 0;
}
#endif /* POSIX_GETPWNAM_R */
#ifdef TEST_GETXXYYY
#include <err.h>
int verbose_flag = 0;
static void
print_result(struct passwd *p)
{
if (!verbose_flag)
return;
printf("%s\n", p->pw_name);
printf("%d\n", (int)p->pw_uid);
printf("%s\n", p->pw_shell);
printf("%s\n", p->pw_dir);
}
int
main(int argc, char **argv)
{
struct passwd pwd, *result;
char buf[1024];
int ret;
const char *user;
user = getenv("USER");
if (!user)
user = "root";
ret = rk_getpwnam_r(user, &pwd, buf, sizeof(buf), &result);
if (ret)
errx(1, "rk_getpwnam_r");
print_result(result);
ret = rk_getpwnam_r(user, &pwd, buf, 1, &result);
if (ret == 0)
errx(1, "rk_getpwnam_r too small buf");
ret = rk_getpwnam_r("no-user-here-promise", &pwd, buf, sizeof(buf), &result);
if (ret == 0)
errx(1, "rk_getpwnam_r no user");
return 0;
}
#endif

View File

@@ -643,16 +643,6 @@ ROKEN_LIB_FUNCTION char* ROKEN_LIB_CALL getcwd(char *, size_t);
#ifdef HAVE_PWD_H
#include <pwd.h>
#ifdef POSIX_GETPWNAM_R
#define rk_getpwnam_r(_n, _pw, _b, _sz, _pwd) getpwnam_r(_n, _pw, _b, _sz, _pwd)
#define rk_getpwuid_r(_u, _pw, _b, _sz, _pwd) getpwuid_r(_u, _pw, _b, _sz, _pwd)
#else
ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL
rk_getpwnam_r(const char *, struct passwd *, char *, size_t, struct passwd **);
ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL
rk_getpwuid_r(uid_t, struct passwd *, char *, size_t, struct passwd **);
#endif
#endif
#ifndef HAVE_SETEUID