diff --git a/.gitignore b/.gitignore index 83a40d3c7..c8cccbcb2 100644 --- a/.gitignore +++ b/.gitignore @@ -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 diff --git a/lib/krb5/kuserok.c b/lib/krb5/kuserok.c index 492d0c6b8..807bb3c68 100644 --- a/lib/krb5/kuserok.c +++ b/lib/krb5/kuserok.c @@ -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; diff --git a/lib/roken/Makefile.am b/lib/roken/Makefile.am index b76c1b4ee..f67c5f937 100644 --- a/lib/roken/Makefile.am +++ b/lib/roken/Makefile.am @@ -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 \ diff --git a/lib/roken/getxxyyy.c b/lib/roken/getxxyyy.c deleted file mode 100644 index f6c6d8ea8..000000000 --- a/lib/roken/getxxyyy.c +++ /dev/null @@ -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 - -#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 - -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 diff --git a/lib/roken/roken.h.in b/lib/roken/roken.h.in index 06358e252..c8538e389 100644 --- a/lib/roken/roken.h.in +++ b/lib/roken/roken.h.in @@ -643,16 +643,6 @@ ROKEN_LIB_FUNCTION char* ROKEN_LIB_CALL getcwd(char *, size_t); #ifdef HAVE_PWD_H #include - -#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