summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPhilip Guenther <guenther@cvs.openbsd.org>2016-03-30 07:52:48 +0000
committerPhilip Guenther <guenther@cvs.openbsd.org>2016-03-30 07:52:48 +0000
commitbe956482da71e55637e55f51acb698124c4e698d (patch)
treeed02ae86a0e16609b327495d007f21b02561d44d
parentbf3562beafdb1f181cadcd57abaaeed07181f728 (diff)
Eliminate userspace caching by getlogin_r/setlogin; make the getlogin
syscall behave exactly like userspace getlogin_r() and rename it to match. Eliminate the reduced-to-no-op wrappers of the syscalls. Eliminate the unnecessary per-thread static buffering by getlogin(). ok kettenis@ deraadt@
-rw-r--r--lib/libc/Symbols.list4
-rw-r--r--lib/libc/gen/getlogin.c61
-rw-r--r--lib/libc/hidden/unistd.h6
-rw-r--r--lib/libc/sys/Makefile.inc14
4 files changed, 20 insertions, 65 deletions
diff --git a/lib/libc/Symbols.list b/lib/libc/Symbols.list
index f954403d882..5513d8a0268 100644
--- a/lib/libc/Symbols.list
+++ b/lib/libc/Symbols.list
@@ -46,9 +46,7 @@ _thread_sys___thrsigdivert
_thread_sys___thrsleep
_thread_sys___thrwakeup
_thread_sys__exit
-_thread_sys__getlogin
_thread_sys__ptrace
-_thread_sys__setlogin
_thread_sys_accept4
_thread_sys_accept
_thread_sys_access
@@ -103,6 +101,7 @@ _thread_sys_getfsstat
_thread_sys_getgid
_thread_sys_getgroups
_thread_sys_getitimer
+_thread_sys_getlogin_r
_thread_sys_getpeername
_thread_sys_getpgid
_thread_sys_getpgrp
@@ -195,6 +194,7 @@ _thread_sys_seteuid
_thread_sys_setgid
_thread_sys_setgroups
_thread_sys_setitimer
+_thread_sys_setlogin
_thread_sys_setpgid
_thread_sys_setpriority
_thread_sys_setregid
diff --git a/lib/libc/gen/getlogin.c b/lib/libc/gen/getlogin.c
index ff2837ae99d..c6072f1f86f 100644
--- a/lib/libc/gen/getlogin.c
+++ b/lib/libc/gen/getlogin.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: getlogin.c,v 1.13 2015/09/12 14:56:50 guenther Exp $ */
+/* $OpenBSD: getlogin.c,v 1.14 2016/03/30 07:52:47 guenther Exp $ */
/*
* Copyright (c) 1988, 1993
* The Regents of the University of California. All rights reserved.
@@ -30,70 +30,25 @@
#include <errno.h>
#include <limits.h>
-#include <pwd.h>
-#include <stdio.h>
#include <string.h>
#include <unistd.h>
-#include <utmp.h>
#include "thread_private.h"
-_THREAD_PRIVATE_MUTEX(logname);
-static int logname_valid = 0;
-static char logname[LOGIN_NAME_MAX + 1];
-
-int _getlogin(char *, size_t);
-int _setlogin(const char *);
+static char logname[LOGIN_NAME_MAX];
char *
getlogin(void)
{
- _THREAD_PRIVATE_KEY(getlogin);
- char * name = (char *)_THREAD_PRIVATE(getlogin, logname, NULL);
+ int err;
- if ((errno = getlogin_r(name, sizeof logname)) != 0)
+ if ((err = getlogin_r(logname, sizeof logname)) != 0) {
+ errno = err;
return NULL;
- if (*name == '\0') {
+ }
+ if (*logname == '\0') {
errno = ENOENT; /* well? */
return NULL;
}
- return name;
-}
-
-int
-getlogin_r(char *name, size_t namelen)
-{
- int logname_size;
-
- _THREAD_PRIVATE_MUTEX_LOCK(logname);
- if (!logname_valid) {
- if (_getlogin(logname, sizeof(logname) - 1) < 0) {
- _THREAD_PRIVATE_MUTEX_UNLOCK(logname);
- return errno;
- }
- logname_valid = 1;
- logname[LOGIN_NAME_MAX] = '\0'; /* paranoia */
- }
- logname_size = strlen(logname) + 1;
- if (namelen < logname_size) {
- _THREAD_PRIVATE_MUTEX_UNLOCK(logname);
- return ERANGE;
- }
- memcpy(name, logname, logname_size);
- _THREAD_PRIVATE_MUTEX_UNLOCK(logname);
- return 0;
-}
-DEF_WEAK(getlogin_r);
-
-int
-setlogin(const char *name)
-{
- int ret;
-
- _THREAD_PRIVATE_MUTEX_LOCK(logname);
- ret = _setlogin(name);
- if (ret == 0)
- logname_valid = 0;
- _THREAD_PRIVATE_MUTEX_UNLOCK(logname);
- return ret;
+ return logname;
}
diff --git a/lib/libc/hidden/unistd.h b/lib/libc/hidden/unistd.h
index 835dc295b8c..3565869772a 100644
--- a/lib/libc/hidden/unistd.h
+++ b/lib/libc/hidden/unistd.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: unistd.h,v 1.6 2016/03/20 02:32:40 guenther Exp $ */
+/* $OpenBSD: unistd.h,v 1.7 2016/03/30 07:52:47 guenther Exp $ */
/*
* Copyright (c) 2015 Philip Guenther <guenther@openbsd.org>
*
@@ -73,7 +73,7 @@ PROTO_NORMAL(getgrouplist);
PROTO_NORMAL(getgroups);
PROTO_DEPRECATED(gethostid);
PROTO_NORMAL(gethostname);
-/*PROTO_BARE(getlogin);*/
+PROTO_DEPRECATED(getlogin);
PROTO_NORMAL(getlogin_r);
PROTO_DEPRECATED(getmode);
PROTO_DEPRECATED(getopt);
@@ -136,7 +136,7 @@ PROTO_NORMAL(setgid);
PROTO_NORMAL(setgroups);
PROTO_DEPRECATED(sethostid);
PROTO_DEPRECATED(sethostname);
-/*PROTO_WRAP(setlogin);*/
+PROTO_NORMAL(setlogin);
PROTO_DEPRECATED(setmode);
PROTO_NORMAL(setpgid);
PROTO_DEPRECATED(setpgrp);
diff --git a/lib/libc/sys/Makefile.inc b/lib/libc/sys/Makefile.inc
index b7feb186eb0..33d762524f9 100644
--- a/lib/libc/sys/Makefile.inc
+++ b/lib/libc/sys/Makefile.inc
@@ -1,4 +1,4 @@
-# $OpenBSD: Makefile.inc,v 1.139 2016/03/30 06:38:42 jmc Exp $
+# $OpenBSD: Makefile.inc,v 1.140 2016/03/30 07:52:47 guenther Exp $
# $NetBSD: Makefile.inc,v 1.35 1995/10/16 23:49:07 jtc Exp $
# @(#)Makefile.inc 8.1 (Berkeley) 6/17/93
@@ -52,7 +52,7 @@ ASM= __get_tcb.o __getcwd.o __semctl.o __set_tcb.o __syscall.o \
recvfrom.o recvmsg.o rename.o renameat.o revoke.o rmdir.o \
sched_yield.o select.o semget.o semop.o sendmsg.o sendsyslog.o \
sendto.o \
- setegid.o seteuid.o setgid.o setgroups.o setitimer.o \
+ setegid.o seteuid.o setgid.o setgroups.o setitimer.o setlogin.o \
setpgid.o setpriority.o setregid.o setresgid.o setresuid.o \
setreuid.o setrlimit.o setrtable.o setsid.o setsockopt.o \
settimeofday.o setuid.o shmat.o shmctl.o shmdt.o \
@@ -71,13 +71,13 @@ PASM= ${ASM:.o=.po}
SASM= ${ASM:.o=.so}
DASM= ${ASM:.o=.do}
-PSEUDO= _getlogin.o _setlogin.o _ptrace.o
+PSEUDO= _ptrace.o
GPSEUDO=${PSEUDO:.o=.go}
PPSEUDO=${PSEUDO:.o=.po}
SPSEUDO=${PSEUDO:.o=.so}
DPSEUDO=${PSEUDO:.o=.do}
-PSEUDO_NOERR= _exit.o
+PSEUDO_NOERR= _exit.o getlogin_r.o
GPSEUDO_NOERR=${PSEUDO_NOERR:.o=.go}
PPSEUDO_NOERR=${PSEUDO_NOERR:.o=.po}
SPSEUDO_NOERR=${PSEUDO_NOERR:.o=.so}
@@ -104,13 +104,13 @@ GENERATE.rsyscall=\
printf '\#include "SYS.h"\nRSYSCALL(${.PREFIX})\n'
GENERATE.pseudo=\
echo creating ${.TARGET} && \
- printf '\#include "SYS.h"\nPSEUDO(${.PREFIX},${.PREFIX:S/_//})\n'
+ printf '\#include "SYS.h"\nPSEUDO(${.PREFIX},${.PREFIX:S/^_//})\n'
GENERATE.pseudo_noerr=\
echo creating ${.TARGET} && \
- printf '\#include "SYS.h"\nPSEUDO_NOERROR(${.PREFIX},${.PREFIX:S/_//})\n'
+ printf '\#include "SYS.h"\nPSEUDO_NOERROR(${.PREFIX},${.PREFIX:S/^_//})\n'
GENERATE.rsyscall_hidden=\
echo creating ${.TARGET} && \
- printf '\#include "SYS.h"\nRSYSCALL_HIDDEN(${.PREFIX:S/_//})\n'
+ printf '\#include "SYS.h"\nRSYSCALL_HIDDEN(${.PREFIX:S/^_//})\n'
# ...and one of these to control how it's compiled
FINISH= ${COMPILE.S} ${CFLAGS:M-[ID]*} ${AINC} -x assembler-with-cpp -