Import NetBSD usr.bin/login
This commit is contained in:
@@ -19,7 +19,7 @@ SRCS+= efun.c getbootfile.c getlabelsector.c getmaxpartitions.c \
|
||||
logwtmp.c logwtmpx.c opendisk.c parsedate.y \
|
||||
passwd.c pw_scan.c pidfile.c pidlock.c pty.c \
|
||||
raise_default_signal.c \
|
||||
secure_path.c sockaddr_snprintf.c stat_flags.c \
|
||||
secure_path.c stat_flags.c \
|
||||
ttyaction.c ttymsg.c \
|
||||
|
||||
MAN= efun.3 getbootfile.3 getlabelsector.3 getmaxpartitions.3 \
|
||||
@@ -35,7 +35,7 @@ MAN= efun.3 getbootfile.3 getlabelsector.3 getmaxpartitions.3 \
|
||||
|
||||
.else
|
||||
SRCS+= efun.c getbootfile.c \
|
||||
getmntopts.c \
|
||||
getmntopts.c sockaddr_snprintf.c\
|
||||
login.c loginx.c login_cap.c login_tty.c logout.c logoutx.c \
|
||||
logwtmp.c logwtmpx.c opendisk.c \
|
||||
passwd.c pw_scan.c pidfile.c pidlock.c pty.c \
|
||||
|
||||
@@ -38,8 +38,6 @@ __RCSID("$NetBSD: sockaddr_snprintf.c,v 1.9 2008/04/28 20:23:03 martin Exp $");
|
||||
#include <sys/un.h>
|
||||
|
||||
#include <netinet/in.h>
|
||||
#include <netatalk/at.h>
|
||||
#include <net/if_dl.h>
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
@@ -57,11 +55,13 @@ sockaddr_snprintf(char * const sbuf, const size_t len, const char * const fmt,
|
||||
char *ebuf = &sbuf[len - 1], *buf = sbuf;
|
||||
const char *ptr, *s;
|
||||
int p = -1;
|
||||
const struct sockaddr_at *sat = NULL;
|
||||
const struct sockaddr_in *sin4 = NULL;
|
||||
#ifndef __minix
|
||||
const struct sockaddr_at *sat = NULL;
|
||||
const struct sockaddr_in6 *sin6 = NULL;
|
||||
const struct sockaddr_un *sun = NULL;
|
||||
const struct sockaddr_dl *sdl = NULL;
|
||||
#endif
|
||||
int na = 1;
|
||||
|
||||
#define ADDC(c) do { if (buf < ebuf) *buf++ = c; else buf++; } \
|
||||
@@ -74,6 +74,7 @@ sockaddr_snprintf(char * const sbuf, const size_t len, const char * const fmt,
|
||||
switch (sa->sa_family) {
|
||||
case AF_UNSPEC:
|
||||
goto done;
|
||||
#ifndef __minix
|
||||
case AF_APPLETALK:
|
||||
sat = ((const struct sockaddr_at *)(const void *)sa);
|
||||
p = ntohs(sat->sat_port);
|
||||
@@ -85,11 +86,13 @@ sockaddr_snprintf(char * const sbuf, const size_t len, const char * const fmt,
|
||||
sun = ((const struct sockaddr_un *)(const void *)sa);
|
||||
(void)strlcpy(addr = abuf, sun->sun_path, SUN_LEN(sun));
|
||||
break;
|
||||
#endif
|
||||
case AF_INET:
|
||||
sin4 = ((const struct sockaddr_in *)(const void *)sa);
|
||||
p = ntohs(sin4->sin_port);
|
||||
a = &sin4->sin_addr;
|
||||
break;
|
||||
#ifndef __minix
|
||||
case AF_INET6:
|
||||
sin6 = ((const struct sockaddr_in6 *)(const void *)sa);
|
||||
p = ntohs(sin6->sin6_port);
|
||||
@@ -103,6 +106,7 @@ sockaddr_snprintf(char * const sbuf, const size_t len, const char * const fmt,
|
||||
addr = w;
|
||||
}
|
||||
break;
|
||||
#endif
|
||||
default:
|
||||
errno = EAFNOSUPPORT;
|
||||
return -1;
|
||||
@@ -111,7 +115,7 @@ sockaddr_snprintf(char * const sbuf, const size_t len, const char * const fmt,
|
||||
if (addr == abuf)
|
||||
name = addr;
|
||||
|
||||
if (a && getnameinfo(sa, (socklen_t)sa->sa_len, addr = abuf,
|
||||
if (a && getnameinfo(sa, (socklen_t)len, addr = abuf,
|
||||
(unsigned int)sizeof(abuf), NULL, 0,
|
||||
NI_NUMERICHOST|NI_NUMERICSERV) != 0)
|
||||
return -1;
|
||||
@@ -141,7 +145,7 @@ sockaddr_snprintf(char * const sbuf, const size_t len, const char * const fmt,
|
||||
ADDS(nbuf);
|
||||
break;
|
||||
case 'l':
|
||||
(void)snprintf(nbuf, sizeof(nbuf), "%d", sa->sa_len);
|
||||
(void)snprintf(nbuf, sizeof(nbuf), "%d", len);
|
||||
ADDS(nbuf);
|
||||
break;
|
||||
case 'A':
|
||||
@@ -150,7 +154,7 @@ sockaddr_snprintf(char * const sbuf, const size_t len, const char * const fmt,
|
||||
else if (!a)
|
||||
ADDNA();
|
||||
else {
|
||||
getnameinfo(sa, (socklen_t)sa->sa_len,
|
||||
getnameinfo(sa, (socklen_t)len,
|
||||
name = Abuf,
|
||||
(unsigned int)sizeof(nbuf), NULL, 0, 0);
|
||||
ADDS(name);
|
||||
@@ -162,12 +166,13 @@ sockaddr_snprintf(char * const sbuf, const size_t len, const char * const fmt,
|
||||
else if (p == -1)
|
||||
ADDNA();
|
||||
else {
|
||||
getnameinfo(sa, (socklen_t)sa->sa_len, NULL, 0,
|
||||
getnameinfo(sa, (socklen_t)len, NULL, 0,
|
||||
port = pbuf,
|
||||
(unsigned int)sizeof(pbuf), 0);
|
||||
ADDS(port);
|
||||
}
|
||||
break;
|
||||
#ifndef __minix
|
||||
case 'I':
|
||||
if (sdl && addr != abuf) {
|
||||
ADDS(abuf);
|
||||
@@ -207,6 +212,7 @@ sockaddr_snprintf(char * const sbuf, const size_t len, const char * const fmt,
|
||||
ADDNA();
|
||||
}
|
||||
break;
|
||||
#endif
|
||||
default:
|
||||
ADDC('%');
|
||||
if (na == 0)
|
||||
|
||||
Reference in New Issue
Block a user