2003-04-17 14:15:26 +00:00
|
|
|
/*-
|
|
|
|
* Copyright (c) 2003 Networks Associates Technology, Inc.
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* This software was developed for the FreeBSD Project by
|
|
|
|
* Jacques A. Vidrine, Safeport Network Services, and Network
|
|
|
|
* Associates Laboratories, the Security Research Division of Network
|
|
|
|
* Associates, Inc. under DARPA/SPAWAR contract N66001-01-C-8035
|
|
|
|
* ("CBOSS"), as part of the DARPA CHATS research program.
|
1994-05-27 05:00:24 +00:00
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*
|
2003-04-17 14:15:26 +00:00
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
|
1994-05-27 05:00:24 +00:00
|
|
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
2003-04-17 14:15:26 +00:00
|
|
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
|
1994-05-27 05:00:24 +00:00
|
|
|
* 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.
|
2003-04-17 14:15:26 +00:00
|
|
|
*
|
1994-05-27 05:00:24 +00:00
|
|
|
*/
|
2002-01-31 12:58:36 +00:00
|
|
|
#include <sys/cdefs.h>
|
2002-01-30 21:36:57 +00:00
|
|
|
__FBSDID("$FreeBSD$");
|
1994-05-27 05:00:24 +00:00
|
|
|
|
2003-04-17 14:15:26 +00:00
|
|
|
#include "namespace.h"
|
1994-05-27 05:00:24 +00:00
|
|
|
#include <sys/param.h>
|
Add nsswitch support. By creating an /etc/nsswitch.conf file, you can
configure FreeBSD so that various databases such as passwd and group can be
looked up using flat files, NIS, or Hesiod.
= Hesiod has been added to libc (see hesiod(3)).
= A library routine for parsing nsswitch.conf and invoking callback
functions as specified has been added to libc (see nsdispatch(3)).
= The following C library functions have been modified to use nsdispatch:
. getgrent, getgrnam, getgrgid
. getpwent, getpwnam, getpwuid
. getusershell
. getaddrinfo
. gethostbyname, gethostbyname2, gethostbyaddr
. getnetbyname, getnetbyaddr
. getipnodebyname, getipnodebyaddr, getnodebyname, getnodebyaddr
= host.conf has been removed from src/etc. rc.network has been modified
to warn that host.conf is no longer used at boot time. In addition, if
there is a host.conf but no nsswitch.conf, the latter is created at boot
time from the former.
Obtained from: NetBSD
2000-09-06 18:16:48 +00:00
|
|
|
#ifdef YP
|
|
|
|
#include <rpc/rpc.h>
|
|
|
|
#include <rpcsvc/yp_prot.h>
|
|
|
|
#include <rpcsvc/ypclnt.h>
|
|
|
|
#endif
|
2003-04-17 14:15:26 +00:00
|
|
|
#include <arpa/inet.h>
|
|
|
|
#include <errno.h>
|
|
|
|
#include <fcntl.h>
|
|
|
|
#ifdef HESIOD
|
|
|
|
#include <hesiod.h>
|
|
|
|
#endif
|
|
|
|
#include <netdb.h>
|
|
|
|
#include <nsswitch.h>
|
|
|
|
#include <pthread.h>
|
|
|
|
#include <pthread_np.h>
|
|
|
|
#include <pwd.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <syslog.h>
|
|
|
|
#include <unistd.h>
|
2001-01-24 13:01:12 +00:00
|
|
|
#include "un-namespace.h"
|
2003-04-17 14:15:26 +00:00
|
|
|
#include <db.h>
|
2003-02-27 13:40:01 +00:00
|
|
|
#include "libc_private.h"
|
Add nsswitch support. By creating an /etc/nsswitch.conf file, you can
configure FreeBSD so that various databases such as passwd and group can be
looked up using flat files, NIS, or Hesiod.
= Hesiod has been added to libc (see hesiod(3)).
= A library routine for parsing nsswitch.conf and invoking callback
functions as specified has been added to libc (see nsdispatch(3)).
= The following C library functions have been modified to use nsdispatch:
. getgrent, getgrnam, getgrgid
. getpwent, getpwnam, getpwuid
. getusershell
. getaddrinfo
. gethostbyname, gethostbyname2, gethostbyaddr
. getnetbyname, getnetbyaddr
. getipnodebyname, getipnodebyaddr, getnodebyname, getnodebyaddr
= host.conf has been removed from src/etc. rc.network has been modified
to warn that host.conf is no longer used at boot time. In addition, if
there is a host.conf but no nsswitch.conf, the latter is created at boot
time from the former.
Obtained from: NetBSD
2000-09-06 18:16:48 +00:00
|
|
|
#include "pw_scan.h"
|
2003-04-17 14:15:26 +00:00
|
|
|
#include "nss_tls.h"
|
2006-04-28 12:03:38 +00:00
|
|
|
#ifdef NS_CACHING
|
|
|
|
#include "nscache.h"
|
|
|
|
#endif
|
Add nsswitch support. By creating an /etc/nsswitch.conf file, you can
configure FreeBSD so that various databases such as passwd and group can be
looked up using flat files, NIS, or Hesiod.
= Hesiod has been added to libc (see hesiod(3)).
= A library routine for parsing nsswitch.conf and invoking callback
functions as specified has been added to libc (see nsdispatch(3)).
= The following C library functions have been modified to use nsdispatch:
. getgrent, getgrnam, getgrgid
. getpwent, getpwnam, getpwuid
. getusershell
. getaddrinfo
. gethostbyname, gethostbyname2, gethostbyaddr
. getnetbyname, getnetbyaddr
. getipnodebyname, getipnodebyaddr, getnodebyname, getnodebyaddr
= host.conf has been removed from src/etc. rc.network has been modified
to warn that host.conf is no longer used at boot time. In addition, if
there is a host.conf but no nsswitch.conf, the latter is created at boot
time from the former.
Obtained from: NetBSD
2000-09-06 18:16:48 +00:00
|
|
|
|
2003-04-17 14:15:26 +00:00
|
|
|
#ifndef CTASSERT
|
|
|
|
#define CTASSERT(x) _CTASSERT(x, __LINE__)
|
|
|
|
#define _CTASSERT(x, y) __CTASSERT(x, y)
|
|
|
|
#define __CTASSERT(x, y) typedef char __assert_ ## y [(x) ? 1 : -1]
|
Add nsswitch support. By creating an /etc/nsswitch.conf file, you can
configure FreeBSD so that various databases such as passwd and group can be
looked up using flat files, NIS, or Hesiod.
= Hesiod has been added to libc (see hesiod(3)).
= A library routine for parsing nsswitch.conf and invoking callback
functions as specified has been added to libc (see nsdispatch(3)).
= The following C library functions have been modified to use nsdispatch:
. getgrent, getgrnam, getgrgid
. getpwent, getpwnam, getpwuid
. getusershell
. getaddrinfo
. gethostbyname, gethostbyname2, gethostbyaddr
. getnetbyname, getnetbyaddr
. getipnodebyname, getipnodebyaddr, getnodebyname, getnodebyaddr
= host.conf has been removed from src/etc. rc.network has been modified
to warn that host.conf is no longer used at boot time. In addition, if
there is a host.conf but no nsswitch.conf, the latter is created at boot
time from the former.
Obtained from: NetBSD
2000-09-06 18:16:48 +00:00
|
|
|
#endif
|
1996-07-12 18:57:58 +00:00
|
|
|
|
2003-04-17 14:15:26 +00:00
|
|
|
/* Counter as stored in /etc/pwd.db */
|
|
|
|
typedef int pwkeynum;
|
|
|
|
|
|
|
|
CTASSERT(MAXLOGNAME > sizeof(uid_t));
|
|
|
|
CTASSERT(MAXLOGNAME > sizeof(pwkeynum));
|
|
|
|
|
|
|
|
enum constants {
|
|
|
|
PWD_STORAGE_INITIAL = 1 << 10, /* 1 KByte */
|
|
|
|
PWD_STORAGE_MAX = 1 << 20, /* 1 MByte */
|
|
|
|
SETPWENT = 1,
|
|
|
|
ENDPWENT = 2,
|
|
|
|
HESIOD_NAME_MAX = 256
|
|
|
|
};
|
|
|
|
|
|
|
|
static const ns_src defaultsrc[] = {
|
2003-04-18 01:00:37 +00:00
|
|
|
{ NSSRC_COMPAT, NS_SUCCESS },
|
2003-04-17 14:15:26 +00:00
|
|
|
{ NULL, 0 }
|
|
|
|
};
|
|
|
|
|
|
|
|
int __pw_match_entry(const char *, size_t, enum nss_lookup_type,
|
|
|
|
const char *, uid_t);
|
|
|
|
int __pw_parse_entry(char *, size_t, struct passwd *, int, int *errnop);
|
|
|
|
|
2003-04-18 22:07:30 +00:00
|
|
|
static void pwd_init(struct passwd *);
|
2003-04-18 17:27:05 +00:00
|
|
|
|
2003-04-17 14:15:26 +00:00
|
|
|
union key {
|
|
|
|
const char *name;
|
|
|
|
uid_t uid;
|
|
|
|
};
|
1997-03-11 11:52:33 +00:00
|
|
|
|
2003-04-17 14:15:26 +00:00
|
|
|
static struct passwd *getpw(int (*fn)(union key, struct passwd *, char *,
|
|
|
|
size_t, struct passwd **), union key);
|
|
|
|
static int wrap_getpwnam_r(union key, struct passwd *, char *,
|
|
|
|
size_t, struct passwd **);
|
|
|
|
static int wrap_getpwuid_r(union key, struct passwd *, char *, size_t,
|
|
|
|
struct passwd **);
|
|
|
|
static int wrap_getpwent_r(union key, struct passwd *, char *, size_t,
|
|
|
|
struct passwd **);
|
|
|
|
|
|
|
|
static int pwdb_match_entry_v3(char *, size_t, enum nss_lookup_type,
|
|
|
|
const char *, uid_t);
|
|
|
|
static int pwdb_parse_entry_v3(char *, size_t, struct passwd *, int *);
|
|
|
|
static int pwdb_match_entry_v4(char *, size_t, enum nss_lookup_type,
|
|
|
|
const char *, uid_t);
|
|
|
|
static int pwdb_parse_entry_v4(char *, size_t, struct passwd *, int *);
|
|
|
|
|
|
|
|
|
|
|
|
struct {
|
|
|
|
int (*match)(char *, size_t, enum nss_lookup_type, const char *,
|
|
|
|
uid_t);
|
|
|
|
int (*parse)(char *, size_t, struct passwd *, int *);
|
|
|
|
} pwdb_versions[] = {
|
|
|
|
{ NULL, NULL }, /* version 0 */
|
|
|
|
{ NULL, NULL }, /* version 1 */
|
|
|
|
{ NULL, NULL }, /* version 2 */
|
|
|
|
{ pwdb_match_entry_v3, pwdb_parse_entry_v3 }, /* version 3 */
|
|
|
|
{ pwdb_match_entry_v4, pwdb_parse_entry_v4 }, /* version 4 */
|
|
|
|
};
|
1996-04-16 00:22:41 +00:00
|
|
|
|
1994-05-27 05:00:24 +00:00
|
|
|
|
2003-04-17 14:15:26 +00:00
|
|
|
struct files_state {
|
|
|
|
DB *db;
|
|
|
|
pwkeynum keynum;
|
|
|
|
int stayopen;
|
|
|
|
int version;
|
Add nsswitch support. By creating an /etc/nsswitch.conf file, you can
configure FreeBSD so that various databases such as passwd and group can be
looked up using flat files, NIS, or Hesiod.
= Hesiod has been added to libc (see hesiod(3)).
= A library routine for parsing nsswitch.conf and invoking callback
functions as specified has been added to libc (see nsdispatch(3)).
= The following C library functions have been modified to use nsdispatch:
. getgrent, getgrnam, getgrgid
. getpwent, getpwnam, getpwuid
. getusershell
. getaddrinfo
. gethostbyname, gethostbyname2, gethostbyaddr
. getnetbyname, getnetbyaddr
. getipnodebyname, getipnodebyaddr, getnodebyname, getnodebyaddr
= host.conf has been removed from src/etc. rc.network has been modified
to warn that host.conf is no longer used at boot time. In addition, if
there is a host.conf but no nsswitch.conf, the latter is created at boot
time from the former.
Obtained from: NetBSD
2000-09-06 18:16:48 +00:00
|
|
|
};
|
2003-04-17 14:15:26 +00:00
|
|
|
static void files_endstate(void *);
|
|
|
|
NSS_TLS_HANDLING(files);
|
|
|
|
static DB *pwdbopen(int *);
|
|
|
|
static void files_endstate(void *);
|
|
|
|
static int files_setpwent(void *, void *, va_list);
|
|
|
|
static int files_passwd(void *, void *, va_list);
|
|
|
|
|
|
|
|
|
|
|
|
#ifdef HESIOD
|
|
|
|
struct dns_state {
|
|
|
|
long counter;
|
|
|
|
};
|
|
|
|
static void dns_endstate(void *);
|
|
|
|
NSS_TLS_HANDLING(dns);
|
|
|
|
static int dns_setpwent(void *, void *, va_list);
|
|
|
|
static int dns_passwd(void *, void *, va_list);
|
|
|
|
#endif
|
|
|
|
|
1994-05-27 05:00:24 +00:00
|
|
|
|
1994-09-20 01:23:45 +00:00
|
|
|
#ifdef YP
|
2003-04-17 14:15:26 +00:00
|
|
|
struct nis_state {
|
|
|
|
char domain[MAXHOSTNAMELEN];
|
|
|
|
int done;
|
|
|
|
char *key;
|
|
|
|
int keylen;
|
|
|
|
};
|
|
|
|
static void nis_endstate(void *);
|
|
|
|
NSS_TLS_HANDLING(nis);
|
|
|
|
static int nis_setpwent(void *, void *, va_list);
|
|
|
|
static int nis_passwd(void *, void *, va_list);
|
|
|
|
static int nis_map(char *, enum nss_lookup_type, char *, size_t, int *);
|
|
|
|
static int nis_adjunct(char *, const char *, char *, size_t);
|
1995-04-04 05:36:16 +00:00
|
|
|
#endif
|
1995-09-02 04:08:55 +00:00
|
|
|
|
2003-04-17 14:15:26 +00:00
|
|
|
|
|
|
|
struct compat_state {
|
|
|
|
DB *db;
|
|
|
|
pwkeynum keynum;
|
|
|
|
int stayopen;
|
|
|
|
int version;
|
|
|
|
DB *exclude;
|
|
|
|
struct passwd template;
|
|
|
|
char *name;
|
|
|
|
enum _compat {
|
|
|
|
COMPAT_MODE_OFF = 0,
|
|
|
|
COMPAT_MODE_ALL,
|
|
|
|
COMPAT_MODE_NAME,
|
|
|
|
COMPAT_MODE_NETGROUP
|
|
|
|
} compat;
|
|
|
|
};
|
|
|
|
static void compat_endstate(void *);
|
|
|
|
NSS_TLS_HANDLING(compat);
|
|
|
|
static int compat_setpwent(void *, void *, va_list);
|
|
|
|
static int compat_passwd(void *, void *, va_list);
|
|
|
|
static void compat_clear_template(struct passwd *);
|
|
|
|
static int compat_set_template(struct passwd *, struct passwd *);
|
|
|
|
static int compat_use_template(struct passwd *, struct passwd *, char *,
|
|
|
|
size_t);
|
|
|
|
static int compat_redispatch(struct compat_state *, enum nss_lookup_type,
|
|
|
|
enum nss_lookup_type, const char *, const char *, uid_t,
|
|
|
|
struct passwd *, char *, size_t, int *);
|
2006-04-28 12:03:38 +00:00
|
|
|
|
|
|
|
#ifdef NS_CACHING
|
|
|
|
static int pwd_id_func(char *, size_t *, va_list ap, void *);
|
|
|
|
static int pwd_marshal_func(char *, size_t *, void *, va_list, void *);
|
|
|
|
static int pwd_unmarshal_func(char *, size_t, void *, va_list, void *);
|
|
|
|
|
|
|
|
static int
|
|
|
|
pwd_id_func(char *buffer, size_t *buffer_size, va_list ap, void *cache_mdata)
|
|
|
|
{
|
|
|
|
char *name;
|
|
|
|
uid_t uid;
|
|
|
|
size_t size, desired_size;
|
|
|
|
int res = NS_UNAVAIL;
|
|
|
|
enum nss_lookup_type lookup_type;
|
|
|
|
|
|
|
|
lookup_type = (enum nss_lookup_type)cache_mdata;
|
|
|
|
switch (lookup_type) {
|
|
|
|
case nss_lt_name:
|
|
|
|
name = va_arg(ap, char *);
|
|
|
|
size = strlen(name);
|
|
|
|
desired_size = sizeof(enum nss_lookup_type) + size + 1;
|
|
|
|
if (desired_size > *buffer_size) {
|
|
|
|
res = NS_RETURN;
|
|
|
|
goto fin;
|
|
|
|
}
|
|
|
|
|
|
|
|
memcpy(buffer, &lookup_type, sizeof(enum nss_lookup_type));
|
|
|
|
memcpy(buffer + sizeof(enum nss_lookup_type), name, size + 1);
|
|
|
|
|
|
|
|
res = NS_SUCCESS;
|
|
|
|
break;
|
|
|
|
case nss_lt_id:
|
|
|
|
uid = va_arg(ap, uid_t);
|
|
|
|
desired_size = sizeof(enum nss_lookup_type) + sizeof(uid_t);
|
|
|
|
if (desired_size > *buffer_size) {
|
|
|
|
res = NS_RETURN;
|
|
|
|
goto fin;
|
|
|
|
}
|
|
|
|
|
|
|
|
memcpy(buffer, &lookup_type, sizeof(enum nss_lookup_type));
|
|
|
|
memcpy(buffer + sizeof(enum nss_lookup_type), &uid,
|
|
|
|
sizeof(uid_t));
|
|
|
|
|
|
|
|
res = NS_SUCCESS;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
/* should be unreachable */
|
|
|
|
return (NS_UNAVAIL);
|
|
|
|
}
|
|
|
|
|
|
|
|
fin:
|
|
|
|
*buffer_size = desired_size;
|
|
|
|
return (res);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
pwd_marshal_func(char *buffer, size_t *buffer_size, void *retval, va_list ap,
|
|
|
|
void *cache_mdata)
|
|
|
|
{
|
|
|
|
char *name;
|
|
|
|
uid_t uid;
|
|
|
|
struct passwd *pwd;
|
|
|
|
char *orig_buf;
|
|
|
|
size_t orig_buf_size;
|
|
|
|
|
|
|
|
struct passwd new_pwd;
|
|
|
|
size_t desired_size, size;
|
|
|
|
char *p;
|
|
|
|
|
|
|
|
switch ((enum nss_lookup_type)cache_mdata) {
|
|
|
|
case nss_lt_name:
|
|
|
|
name = va_arg(ap, char *);
|
|
|
|
break;
|
|
|
|
case nss_lt_id:
|
|
|
|
uid = va_arg(ap, uid_t);
|
|
|
|
break;
|
|
|
|
case nss_lt_all:
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
/* should be unreachable */
|
|
|
|
return (NS_UNAVAIL);
|
|
|
|
}
|
|
|
|
|
|
|
|
pwd = va_arg(ap, struct passwd *);
|
|
|
|
orig_buf = va_arg(ap, char *);
|
|
|
|
orig_buf_size = va_arg(ap, size_t);
|
|
|
|
|
|
|
|
desired_size = sizeof(struct passwd) + sizeof(char *) +
|
|
|
|
strlen(pwd->pw_name) + 1;
|
|
|
|
if (pwd->pw_passwd != NULL)
|
|
|
|
desired_size += strlen(pwd->pw_passwd) + 1;
|
|
|
|
if (pwd->pw_class != NULL)
|
|
|
|
desired_size += strlen(pwd->pw_class) + 1;
|
|
|
|
if (pwd->pw_gecos != NULL)
|
|
|
|
desired_size += strlen(pwd->pw_gecos) + 1;
|
|
|
|
if (pwd->pw_dir != NULL)
|
|
|
|
desired_size += strlen(pwd->pw_dir) + 1;
|
|
|
|
if (pwd->pw_shell != NULL)
|
|
|
|
desired_size += strlen(pwd->pw_shell) + 1;
|
|
|
|
|
|
|
|
if (*buffer_size < desired_size) {
|
|
|
|
/* this assignment is here for future use */
|
|
|
|
*buffer_size = desired_size;
|
|
|
|
return (NS_RETURN);
|
|
|
|
}
|
|
|
|
|
|
|
|
memcpy(&new_pwd, pwd, sizeof(struct passwd));
|
|
|
|
memset(buffer, 0, desired_size);
|
|
|
|
|
|
|
|
*buffer_size = desired_size;
|
|
|
|
p = buffer + sizeof(struct passwd) + sizeof(char *);
|
|
|
|
memcpy(buffer + sizeof(struct passwd), &p, sizeof(char *));
|
|
|
|
|
|
|
|
if (new_pwd.pw_name != NULL) {
|
|
|
|
size = strlen(new_pwd.pw_name);
|
|
|
|
memcpy(p, new_pwd.pw_name, size);
|
|
|
|
new_pwd.pw_name = p;
|
|
|
|
p += size + 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (new_pwd.pw_passwd != NULL) {
|
|
|
|
size = strlen(new_pwd.pw_passwd);
|
|
|
|
memcpy(p, new_pwd.pw_passwd, size);
|
|
|
|
new_pwd.pw_passwd = p;
|
|
|
|
p += size + 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (new_pwd.pw_class != NULL) {
|
|
|
|
size = strlen(new_pwd.pw_class);
|
|
|
|
memcpy(p, new_pwd.pw_class, size);
|
|
|
|
new_pwd.pw_class = p;
|
|
|
|
p += size + 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (new_pwd.pw_gecos != NULL) {
|
|
|
|
size = strlen(new_pwd.pw_gecos);
|
|
|
|
memcpy(p, new_pwd.pw_gecos, size);
|
|
|
|
new_pwd.pw_gecos = p;
|
|
|
|
p += size + 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (new_pwd.pw_dir != NULL) {
|
|
|
|
size = strlen(new_pwd.pw_dir);
|
|
|
|
memcpy(p, new_pwd.pw_dir, size);
|
|
|
|
new_pwd.pw_dir = p;
|
|
|
|
p += size + 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (new_pwd.pw_shell != NULL) {
|
|
|
|
size = strlen(new_pwd.pw_shell);
|
|
|
|
memcpy(p, new_pwd.pw_shell, size);
|
|
|
|
new_pwd.pw_shell = p;
|
|
|
|
p += size + 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
memcpy(buffer, &new_pwd, sizeof(struct passwd));
|
|
|
|
return (NS_SUCCESS);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
pwd_unmarshal_func(char *buffer, size_t buffer_size, void *retval, va_list ap,
|
|
|
|
void *cache_mdata)
|
|
|
|
{
|
|
|
|
char *name;
|
|
|
|
uid_t uid;
|
|
|
|
struct passwd *pwd;
|
|
|
|
char *orig_buf;
|
|
|
|
size_t orig_buf_size;
|
|
|
|
int *ret_errno;
|
|
|
|
|
|
|
|
char *p;
|
|
|
|
|
|
|
|
switch ((enum nss_lookup_type)cache_mdata) {
|
|
|
|
case nss_lt_name:
|
|
|
|
name = va_arg(ap, char *);
|
|
|
|
break;
|
|
|
|
case nss_lt_id:
|
|
|
|
uid = va_arg(ap, uid_t);
|
|
|
|
break;
|
|
|
|
case nss_lt_all:
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
/* should be unreachable */
|
|
|
|
return (NS_UNAVAIL);
|
|
|
|
}
|
|
|
|
|
|
|
|
pwd = va_arg(ap, struct passwd *);
|
|
|
|
orig_buf = va_arg(ap, char *);
|
|
|
|
orig_buf_size = va_arg(ap, size_t);
|
|
|
|
ret_errno = va_arg(ap, int *);
|
|
|
|
|
|
|
|
if (orig_buf_size <
|
|
|
|
buffer_size - sizeof(struct passwd) - sizeof(char *)) {
|
|
|
|
*ret_errno = ERANGE;
|
|
|
|
return (NS_RETURN);
|
|
|
|
}
|
|
|
|
|
|
|
|
memcpy(pwd, buffer, sizeof(struct passwd));
|
|
|
|
memcpy(&p, buffer + sizeof(struct passwd), sizeof(char *));
|
|
|
|
memcpy(orig_buf, buffer + sizeof(struct passwd) + sizeof(char *),
|
|
|
|
buffer_size - sizeof(struct passwd) - sizeof(char *));
|
|
|
|
|
|
|
|
NS_APPLY_OFFSET(pwd->pw_name, orig_buf, p, char *);
|
|
|
|
NS_APPLY_OFFSET(pwd->pw_passwd, orig_buf, p, char *);
|
|
|
|
NS_APPLY_OFFSET(pwd->pw_class, orig_buf, p, char *);
|
|
|
|
NS_APPLY_OFFSET(pwd->pw_gecos, orig_buf, p, char *);
|
|
|
|
NS_APPLY_OFFSET(pwd->pw_dir, orig_buf, p, char *);
|
|
|
|
NS_APPLY_OFFSET(pwd->pw_shell, orig_buf, p, char *);
|
|
|
|
|
|
|
|
if (retval != NULL)
|
|
|
|
*((struct passwd **)retval) = pwd;
|
|
|
|
|
|
|
|
return (NS_SUCCESS);
|
|
|
|
}
|
|
|
|
|
|
|
|
NSS_MP_CACHE_HANDLING(passwd);
|
|
|
|
#endif /* NS_CACHING */
|
|
|
|
|
2003-04-17 14:15:26 +00:00
|
|
|
void
|
|
|
|
setpwent(void)
|
|
|
|
{
|
2006-04-28 12:03:38 +00:00
|
|
|
#ifdef NS_CACHING
|
|
|
|
static const nss_cache_info cache_info = NS_MP_CACHE_INFO_INITIALIZER(
|
|
|
|
passwd, (void *)nss_lt_all,
|
|
|
|
NULL, NULL);
|
|
|
|
#endif
|
|
|
|
|
2003-04-17 14:15:26 +00:00
|
|
|
static const ns_dtab dtab[] = {
|
|
|
|
{ NSSRC_FILES, files_setpwent, (void *)SETPWENT },
|
Add nsswitch support. By creating an /etc/nsswitch.conf file, you can
configure FreeBSD so that various databases such as passwd and group can be
looked up using flat files, NIS, or Hesiod.
= Hesiod has been added to libc (see hesiod(3)).
= A library routine for parsing nsswitch.conf and invoking callback
functions as specified has been added to libc (see nsdispatch(3)).
= The following C library functions have been modified to use nsdispatch:
. getgrent, getgrnam, getgrgid
. getpwent, getpwnam, getpwuid
. getusershell
. getaddrinfo
. gethostbyname, gethostbyname2, gethostbyaddr
. getnetbyname, getnetbyaddr
. getipnodebyname, getipnodebyaddr, getnodebyname, getnodebyaddr
= host.conf has been removed from src/etc. rc.network has been modified
to warn that host.conf is no longer used at boot time. In addition, if
there is a host.conf but no nsswitch.conf, the latter is created at boot
time from the former.
Obtained from: NetBSD
2000-09-06 18:16:48 +00:00
|
|
|
#ifdef HESIOD
|
2003-04-17 14:15:26 +00:00
|
|
|
{ NSSRC_DNS, dns_setpwent, (void *)SETPWENT },
|
1994-09-20 01:23:45 +00:00
|
|
|
#endif
|
2003-04-17 14:15:26 +00:00
|
|
|
#ifdef YP
|
|
|
|
{ NSSRC_NIS, nis_setpwent, (void *)SETPWENT },
|
|
|
|
#endif
|
|
|
|
{ NSSRC_COMPAT, compat_setpwent, (void *)SETPWENT },
|
2006-04-28 12:03:38 +00:00
|
|
|
#ifdef NS_CACHING
|
|
|
|
NS_CACHE_CB(&cache_info)
|
|
|
|
#endif
|
2003-04-17 14:15:26 +00:00
|
|
|
{ NULL, NULL, NULL }
|
|
|
|
};
|
|
|
|
(void)_nsdispatch(NULL, dtab, NSDB_PASSWD, "setpwent", defaultsrc, 0);
|
|
|
|
}
|
1994-05-27 05:00:24 +00:00
|
|
|
|
Add nsswitch support. By creating an /etc/nsswitch.conf file, you can
configure FreeBSD so that various databases such as passwd and group can be
looked up using flat files, NIS, or Hesiod.
= Hesiod has been added to libc (see hesiod(3)).
= A library routine for parsing nsswitch.conf and invoking callback
functions as specified has been added to libc (see nsdispatch(3)).
= The following C library functions have been modified to use nsdispatch:
. getgrent, getgrnam, getgrgid
. getpwent, getpwnam, getpwuid
. getusershell
. getaddrinfo
. gethostbyname, gethostbyname2, gethostbyaddr
. getnetbyname, getnetbyaddr
. getipnodebyname, getipnodebyaddr, getnodebyname, getnodebyaddr
= host.conf has been removed from src/etc. rc.network has been modified
to warn that host.conf is no longer used at boot time. In addition, if
there is a host.conf but no nsswitch.conf, the latter is created at boot
time from the former.
Obtained from: NetBSD
2000-09-06 18:16:48 +00:00
|
|
|
|
2003-04-17 14:15:26 +00:00
|
|
|
int
|
|
|
|
setpassent(int stayopen)
|
1994-05-27 05:00:24 +00:00
|
|
|
{
|
2006-04-28 12:03:38 +00:00
|
|
|
#ifdef NS_CACHING
|
|
|
|
static const nss_cache_info cache_info = NS_MP_CACHE_INFO_INITIALIZER(
|
|
|
|
passwd, (void *)nss_lt_all,
|
|
|
|
NULL, NULL);
|
|
|
|
#endif
|
|
|
|
|
2003-04-17 14:15:26 +00:00
|
|
|
static const ns_dtab dtab[] = {
|
|
|
|
{ NSSRC_FILES, files_setpwent, (void *)SETPWENT },
|
|
|
|
#ifdef HESIOD
|
|
|
|
{ NSSRC_DNS, dns_setpwent, (void *)SETPWENT },
|
|
|
|
#endif
|
|
|
|
#ifdef YP
|
|
|
|
{ NSSRC_NIS, nis_setpwent, (void *)SETPWENT },
|
|
|
|
#endif
|
|
|
|
{ NSSRC_COMPAT, compat_setpwent, (void *)SETPWENT },
|
2006-04-28 12:03:38 +00:00
|
|
|
#ifdef NS_CACHING
|
|
|
|
NS_CACHE_CB(&cache_info)
|
|
|
|
#endif
|
2003-04-17 14:15:26 +00:00
|
|
|
{ NULL, NULL, NULL }
|
|
|
|
};
|
|
|
|
(void)_nsdispatch(NULL, dtab, NSDB_PASSWD, "setpwent", defaultsrc,
|
|
|
|
stayopen);
|
|
|
|
return (1);
|
|
|
|
}
|
1994-05-27 05:00:24 +00:00
|
|
|
|
|
|
|
|
2003-04-17 14:15:26 +00:00
|
|
|
void
|
|
|
|
endpwent(void)
|
|
|
|
{
|
2006-04-28 12:03:38 +00:00
|
|
|
#ifdef NS_CACHING
|
|
|
|
static const nss_cache_info cache_info = NS_MP_CACHE_INFO_INITIALIZER(
|
|
|
|
passwd, (void *)nss_lt_all,
|
|
|
|
NULL, NULL);
|
|
|
|
#endif
|
|
|
|
|
2003-04-17 14:15:26 +00:00
|
|
|
static const ns_dtab dtab[] = {
|
|
|
|
{ NSSRC_FILES, files_setpwent, (void *)ENDPWENT },
|
|
|
|
#ifdef HESIOD
|
|
|
|
{ NSSRC_DNS, dns_setpwent, (void *)ENDPWENT },
|
|
|
|
#endif
|
|
|
|
#ifdef YP
|
|
|
|
{ NSSRC_NIS, nis_setpwent, (void *)ENDPWENT },
|
|
|
|
#endif
|
|
|
|
{ NSSRC_COMPAT, compat_setpwent, (void *)ENDPWENT },
|
2006-04-28 12:03:38 +00:00
|
|
|
#ifdef NS_CACHING
|
|
|
|
NS_CACHE_CB(&cache_info)
|
|
|
|
#endif
|
2003-04-17 14:15:26 +00:00
|
|
|
{ NULL, NULL, NULL }
|
|
|
|
};
|
|
|
|
(void)_nsdispatch(NULL, dtab, NSDB_PASSWD, "endpwent", defaultsrc);
|
1994-05-27 05:00:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-04-17 14:15:26 +00:00
|
|
|
int
|
|
|
|
getpwent_r(struct passwd *pwd, char *buffer, size_t bufsize,
|
|
|
|
struct passwd **result)
|
|
|
|
{
|
2006-04-28 12:03:38 +00:00
|
|
|
#ifdef NS_CACHING
|
|
|
|
static const nss_cache_info cache_info = NS_MP_CACHE_INFO_INITIALIZER(
|
|
|
|
passwd, (void *)nss_lt_all,
|
|
|
|
pwd_marshal_func, pwd_unmarshal_func);
|
|
|
|
#endif
|
|
|
|
|
2003-04-17 14:15:26 +00:00
|
|
|
static const ns_dtab dtab[] = {
|
|
|
|
{ NSSRC_FILES, files_passwd, (void *)nss_lt_all },
|
|
|
|
#ifdef HESIOD
|
|
|
|
{ NSSRC_DNS, dns_passwd, (void *)nss_lt_all },
|
|
|
|
#endif
|
|
|
|
#ifdef YP
|
|
|
|
{ NSSRC_NIS, nis_passwd, (void *)nss_lt_all },
|
|
|
|
#endif
|
|
|
|
{ NSSRC_COMPAT, compat_passwd, (void *)nss_lt_all },
|
2006-04-28 12:03:38 +00:00
|
|
|
#ifdef NS_CACHING
|
|
|
|
NS_CACHE_CB(&cache_info)
|
|
|
|
#endif
|
2003-04-17 14:15:26 +00:00
|
|
|
{ NULL, NULL, NULL }
|
|
|
|
};
|
|
|
|
int rv, ret_errno;
|
|
|
|
|
2003-04-18 22:07:30 +00:00
|
|
|
pwd_init(pwd);
|
|
|
|
ret_errno = 0;
|
2003-04-17 14:15:26 +00:00
|
|
|
*result = NULL;
|
|
|
|
rv = _nsdispatch(result, dtab, NSDB_PASSWD, "getpwent_r", defaultsrc,
|
|
|
|
pwd, buffer, bufsize, &ret_errno);
|
|
|
|
if (rv == NS_SUCCESS)
|
|
|
|
return (0);
|
|
|
|
else
|
|
|
|
return (ret_errno);
|
|
|
|
}
|
1994-05-27 05:00:24 +00:00
|
|
|
|
1995-03-23 00:59:15 +00:00
|
|
|
|
2003-04-17 14:15:26 +00:00
|
|
|
int
|
|
|
|
getpwnam_r(const char *name, struct passwd *pwd, char *buffer, size_t bufsize,
|
|
|
|
struct passwd **result)
|
|
|
|
{
|
2006-04-28 12:03:38 +00:00
|
|
|
#ifdef NS_CACHING
|
|
|
|
static const nss_cache_info cache_info =
|
|
|
|
NS_COMMON_CACHE_INFO_INITIALIZER(
|
|
|
|
passwd, (void *)nss_lt_name,
|
|
|
|
pwd_id_func, pwd_marshal_func, pwd_unmarshal_func);
|
|
|
|
#endif
|
|
|
|
|
2003-04-17 14:15:26 +00:00
|
|
|
static const ns_dtab dtab[] = {
|
|
|
|
{ NSSRC_FILES, files_passwd, (void *)nss_lt_name },
|
|
|
|
#ifdef HESIOD
|
|
|
|
{ NSSRC_DNS, dns_passwd, (void *)nss_lt_name },
|
|
|
|
#endif
|
|
|
|
#ifdef YP
|
|
|
|
{ NSSRC_NIS, nis_passwd, (void *)nss_lt_name },
|
|
|
|
#endif
|
|
|
|
{ NSSRC_COMPAT, compat_passwd, (void *)nss_lt_name },
|
2006-04-28 12:03:38 +00:00
|
|
|
#ifdef NS_CACHING
|
|
|
|
NS_CACHE_CB(&cache_info)
|
|
|
|
#endif
|
2003-04-17 14:15:26 +00:00
|
|
|
{ NULL, NULL, NULL }
|
|
|
|
};
|
|
|
|
int rv, ret_errno;
|
|
|
|
|
2003-04-18 22:07:30 +00:00
|
|
|
pwd_init(pwd);
|
|
|
|
ret_errno = 0;
|
2003-04-17 14:15:26 +00:00
|
|
|
*result = NULL;
|
|
|
|
rv = _nsdispatch(result, dtab, NSDB_PASSWD, "getpwnam_r", defaultsrc,
|
|
|
|
name, pwd, buffer, bufsize, &ret_errno);
|
|
|
|
if (rv == NS_SUCCESS)
|
|
|
|
return (0);
|
|
|
|
else
|
|
|
|
return (ret_errno);
|
1994-05-27 05:00:24 +00:00
|
|
|
}
|
|
|
|
|
2003-04-17 14:15:26 +00:00
|
|
|
|
|
|
|
int
|
|
|
|
getpwuid_r(uid_t uid, struct passwd *pwd, char *buffer, size_t bufsize,
|
|
|
|
struct passwd **result)
|
1994-05-27 05:00:24 +00:00
|
|
|
{
|
2006-04-28 12:03:38 +00:00
|
|
|
#ifdef NS_CACHING
|
|
|
|
static const nss_cache_info cache_info =
|
|
|
|
NS_COMMON_CACHE_INFO_INITIALIZER(
|
|
|
|
passwd, (void *)nss_lt_id,
|
|
|
|
pwd_id_func, pwd_marshal_func, pwd_unmarshal_func);
|
|
|
|
#endif
|
|
|
|
|
2003-04-17 14:15:26 +00:00
|
|
|
static const ns_dtab dtab[] = {
|
|
|
|
{ NSSRC_FILES, files_passwd, (void *)nss_lt_id },
|
|
|
|
#ifdef HESIOD
|
|
|
|
{ NSSRC_DNS, dns_passwd, (void *)nss_lt_id },
|
|
|
|
#endif
|
|
|
|
#ifdef YP
|
|
|
|
{ NSSRC_NIS, nis_passwd, (void *)nss_lt_id },
|
|
|
|
#endif
|
|
|
|
{ NSSRC_COMPAT, compat_passwd, (void *)nss_lt_id },
|
2006-04-28 12:03:38 +00:00
|
|
|
#ifdef NS_CACHING
|
|
|
|
NS_CACHE_CB(&cache_info)
|
|
|
|
#endif
|
2003-04-17 14:15:26 +00:00
|
|
|
{ NULL, NULL, NULL }
|
|
|
|
};
|
|
|
|
int rv, ret_errno;
|
|
|
|
|
2003-04-18 22:07:30 +00:00
|
|
|
pwd_init(pwd);
|
|
|
|
ret_errno = 0;
|
2003-04-17 14:15:26 +00:00
|
|
|
*result = NULL;
|
|
|
|
rv = _nsdispatch(result, dtab, NSDB_PASSWD, "getpwuid_r", defaultsrc,
|
|
|
|
uid, pwd, buffer, bufsize, &ret_errno);
|
|
|
|
if (rv == NS_SUCCESS)
|
|
|
|
return (0);
|
|
|
|
else
|
|
|
|
return (ret_errno);
|
|
|
|
}
|
Add nsswitch support. By creating an /etc/nsswitch.conf file, you can
configure FreeBSD so that various databases such as passwd and group can be
looked up using flat files, NIS, or Hesiod.
= Hesiod has been added to libc (see hesiod(3)).
= A library routine for parsing nsswitch.conf and invoking callback
functions as specified has been added to libc (see nsdispatch(3)).
= The following C library functions have been modified to use nsdispatch:
. getgrent, getgrnam, getgrgid
. getpwent, getpwnam, getpwuid
. getusershell
. getaddrinfo
. gethostbyname, gethostbyname2, gethostbyaddr
. getnetbyname, getnetbyaddr
. getipnodebyname, getipnodebyaddr, getnodebyname, getnodebyaddr
= host.conf has been removed from src/etc. rc.network has been modified
to warn that host.conf is no longer used at boot time. In addition, if
there is a host.conf but no nsswitch.conf, the latter is created at boot
time from the former.
Obtained from: NetBSD
2000-09-06 18:16:48 +00:00
|
|
|
|
|
|
|
|
2003-04-18 22:07:30 +00:00
|
|
|
static void
|
|
|
|
pwd_init(struct passwd *pwd)
|
2003-04-18 17:27:05 +00:00
|
|
|
{
|
2003-04-18 22:07:30 +00:00
|
|
|
static char nul[] = "";
|
2003-04-18 17:27:05 +00:00
|
|
|
|
|
|
|
memset(pwd, 0, sizeof(*pwd));
|
|
|
|
pwd->pw_uid = (uid_t)-1; /* Considered least likely to lead to */
|
|
|
|
pwd->pw_gid = (gid_t)-1; /* a security issue. */
|
2003-04-18 22:07:30 +00:00
|
|
|
pwd->pw_name = nul;
|
|
|
|
pwd->pw_passwd = nul;
|
|
|
|
pwd->pw_class = nul;
|
|
|
|
pwd->pw_gecos = nul;
|
|
|
|
pwd->pw_dir = nul;
|
|
|
|
pwd->pw_shell = nul;
|
2003-04-18 17:27:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-04-17 14:15:26 +00:00
|
|
|
static struct passwd pwd;
|
|
|
|
static char *pwd_storage;
|
|
|
|
static size_t pwd_storage_size;
|
|
|
|
|
Add nsswitch support. By creating an /etc/nsswitch.conf file, you can
configure FreeBSD so that various databases such as passwd and group can be
looked up using flat files, NIS, or Hesiod.
= Hesiod has been added to libc (see hesiod(3)).
= A library routine for parsing nsswitch.conf and invoking callback
functions as specified has been added to libc (see nsdispatch(3)).
= The following C library functions have been modified to use nsdispatch:
. getgrent, getgrnam, getgrgid
. getpwent, getpwnam, getpwuid
. getusershell
. getaddrinfo
. gethostbyname, gethostbyname2, gethostbyaddr
. getnetbyname, getnetbyaddr
. getipnodebyname, getipnodebyaddr, getnodebyname, getnodebyaddr
= host.conf has been removed from src/etc. rc.network has been modified
to warn that host.conf is no longer used at boot time. In addition, if
there is a host.conf but no nsswitch.conf, the latter is created at boot
time from the former.
Obtained from: NetBSD
2000-09-06 18:16:48 +00:00
|
|
|
|
2003-04-17 14:15:26 +00:00
|
|
|
static struct passwd *
|
|
|
|
getpw(int (*fn)(union key, struct passwd *, char *, size_t, struct passwd **),
|
|
|
|
union key key)
|
|
|
|
{
|
|
|
|
int rv;
|
|
|
|
struct passwd *res;
|
|
|
|
|
|
|
|
if (pwd_storage == NULL) {
|
|
|
|
pwd_storage = malloc(PWD_STORAGE_INITIAL);
|
|
|
|
if (pwd_storage == NULL)
|
|
|
|
return (NULL);
|
|
|
|
pwd_storage_size = PWD_STORAGE_INITIAL;
|
2000-11-10 19:11:14 +00:00
|
|
|
}
|
2003-04-17 14:15:26 +00:00
|
|
|
do {
|
|
|
|
rv = fn(key, &pwd, pwd_storage, pwd_storage_size, &res);
|
|
|
|
if (res == NULL && rv == ERANGE) {
|
|
|
|
free(pwd_storage);
|
|
|
|
if ((pwd_storage_size << 1) > PWD_STORAGE_MAX) {
|
|
|
|
pwd_storage = NULL;
|
2004-05-17 06:17:59 +00:00
|
|
|
errno = ERANGE;
|
2003-04-17 14:15:26 +00:00
|
|
|
return (NULL);
|
|
|
|
}
|
|
|
|
pwd_storage_size <<= 1;
|
|
|
|
pwd_storage = malloc(pwd_storage_size);
|
|
|
|
if (pwd_storage == NULL)
|
|
|
|
return (NULL);
|
|
|
|
}
|
|
|
|
} while (res == NULL && rv == ERANGE);
|
2004-05-17 18:27:05 +00:00
|
|
|
if (rv != 0)
|
2004-05-17 06:17:59 +00:00
|
|
|
errno = rv;
|
2003-04-17 14:15:26 +00:00
|
|
|
return (res);
|
1994-05-27 05:00:24 +00:00
|
|
|
}
|
|
|
|
|
2003-04-17 14:15:26 +00:00
|
|
|
|
Add nsswitch support. By creating an /etc/nsswitch.conf file, you can
configure FreeBSD so that various databases such as passwd and group can be
looked up using flat files, NIS, or Hesiod.
= Hesiod has been added to libc (see hesiod(3)).
= A library routine for parsing nsswitch.conf and invoking callback
functions as specified has been added to libc (see nsdispatch(3)).
= The following C library functions have been modified to use nsdispatch:
. getgrent, getgrnam, getgrgid
. getpwent, getpwnam, getpwuid
. getusershell
. getaddrinfo
. gethostbyname, gethostbyname2, gethostbyaddr
. getnetbyname, getnetbyaddr
. getipnodebyname, getipnodebyaddr, getnodebyname, getnodebyaddr
= host.conf has been removed from src/etc. rc.network has been modified
to warn that host.conf is no longer used at boot time. In addition, if
there is a host.conf but no nsswitch.conf, the latter is created at boot
time from the former.
Obtained from: NetBSD
2000-09-06 18:16:48 +00:00
|
|
|
static int
|
2003-04-17 14:15:26 +00:00
|
|
|
wrap_getpwnam_r(union key key, struct passwd *pwd, char *buffer,
|
|
|
|
size_t bufsize, struct passwd **res)
|
1994-05-27 05:00:24 +00:00
|
|
|
{
|
2003-04-17 14:15:26 +00:00
|
|
|
return (getpwnam_r(key.name, pwd, buffer, bufsize, res));
|
|
|
|
}
|
1994-05-27 05:00:24 +00:00
|
|
|
|
|
|
|
|
2003-04-17 14:15:26 +00:00
|
|
|
static int
|
|
|
|
wrap_getpwuid_r(union key key, struct passwd *pwd, char *buffer,
|
|
|
|
size_t bufsize, struct passwd **res)
|
|
|
|
{
|
|
|
|
return (getpwuid_r(key.uid, pwd, buffer, bufsize, res));
|
|
|
|
}
|
1994-05-27 05:00:24 +00:00
|
|
|
|
|
|
|
|
2003-04-17 14:15:26 +00:00
|
|
|
static int
|
|
|
|
wrap_getpwent_r(union key key __unused, struct passwd *pwd, char *buffer,
|
|
|
|
size_t bufsize, struct passwd **res)
|
|
|
|
{
|
|
|
|
return (getpwent_r(pwd, buffer, bufsize, res));
|
|
|
|
}
|
1994-05-27 05:00:24 +00:00
|
|
|
|
|
|
|
|
2003-04-17 14:15:26 +00:00
|
|
|
struct passwd *
|
|
|
|
getpwnam(const char *name)
|
|
|
|
{
|
|
|
|
union key key;
|
|
|
|
|
|
|
|
key.name = name;
|
|
|
|
return (getpw(wrap_getpwnam_r, key));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
struct passwd *
|
|
|
|
getpwuid(uid_t uid)
|
|
|
|
{
|
|
|
|
union key key;
|
|
|
|
|
|
|
|
key.uid = uid;
|
|
|
|
return (getpw(wrap_getpwuid_r, key));
|
1994-05-27 05:00:24 +00:00
|
|
|
}
|
1994-09-20 01:23:45 +00:00
|
|
|
|
2003-04-17 14:15:26 +00:00
|
|
|
|
|
|
|
struct passwd *
|
|
|
|
getpwent(void)
|
|
|
|
{
|
|
|
|
union key key;
|
|
|
|
|
|
|
|
key.uid = 0; /* not used */
|
|
|
|
return (getpw(wrap_getpwent_r, key));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
Add nsswitch support. By creating an /etc/nsswitch.conf file, you can
configure FreeBSD so that various databases such as passwd and group can be
looked up using flat files, NIS, or Hesiod.
= Hesiod has been added to libc (see hesiod(3)).
= A library routine for parsing nsswitch.conf and invoking callback
functions as specified has been added to libc (see nsdispatch(3)).
= The following C library functions have been modified to use nsdispatch:
. getgrent, getgrnam, getgrgid
. getpwent, getpwnam, getpwuid
. getusershell
. getaddrinfo
. gethostbyname, gethostbyname2, gethostbyaddr
. getnetbyname, getnetbyaddr
. getipnodebyname, getipnodebyaddr, getnodebyname, getnodebyaddr
= host.conf has been removed from src/etc. rc.network has been modified
to warn that host.conf is no longer used at boot time. In addition, if
there is a host.conf but no nsswitch.conf, the latter is created at boot
time from the former.
Obtained from: NetBSD
2000-09-06 18:16:48 +00:00
|
|
|
/*
|
2003-04-17 14:15:26 +00:00
|
|
|
* files backend
|
Add nsswitch support. By creating an /etc/nsswitch.conf file, you can
configure FreeBSD so that various databases such as passwd and group can be
looked up using flat files, NIS, or Hesiod.
= Hesiod has been added to libc (see hesiod(3)).
= A library routine for parsing nsswitch.conf and invoking callback
functions as specified has been added to libc (see nsdispatch(3)).
= The following C library functions have been modified to use nsdispatch:
. getgrent, getgrnam, getgrgid
. getpwent, getpwnam, getpwuid
. getusershell
. getaddrinfo
. gethostbyname, gethostbyname2, gethostbyaddr
. getnetbyname, getnetbyaddr
. getipnodebyname, getipnodebyaddr, getnodebyname, getnodebyaddr
= host.conf has been removed from src/etc. rc.network has been modified
to warn that host.conf is no longer used at boot time. In addition, if
there is a host.conf but no nsswitch.conf, the latter is created at boot
time from the former.
Obtained from: NetBSD
2000-09-06 18:16:48 +00:00
|
|
|
*/
|
2003-04-17 14:15:26 +00:00
|
|
|
static DB *
|
|
|
|
pwdbopen(int *version)
|
1995-03-23 00:59:15 +00:00
|
|
|
{
|
2003-04-17 14:15:26 +00:00
|
|
|
DB *res;
|
|
|
|
DBT key, entry;
|
|
|
|
int rv;
|
|
|
|
|
|
|
|
if (geteuid() != 0 ||
|
|
|
|
(res = dbopen(_PATH_SMP_DB, O_RDONLY, 0, DB_HASH, NULL)) == NULL)
|
|
|
|
res = dbopen(_PATH_MP_DB, O_RDONLY, 0, DB_HASH, NULL);
|
|
|
|
if (res == NULL)
|
|
|
|
return (NULL);
|
|
|
|
key.data = _PWD_VERSION_KEY;
|
|
|
|
key.size = strlen(_PWD_VERSION_KEY);
|
|
|
|
rv = res->get(res, &key, &entry, 0);
|
|
|
|
if (rv == 0)
|
|
|
|
*version = *(unsigned char *)entry.data;
|
|
|
|
else
|
|
|
|
*version = 3;
|
|
|
|
if (*version < 3 ||
|
|
|
|
*version >= sizeof(pwdb_versions)/sizeof(pwdb_versions[0])) {
|
|
|
|
syslog(LOG_CRIT, "Unsupported password database version %d",
|
|
|
|
*version);
|
|
|
|
res->close(res);
|
|
|
|
res = NULL;
|
1998-09-15 16:22:30 +00:00
|
|
|
}
|
2003-04-17 14:15:26 +00:00
|
|
|
return (res);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
files_endstate(void *p)
|
|
|
|
{
|
|
|
|
DB *db;
|
|
|
|
|
|
|
|
if (p == NULL)
|
|
|
|
return;
|
|
|
|
db = ((struct files_state *)p)->db;
|
|
|
|
if (db != NULL)
|
|
|
|
db->close(db);
|
|
|
|
free(p);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static int
|
|
|
|
files_setpwent(void *retval, void *mdata, va_list ap)
|
|
|
|
{
|
|
|
|
struct files_state *st;
|
|
|
|
int rv, stayopen;
|
|
|
|
|
|
|
|
rv = files_getstate(&st);
|
|
|
|
if (rv != 0)
|
|
|
|
return (NS_UNAVAIL);
|
|
|
|
switch ((enum constants)mdata) {
|
|
|
|
case SETPWENT:
|
|
|
|
stayopen = va_arg(ap, int);
|
|
|
|
st->keynum = 0;
|
|
|
|
if (stayopen)
|
|
|
|
st->db = pwdbopen(&st->version);
|
|
|
|
st->stayopen = stayopen;
|
|
|
|
break;
|
|
|
|
case ENDPWENT:
|
|
|
|
if (st->db != NULL) {
|
|
|
|
(void)st->db->close(st->db);
|
|
|
|
st->db = NULL;
|
Add nsswitch support. By creating an /etc/nsswitch.conf file, you can
configure FreeBSD so that various databases such as passwd and group can be
looked up using flat files, NIS, or Hesiod.
= Hesiod has been added to libc (see hesiod(3)).
= A library routine for parsing nsswitch.conf and invoking callback
functions as specified has been added to libc (see nsdispatch(3)).
= The following C library functions have been modified to use nsdispatch:
. getgrent, getgrnam, getgrgid
. getpwent, getpwnam, getpwuid
. getusershell
. getaddrinfo
. gethostbyname, gethostbyname2, gethostbyaddr
. getnetbyname, getnetbyaddr
. getipnodebyname, getipnodebyaddr, getnodebyname, getnodebyaddr
= host.conf has been removed from src/etc. rc.network has been modified
to warn that host.conf is no longer used at boot time. In addition, if
there is a host.conf but no nsswitch.conf, the latter is created at boot
time from the former.
Obtained from: NetBSD
2000-09-06 18:16:48 +00:00
|
|
|
}
|
2003-04-17 14:15:26 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
Add nsswitch support. By creating an /etc/nsswitch.conf file, you can
configure FreeBSD so that various databases such as passwd and group can be
looked up using flat files, NIS, or Hesiod.
= Hesiod has been added to libc (see hesiod(3)).
= A library routine for parsing nsswitch.conf and invoking callback
functions as specified has been added to libc (see nsdispatch(3)).
= The following C library functions have been modified to use nsdispatch:
. getgrent, getgrnam, getgrgid
. getpwent, getpwnam, getpwuid
. getusershell
. getaddrinfo
. gethostbyname, gethostbyname2, gethostbyaddr
. getnetbyname, getnetbyaddr
. getipnodebyname, getipnodebyaddr, getnodebyname, getnodebyaddr
= host.conf has been removed from src/etc. rc.network has been modified
to warn that host.conf is no longer used at boot time. In addition, if
there is a host.conf but no nsswitch.conf, the latter is created at boot
time from the former.
Obtained from: NetBSD
2000-09-06 18:16:48 +00:00
|
|
|
}
|
2003-04-17 14:15:26 +00:00
|
|
|
return (NS_UNAVAIL);
|
1996-04-16 00:22:41 +00:00
|
|
|
}
|
1995-03-23 00:59:15 +00:00
|
|
|
|
Add nsswitch support. By creating an /etc/nsswitch.conf file, you can
configure FreeBSD so that various databases such as passwd and group can be
looked up using flat files, NIS, or Hesiod.
= Hesiod has been added to libc (see hesiod(3)).
= A library routine for parsing nsswitch.conf and invoking callback
functions as specified has been added to libc (see nsdispatch(3)).
= The following C library functions have been modified to use nsdispatch:
. getgrent, getgrnam, getgrgid
. getpwent, getpwnam, getpwuid
. getusershell
. getaddrinfo
. gethostbyname, gethostbyname2, gethostbyaddr
. getnetbyname, getnetbyaddr
. getipnodebyname, getipnodebyaddr, getnodebyname, getnodebyaddr
= host.conf has been removed from src/etc. rc.network has been modified
to warn that host.conf is no longer used at boot time. In addition, if
there is a host.conf but no nsswitch.conf, the latter is created at boot
time from the former.
Obtained from: NetBSD
2000-09-06 18:16:48 +00:00
|
|
|
|
|
|
|
static int
|
2003-04-17 14:15:26 +00:00
|
|
|
files_passwd(void *retval, void *mdata, va_list ap)
|
1996-04-16 00:22:41 +00:00
|
|
|
{
|
2003-04-17 14:15:26 +00:00
|
|
|
char keybuf[MAXLOGNAME + 1];
|
|
|
|
DBT key, entry;
|
|
|
|
struct files_state *st;
|
|
|
|
enum nss_lookup_type how;
|
|
|
|
const char *name;
|
|
|
|
struct passwd *pwd;
|
|
|
|
char *buffer;
|
|
|
|
size_t bufsize, namesize;
|
|
|
|
uid_t uid;
|
|
|
|
uint32_t store;
|
|
|
|
int rv, stayopen, *errnop;
|
1996-04-16 00:22:41 +00:00
|
|
|
|
2003-04-17 14:15:26 +00:00
|
|
|
name = NULL;
|
|
|
|
uid = (uid_t)-1;
|
|
|
|
how = (enum nss_lookup_type)mdata;
|
|
|
|
switch (how) {
|
|
|
|
case nss_lt_name:
|
Add nsswitch support. By creating an /etc/nsswitch.conf file, you can
configure FreeBSD so that various databases such as passwd and group can be
looked up using flat files, NIS, or Hesiod.
= Hesiod has been added to libc (see hesiod(3)).
= A library routine for parsing nsswitch.conf and invoking callback
functions as specified has been added to libc (see nsdispatch(3)).
= The following C library functions have been modified to use nsdispatch:
. getgrent, getgrnam, getgrgid
. getpwent, getpwnam, getpwuid
. getusershell
. getaddrinfo
. gethostbyname, gethostbyname2, gethostbyaddr
. getnetbyname, getnetbyaddr
. getipnodebyname, getipnodebyaddr, getnodebyname, getnodebyaddr
= host.conf has been removed from src/etc. rc.network has been modified
to warn that host.conf is no longer used at boot time. In addition, if
there is a host.conf but no nsswitch.conf, the latter is created at boot
time from the former.
Obtained from: NetBSD
2000-09-06 18:16:48 +00:00
|
|
|
name = va_arg(ap, const char *);
|
2003-04-17 14:15:26 +00:00
|
|
|
keybuf[0] = _PW_KEYBYNAME;
|
Add nsswitch support. By creating an /etc/nsswitch.conf file, you can
configure FreeBSD so that various databases such as passwd and group can be
looked up using flat files, NIS, or Hesiod.
= Hesiod has been added to libc (see hesiod(3)).
= A library routine for parsing nsswitch.conf and invoking callback
functions as specified has been added to libc (see nsdispatch(3)).
= The following C library functions have been modified to use nsdispatch:
. getgrent, getgrnam, getgrgid
. getpwent, getpwnam, getpwuid
. getusershell
. getaddrinfo
. gethostbyname, gethostbyname2, gethostbyaddr
. getnetbyname, getnetbyaddr
. getipnodebyname, getipnodebyaddr, getnodebyname, getnodebyaddr
= host.conf has been removed from src/etc. rc.network has been modified
to warn that host.conf is no longer used at boot time. In addition, if
there is a host.conf but no nsswitch.conf, the latter is created at boot
time from the former.
Obtained from: NetBSD
2000-09-06 18:16:48 +00:00
|
|
|
break;
|
2003-04-17 14:15:26 +00:00
|
|
|
case nss_lt_id:
|
Add nsswitch support. By creating an /etc/nsswitch.conf file, you can
configure FreeBSD so that various databases such as passwd and group can be
looked up using flat files, NIS, or Hesiod.
= Hesiod has been added to libc (see hesiod(3)).
= A library routine for parsing nsswitch.conf and invoking callback
functions as specified has been added to libc (see nsdispatch(3)).
= The following C library functions have been modified to use nsdispatch:
. getgrent, getgrnam, getgrgid
. getpwent, getpwnam, getpwuid
. getusershell
. getaddrinfo
. gethostbyname, gethostbyname2, gethostbyaddr
. getnetbyname, getnetbyaddr
. getipnodebyname, getipnodebyaddr, getnodebyname, getnodebyaddr
= host.conf has been removed from src/etc. rc.network has been modified
to warn that host.conf is no longer used at boot time. In addition, if
there is a host.conf but no nsswitch.conf, the latter is created at boot
time from the former.
Obtained from: NetBSD
2000-09-06 18:16:48 +00:00
|
|
|
uid = va_arg(ap, uid_t);
|
2003-04-17 14:15:26 +00:00
|
|
|
keybuf[0] = _PW_KEYBYUID;
|
|
|
|
break;
|
|
|
|
case nss_lt_all:
|
|
|
|
keybuf[0] = _PW_KEYBYNUM;
|
Add nsswitch support. By creating an /etc/nsswitch.conf file, you can
configure FreeBSD so that various databases such as passwd and group can be
looked up using flat files, NIS, or Hesiod.
= Hesiod has been added to libc (see hesiod(3)).
= A library routine for parsing nsswitch.conf and invoking callback
functions as specified has been added to libc (see nsdispatch(3)).
= The following C library functions have been modified to use nsdispatch:
. getgrent, getgrnam, getgrgid
. getpwent, getpwnam, getpwuid
. getusershell
. getaddrinfo
. gethostbyname, gethostbyname2, gethostbyaddr
. getnetbyname, getnetbyaddr
. getipnodebyname, getipnodebyaddr, getnodebyname, getnodebyaddr
= host.conf has been removed from src/etc. rc.network has been modified
to warn that host.conf is no longer used at boot time. In addition, if
there is a host.conf but no nsswitch.conf, the latter is created at boot
time from the former.
Obtained from: NetBSD
2000-09-06 18:16:48 +00:00
|
|
|
break;
|
|
|
|
default:
|
2003-04-17 14:15:26 +00:00
|
|
|
rv = NS_NOTFOUND;
|
|
|
|
goto fin;
|
Add nsswitch support. By creating an /etc/nsswitch.conf file, you can
configure FreeBSD so that various databases such as passwd and group can be
looked up using flat files, NIS, or Hesiod.
= Hesiod has been added to libc (see hesiod(3)).
= A library routine for parsing nsswitch.conf and invoking callback
functions as specified has been added to libc (see nsdispatch(3)).
= The following C library functions have been modified to use nsdispatch:
. getgrent, getgrnam, getgrgid
. getpwent, getpwnam, getpwuid
. getusershell
. getaddrinfo
. gethostbyname, gethostbyname2, gethostbyaddr
. getnetbyname, getnetbyaddr
. getipnodebyname, getipnodebyaddr, getnodebyname, getnodebyaddr
= host.conf has been removed from src/etc. rc.network has been modified
to warn that host.conf is no longer used at boot time. In addition, if
there is a host.conf but no nsswitch.conf, the latter is created at boot
time from the former.
Obtained from: NetBSD
2000-09-06 18:16:48 +00:00
|
|
|
}
|
2003-04-17 14:15:26 +00:00
|
|
|
pwd = va_arg(ap, struct passwd *);
|
|
|
|
buffer = va_arg(ap, char *);
|
|
|
|
bufsize = va_arg(ap, size_t);
|
|
|
|
errnop = va_arg(ap, int *);
|
|
|
|
*errnop = files_getstate(&st);
|
|
|
|
if (*errnop != 0)
|
|
|
|
return (NS_UNAVAIL);
|
|
|
|
if (how == nss_lt_all && st->keynum < 0) {
|
|
|
|
rv = NS_NOTFOUND;
|
|
|
|
goto fin;
|
1996-04-16 00:22:41 +00:00
|
|
|
}
|
2003-04-17 14:15:26 +00:00
|
|
|
if (st->db == NULL &&
|
|
|
|
(st->db = pwdbopen(&st->version)) == NULL) {
|
|
|
|
*errnop = errno;
|
|
|
|
rv = NS_UNAVAIL;
|
|
|
|
goto fin;
|
2002-04-14 22:24:55 +00:00
|
|
|
}
|
2003-04-17 14:15:26 +00:00
|
|
|
if (how == nss_lt_all)
|
|
|
|
stayopen = 1;
|
|
|
|
else
|
|
|
|
stayopen = st->stayopen;
|
|
|
|
key.data = keybuf;
|
|
|
|
do {
|
|
|
|
switch (how) {
|
|
|
|
case nss_lt_name:
|
|
|
|
/* MAXLOGNAME includes NUL byte, but we do not
|
|
|
|
* include the NUL byte in the key.
|
|
|
|
*/
|
2003-05-01 19:03:14 +00:00
|
|
|
namesize = strlcpy(&keybuf[1], name, sizeof(keybuf)-1);
|
2003-04-17 14:15:26 +00:00
|
|
|
if (namesize >= sizeof(keybuf)-1) {
|
|
|
|
*errnop = EINVAL;
|
|
|
|
rv = NS_NOTFOUND;
|
|
|
|
goto fin;
|
|
|
|
}
|
|
|
|
key.size = namesize + 1;
|
|
|
|
break;
|
|
|
|
case nss_lt_id:
|
|
|
|
if (st->version < _PWD_CURRENT_VERSION) {
|
|
|
|
memcpy(&keybuf[1], &uid, sizeof(uid));
|
|
|
|
key.size = sizeof(uid) + 1;
|
|
|
|
} else {
|
|
|
|
store = htonl(uid);
|
|
|
|
memcpy(&keybuf[1], &store, sizeof(store));
|
|
|
|
key.size = sizeof(store) + 1;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case nss_lt_all:
|
|
|
|
st->keynum++;
|
|
|
|
if (st->version < _PWD_CURRENT_VERSION) {
|
|
|
|
memcpy(&keybuf[1], &st->keynum,
|
|
|
|
sizeof(st->keynum));
|
|
|
|
key.size = sizeof(st->keynum) + 1;
|
|
|
|
} else {
|
|
|
|
store = htonl(st->keynum);
|
|
|
|
memcpy(&keybuf[1], &store, sizeof(store));
|
|
|
|
key.size = sizeof(store) + 1;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2003-04-18 14:11:17 +00:00
|
|
|
keybuf[0] = _PW_VERSIONED(keybuf[0], st->version);
|
2003-04-17 14:15:26 +00:00
|
|
|
rv = st->db->get(st->db, &key, &entry, 0);
|
|
|
|
if (rv < 0 || rv > 1) { /* should never return > 1 */
|
|
|
|
*errnop = errno;
|
|
|
|
rv = NS_UNAVAIL;
|
|
|
|
goto fin;
|
|
|
|
} else if (rv == 1) {
|
|
|
|
if (how == nss_lt_all)
|
|
|
|
st->keynum = -1;
|
|
|
|
rv = NS_NOTFOUND;
|
|
|
|
goto fin;
|
|
|
|
}
|
|
|
|
rv = pwdb_versions[st->version].match(entry.data, entry.size,
|
|
|
|
how, name, uid);
|
|
|
|
if (rv != NS_SUCCESS)
|
|
|
|
continue;
|
|
|
|
if (entry.size > bufsize) {
|
|
|
|
*errnop = ERANGE;
|
|
|
|
rv = NS_RETURN;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
memcpy(buffer, entry.data, entry.size);
|
|
|
|
rv = pwdb_versions[st->version].parse(buffer, entry.size, pwd,
|
|
|
|
errnop);
|
|
|
|
} while (how == nss_lt_all && !(rv & NS_TERMINATE));
|
|
|
|
fin:
|
|
|
|
if (!stayopen && st->db != NULL) {
|
|
|
|
(void)st->db->close(st->db);
|
|
|
|
st->db = NULL;
|
|
|
|
}
|
2003-04-18 16:24:25 +00:00
|
|
|
if (rv == NS_SUCCESS) {
|
|
|
|
pwd->pw_fields &= ~_PWF_SOURCE;
|
|
|
|
pwd->pw_fields |= _PWF_FILES;
|
|
|
|
if (retval != NULL)
|
|
|
|
*(struct passwd **)retval = pwd;
|
|
|
|
}
|
2003-04-17 14:15:26 +00:00
|
|
|
return (rv);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static int
|
2004-01-12 13:33:24 +00:00
|
|
|
pwdb_match_entry_v3(char *entry, size_t entrysize, enum nss_lookup_type how,
|
2003-04-17 14:15:26 +00:00
|
|
|
const char *name, uid_t uid)
|
|
|
|
{
|
|
|
|
const char *p, *eom;
|
|
|
|
uid_t uid2;
|
|
|
|
|
|
|
|
eom = &entry[entrysize];
|
|
|
|
for (p = entry; p < eom; p++)
|
|
|
|
if (*p == '\0')
|
|
|
|
break;
|
|
|
|
if (*p != '\0')
|
|
|
|
return (NS_NOTFOUND);
|
|
|
|
if (how == nss_lt_all)
|
|
|
|
return (NS_SUCCESS);
|
2004-01-12 13:33:24 +00:00
|
|
|
if (how == nss_lt_name)
|
2003-04-17 14:15:26 +00:00
|
|
|
return (strcmp(name, entry) == 0 ? NS_SUCCESS : NS_NOTFOUND);
|
|
|
|
for (p++; p < eom; p++)
|
|
|
|
if (*p == '\0')
|
|
|
|
break;
|
|
|
|
if (*p != '\0' || (++p) + sizeof(uid) >= eom)
|
|
|
|
return (NS_NOTFOUND);
|
|
|
|
memcpy(&uid2, p, sizeof(uid2));
|
|
|
|
return (uid == uid2 ? NS_SUCCESS : NS_NOTFOUND);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static int
|
|
|
|
pwdb_parse_entry_v3(char *buffer, size_t bufsize, struct passwd *pwd,
|
|
|
|
int *errnop)
|
|
|
|
{
|
|
|
|
char *p, *eom;
|
|
|
|
int32_t pw_change, pw_expire;
|
|
|
|
|
|
|
|
/* THIS CODE MUST MATCH THAT IN pwd_mkdb. */
|
|
|
|
p = buffer;
|
|
|
|
eom = &buffer[bufsize];
|
|
|
|
#define STRING(field) do { \
|
|
|
|
(field) = p; \
|
|
|
|
while (p < eom && *p != '\0') \
|
|
|
|
p++; \
|
|
|
|
if (p >= eom) \
|
|
|
|
return (NS_NOTFOUND); \
|
|
|
|
p++; \
|
|
|
|
} while (0)
|
|
|
|
#define SCALAR(field) do { \
|
|
|
|
if (p + sizeof(field) > eom) \
|
|
|
|
return (NS_NOTFOUND); \
|
|
|
|
memcpy(&(field), p, sizeof(field)); \
|
|
|
|
p += sizeof(field); \
|
|
|
|
} while (0)
|
|
|
|
STRING(pwd->pw_name);
|
|
|
|
STRING(pwd->pw_passwd);
|
|
|
|
SCALAR(pwd->pw_uid);
|
|
|
|
SCALAR(pwd->pw_gid);
|
|
|
|
SCALAR(pw_change);
|
|
|
|
STRING(pwd->pw_class);
|
|
|
|
STRING(pwd->pw_gecos);
|
|
|
|
STRING(pwd->pw_dir);
|
|
|
|
STRING(pwd->pw_shell);
|
|
|
|
SCALAR(pw_expire);
|
|
|
|
SCALAR(pwd->pw_fields);
|
|
|
|
#undef STRING
|
|
|
|
#undef SCALAR
|
|
|
|
pwd->pw_change = pw_change;
|
|
|
|
pwd->pw_expire = pw_expire;
|
|
|
|
return (NS_SUCCESS);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static int
|
2004-01-12 13:33:24 +00:00
|
|
|
pwdb_match_entry_v4(char *entry, size_t entrysize, enum nss_lookup_type how,
|
2003-04-17 14:15:26 +00:00
|
|
|
const char *name, uid_t uid)
|
|
|
|
{
|
|
|
|
const char *p, *eom;
|
|
|
|
uint32_t uid2;
|
|
|
|
|
|
|
|
eom = &entry[entrysize];
|
|
|
|
for (p = entry; p < eom; p++)
|
|
|
|
if (*p == '\0')
|
|
|
|
break;
|
|
|
|
if (*p != '\0')
|
|
|
|
return (NS_NOTFOUND);
|
|
|
|
if (how == nss_lt_all)
|
|
|
|
return (NS_SUCCESS);
|
2004-01-12 13:33:24 +00:00
|
|
|
if (how == nss_lt_name)
|
2003-04-17 14:15:26 +00:00
|
|
|
return (strcmp(name, entry) == 0 ? NS_SUCCESS : NS_NOTFOUND);
|
|
|
|
for (p++; p < eom; p++)
|
|
|
|
if (*p == '\0')
|
|
|
|
break;
|
|
|
|
if (*p != '\0' || (++p) + sizeof(uid) >= eom)
|
|
|
|
return (NS_NOTFOUND);
|
|
|
|
memcpy(&uid2, p, sizeof(uid2));
|
|
|
|
uid2 = ntohl(uid2);
|
|
|
|
return (uid == (uid_t)uid2 ? NS_SUCCESS : NS_NOTFOUND);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static int
|
|
|
|
pwdb_parse_entry_v4(char *buffer, size_t bufsize, struct passwd *pwd,
|
|
|
|
int *errnop)
|
|
|
|
{
|
|
|
|
char *p, *eom;
|
|
|
|
uint32_t n;
|
|
|
|
|
|
|
|
/* THIS CODE MUST MATCH THAT IN pwd_mkdb. */
|
|
|
|
p = buffer;
|
|
|
|
eom = &buffer[bufsize];
|
|
|
|
#define STRING(field) do { \
|
|
|
|
(field) = p; \
|
|
|
|
while (p < eom && *p != '\0') \
|
|
|
|
p++; \
|
|
|
|
if (p >= eom) \
|
|
|
|
return (NS_NOTFOUND); \
|
|
|
|
p++; \
|
|
|
|
} while (0)
|
|
|
|
#define SCALAR(field) do { \
|
|
|
|
if (p + sizeof(n) > eom) \
|
|
|
|
return (NS_NOTFOUND); \
|
|
|
|
memcpy(&n, p, sizeof(n)); \
|
|
|
|
(field) = ntohl(n); \
|
|
|
|
p += sizeof(n); \
|
|
|
|
} while (0)
|
|
|
|
STRING(pwd->pw_name);
|
|
|
|
STRING(pwd->pw_passwd);
|
|
|
|
SCALAR(pwd->pw_uid);
|
|
|
|
SCALAR(pwd->pw_gid);
|
|
|
|
SCALAR(pwd->pw_change);
|
|
|
|
STRING(pwd->pw_class);
|
|
|
|
STRING(pwd->pw_gecos);
|
|
|
|
STRING(pwd->pw_dir);
|
|
|
|
STRING(pwd->pw_shell);
|
|
|
|
SCALAR(pwd->pw_expire);
|
|
|
|
SCALAR(pwd->pw_fields);
|
|
|
|
#undef STRING
|
|
|
|
#undef SCALAR
|
|
|
|
return (NS_SUCCESS);
|
1996-04-16 00:22:41 +00:00
|
|
|
}
|
|
|
|
|
2003-04-17 14:15:26 +00:00
|
|
|
|
Add nsswitch support. By creating an /etc/nsswitch.conf file, you can
configure FreeBSD so that various databases such as passwd and group can be
looked up using flat files, NIS, or Hesiod.
= Hesiod has been added to libc (see hesiod(3)).
= A library routine for parsing nsswitch.conf and invoking callback
functions as specified has been added to libc (see nsdispatch(3)).
= The following C library functions have been modified to use nsdispatch:
. getgrent, getgrnam, getgrgid
. getpwent, getpwnam, getpwuid
. getusershell
. getaddrinfo
. gethostbyname, gethostbyname2, gethostbyaddr
. getnetbyname, getnetbyaddr
. getipnodebyname, getipnodebyaddr, getnodebyname, getnodebyaddr
= host.conf has been removed from src/etc. rc.network has been modified
to warn that host.conf is no longer used at boot time. In addition, if
there is a host.conf but no nsswitch.conf, the latter is created at boot
time from the former.
Obtained from: NetBSD
2000-09-06 18:16:48 +00:00
|
|
|
#ifdef HESIOD
|
1996-04-16 00:22:41 +00:00
|
|
|
/*
|
2003-04-17 14:15:26 +00:00
|
|
|
* dns backend
|
1996-04-16 00:22:41 +00:00
|
|
|
*/
|
2003-04-17 14:15:26 +00:00
|
|
|
static void
|
|
|
|
dns_endstate(void *p)
|
|
|
|
{
|
|
|
|
free(p);
|
|
|
|
}
|
|
|
|
|
1996-04-16 00:22:41 +00:00
|
|
|
|
Add nsswitch support. By creating an /etc/nsswitch.conf file, you can
configure FreeBSD so that various databases such as passwd and group can be
looked up using flat files, NIS, or Hesiod.
= Hesiod has been added to libc (see hesiod(3)).
= A library routine for parsing nsswitch.conf and invoking callback
functions as specified has been added to libc (see nsdispatch(3)).
= The following C library functions have been modified to use nsdispatch:
. getgrent, getgrnam, getgrgid
. getpwent, getpwnam, getpwuid
. getusershell
. getaddrinfo
. gethostbyname, gethostbyname2, gethostbyaddr
. getnetbyname, getnetbyaddr
. getipnodebyname, getipnodebyaddr, getnodebyname, getnodebyaddr
= host.conf has been removed from src/etc. rc.network has been modified
to warn that host.conf is no longer used at boot time. In addition, if
there is a host.conf but no nsswitch.conf, the latter is created at boot
time from the former.
Obtained from: NetBSD
2000-09-06 18:16:48 +00:00
|
|
|
static int
|
2003-04-17 14:15:26 +00:00
|
|
|
dns_setpwent(void *retval, void *mdata, va_list ap)
|
Add nsswitch support. By creating an /etc/nsswitch.conf file, you can
configure FreeBSD so that various databases such as passwd and group can be
looked up using flat files, NIS, or Hesiod.
= Hesiod has been added to libc (see hesiod(3)).
= A library routine for parsing nsswitch.conf and invoking callback
functions as specified has been added to libc (see nsdispatch(3)).
= The following C library functions have been modified to use nsdispatch:
. getgrent, getgrnam, getgrgid
. getpwent, getpwnam, getpwuid
. getusershell
. getaddrinfo
. gethostbyname, gethostbyname2, gethostbyaddr
. getnetbyname, getnetbyaddr
. getipnodebyname, getipnodebyaddr, getnodebyname, getnodebyaddr
= host.conf has been removed from src/etc. rc.network has been modified
to warn that host.conf is no longer used at boot time. In addition, if
there is a host.conf but no nsswitch.conf, the latter is created at boot
time from the former.
Obtained from: NetBSD
2000-09-06 18:16:48 +00:00
|
|
|
{
|
2003-04-17 14:15:26 +00:00
|
|
|
struct dns_state *st;
|
|
|
|
int rv;
|
|
|
|
|
|
|
|
rv = dns_getstate(&st);
|
|
|
|
if (rv != 0)
|
|
|
|
return (NS_UNAVAIL);
|
|
|
|
st->counter = 0;
|
|
|
|
return (NS_UNAVAIL);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static int
|
|
|
|
dns_passwd(void *retval, void *mdata, va_list ap)
|
|
|
|
{
|
|
|
|
char buf[HESIOD_NAME_MAX];
|
|
|
|
struct dns_state *st;
|
|
|
|
struct passwd *pwd;
|
|
|
|
const char *name, *label;
|
|
|
|
void *ctx;
|
|
|
|
char *buffer, **hes;
|
|
|
|
size_t bufsize, linesize;
|
|
|
|
uid_t uid;
|
|
|
|
enum nss_lookup_type how;
|
|
|
|
int rv, *errnop;
|
|
|
|
|
|
|
|
ctx = NULL;
|
|
|
|
hes = NULL;
|
|
|
|
name = NULL;
|
|
|
|
uid = (uid_t)-1;
|
|
|
|
how = (enum nss_lookup_type)mdata;
|
|
|
|
switch (how) {
|
|
|
|
case nss_lt_name:
|
Add nsswitch support. By creating an /etc/nsswitch.conf file, you can
configure FreeBSD so that various databases such as passwd and group can be
looked up using flat files, NIS, or Hesiod.
= Hesiod has been added to libc (see hesiod(3)).
= A library routine for parsing nsswitch.conf and invoking callback
functions as specified has been added to libc (see nsdispatch(3)).
= The following C library functions have been modified to use nsdispatch:
. getgrent, getgrnam, getgrgid
. getpwent, getpwnam, getpwuid
. getusershell
. getaddrinfo
. gethostbyname, gethostbyname2, gethostbyaddr
. getnetbyname, getnetbyaddr
. getipnodebyname, getipnodebyaddr, getnodebyname, getnodebyaddr
= host.conf has been removed from src/etc. rc.network has been modified
to warn that host.conf is no longer used at boot time. In addition, if
there is a host.conf but no nsswitch.conf, the latter is created at boot
time from the former.
Obtained from: NetBSD
2000-09-06 18:16:48 +00:00
|
|
|
name = va_arg(ap, const char *);
|
|
|
|
break;
|
2003-04-17 14:15:26 +00:00
|
|
|
case nss_lt_id:
|
Add nsswitch support. By creating an /etc/nsswitch.conf file, you can
configure FreeBSD so that various databases such as passwd and group can be
looked up using flat files, NIS, or Hesiod.
= Hesiod has been added to libc (see hesiod(3)).
= A library routine for parsing nsswitch.conf and invoking callback
functions as specified has been added to libc (see nsdispatch(3)).
= The following C library functions have been modified to use nsdispatch:
. getgrent, getgrnam, getgrgid
. getpwent, getpwnam, getpwuid
. getusershell
. getaddrinfo
. gethostbyname, gethostbyname2, gethostbyaddr
. getnetbyname, getnetbyaddr
. getipnodebyname, getipnodebyaddr, getnodebyname, getnodebyaddr
= host.conf has been removed from src/etc. rc.network has been modified
to warn that host.conf is no longer used at boot time. In addition, if
there is a host.conf but no nsswitch.conf, the latter is created at boot
time from the former.
Obtained from: NetBSD
2000-09-06 18:16:48 +00:00
|
|
|
uid = va_arg(ap, uid_t);
|
|
|
|
break;
|
2003-04-17 14:15:26 +00:00
|
|
|
case nss_lt_all:
|
|
|
|
break;
|
Add nsswitch support. By creating an /etc/nsswitch.conf file, you can
configure FreeBSD so that various databases such as passwd and group can be
looked up using flat files, NIS, or Hesiod.
= Hesiod has been added to libc (see hesiod(3)).
= A library routine for parsing nsswitch.conf and invoking callback
functions as specified has been added to libc (see nsdispatch(3)).
= The following C library functions have been modified to use nsdispatch:
. getgrent, getgrnam, getgrgid
. getpwent, getpwnam, getpwuid
. getusershell
. getaddrinfo
. gethostbyname, gethostbyname2, gethostbyaddr
. getnetbyname, getnetbyaddr
. getipnodebyname, getipnodebyaddr, getnodebyname, getnodebyaddr
= host.conf has been removed from src/etc. rc.network has been modified
to warn that host.conf is no longer used at boot time. In addition, if
there is a host.conf but no nsswitch.conf, the latter is created at boot
time from the former.
Obtained from: NetBSD
2000-09-06 18:16:48 +00:00
|
|
|
}
|
2003-04-17 14:15:26 +00:00
|
|
|
pwd = va_arg(ap, struct passwd *);
|
|
|
|
buffer = va_arg(ap, char *);
|
|
|
|
bufsize = va_arg(ap, size_t);
|
|
|
|
errnop = va_arg(ap, int *);
|
|
|
|
*errnop = dns_getstate(&st);
|
|
|
|
if (*errnop != 0)
|
|
|
|
return (NS_UNAVAIL);
|
|
|
|
if (hesiod_init(&ctx) != 0) {
|
|
|
|
*errnop = errno;
|
|
|
|
rv = NS_UNAVAIL;
|
|
|
|
goto fin;
|
Add nsswitch support. By creating an /etc/nsswitch.conf file, you can
configure FreeBSD so that various databases such as passwd and group can be
looked up using flat files, NIS, or Hesiod.
= Hesiod has been added to libc (see hesiod(3)).
= A library routine for parsing nsswitch.conf and invoking callback
functions as specified has been added to libc (see nsdispatch(3)).
= The following C library functions have been modified to use nsdispatch:
. getgrent, getgrnam, getgrgid
. getpwent, getpwnam, getpwuid
. getusershell
. getaddrinfo
. gethostbyname, gethostbyname2, gethostbyaddr
. getnetbyname, getnetbyaddr
. getipnodebyname, getipnodebyaddr, getnodebyname, getnodebyaddr
= host.conf has been removed from src/etc. rc.network has been modified
to warn that host.conf is no longer used at boot time. In addition, if
there is a host.conf but no nsswitch.conf, the latter is created at boot
time from the former.
Obtained from: NetBSD
2000-09-06 18:16:48 +00:00
|
|
|
}
|
2003-04-17 14:15:26 +00:00
|
|
|
do {
|
|
|
|
rv = NS_NOTFOUND;
|
|
|
|
switch (how) {
|
|
|
|
case nss_lt_name:
|
|
|
|
label = name;
|
|
|
|
break;
|
|
|
|
case nss_lt_id:
|
|
|
|
if (snprintf(buf, sizeof(buf), "%lu",
|
|
|
|
(unsigned long)uid) >= sizeof(buf))
|
|
|
|
goto fin;
|
|
|
|
label = buf;
|
|
|
|
break;
|
|
|
|
case nss_lt_all:
|
|
|
|
if (st->counter < 0)
|
|
|
|
goto fin;
|
|
|
|
if (snprintf(buf, sizeof(buf), "passwd-%ld",
|
|
|
|
st->counter++) >= sizeof(buf))
|
|
|
|
goto fin;
|
|
|
|
label = buf;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
hes = hesiod_resolve(ctx, label,
|
|
|
|
how == nss_lt_id ? "uid" : "passwd");
|
|
|
|
if (hes == NULL) {
|
|
|
|
if (how == nss_lt_all)
|
|
|
|
st->counter = -1;
|
|
|
|
if (errno != ENOENT)
|
|
|
|
*errnop = errno;
|
|
|
|
goto fin;
|
|
|
|
}
|
|
|
|
rv = __pw_match_entry(hes[0], strlen(hes[0]), how, name, uid);
|
|
|
|
if (rv != NS_SUCCESS) {
|
|
|
|
hesiod_free_list(ctx, hes);
|
|
|
|
hes = NULL;
|
|
|
|
continue;
|
|
|
|
}
|
2003-05-01 19:03:14 +00:00
|
|
|
linesize = strlcpy(buffer, hes[0], bufsize);
|
2003-04-17 14:15:26 +00:00
|
|
|
if (linesize >= bufsize) {
|
|
|
|
*errnop = ERANGE;
|
|
|
|
rv = NS_RETURN;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
hesiod_free_list(ctx, hes);
|
|
|
|
hes = NULL;
|
|
|
|
rv = __pw_parse_entry(buffer, bufsize, pwd, 0, errnop);
|
|
|
|
} while (how == nss_lt_all && !(rv & NS_TERMINATE));
|
|
|
|
fin:
|
|
|
|
if (hes != NULL)
|
|
|
|
hesiod_free_list(ctx, hes);
|
|
|
|
if (ctx != NULL)
|
|
|
|
hesiod_end(ctx);
|
|
|
|
if (rv == NS_SUCCESS) {
|
|
|
|
pwd->pw_fields &= ~_PWF_SOURCE;
|
|
|
|
pwd->pw_fields |= _PWF_HESIOD;
|
|
|
|
if (retval != NULL)
|
|
|
|
*(struct passwd **)retval = pwd;
|
2002-04-14 22:24:55 +00:00
|
|
|
}
|
2003-04-17 14:15:26 +00:00
|
|
|
return (rv);
|
1996-04-16 00:22:41 +00:00
|
|
|
}
|
2003-04-17 14:15:26 +00:00
|
|
|
#endif /* HESIOD */
|
|
|
|
|
1996-04-16 00:22:41 +00:00
|
|
|
|
Add nsswitch support. By creating an /etc/nsswitch.conf file, you can
configure FreeBSD so that various databases such as passwd and group can be
looked up using flat files, NIS, or Hesiod.
= Hesiod has been added to libc (see hesiod(3)).
= A library routine for parsing nsswitch.conf and invoking callback
functions as specified has been added to libc (see nsdispatch(3)).
= The following C library functions have been modified to use nsdispatch:
. getgrent, getgrnam, getgrgid
. getpwent, getpwnam, getpwuid
. getusershell
. getaddrinfo
. gethostbyname, gethostbyname2, gethostbyaddr
. getnetbyname, getnetbyaddr
. getipnodebyname, getipnodebyaddr, getnodebyname, getnodebyaddr
= host.conf has been removed from src/etc. rc.network has been modified
to warn that host.conf is no longer used at boot time. In addition, if
there is a host.conf but no nsswitch.conf, the latter is created at boot
time from the former.
Obtained from: NetBSD
2000-09-06 18:16:48 +00:00
|
|
|
#ifdef YP
|
1996-04-16 00:22:41 +00:00
|
|
|
/*
|
2003-04-17 14:15:26 +00:00
|
|
|
* nis backend
|
1996-04-16 00:22:41 +00:00
|
|
|
*/
|
2003-04-17 14:15:26 +00:00
|
|
|
static void
|
|
|
|
nis_endstate(void *p)
|
|
|
|
{
|
|
|
|
free(((struct nis_state *)p)->key);
|
|
|
|
free(p);
|
|
|
|
}
|
Add nsswitch support. By creating an /etc/nsswitch.conf file, you can
configure FreeBSD so that various databases such as passwd and group can be
looked up using flat files, NIS, or Hesiod.
= Hesiod has been added to libc (see hesiod(3)).
= A library routine for parsing nsswitch.conf and invoking callback
functions as specified has been added to libc (see nsdispatch(3)).
= The following C library functions have been modified to use nsdispatch:
. getgrent, getgrnam, getgrgid
. getpwent, getpwnam, getpwuid
. getusershell
. getaddrinfo
. gethostbyname, gethostbyname2, gethostbyaddr
. getnetbyname, getnetbyaddr
. getipnodebyname, getipnodebyaddr, getnodebyname, getnodebyaddr
= host.conf has been removed from src/etc. rc.network has been modified
to warn that host.conf is no longer used at boot time. In addition, if
there is a host.conf but no nsswitch.conf, the latter is created at boot
time from the former.
Obtained from: NetBSD
2000-09-06 18:16:48 +00:00
|
|
|
|
2003-07-18 23:51:15 +00:00
|
|
|
/*
|
|
|
|
* Test for the presence of special FreeBSD-specific master.passwd.by*
|
|
|
|
* maps. We do this using yp_order(). If it fails, then either the server
|
|
|
|
* doesn't have the map, or the YPPROC_ORDER procedure isn't supported by
|
|
|
|
* the server (Sun NIS+ servers in YP compat mode behave this way). If
|
|
|
|
* the master.passwd.by* maps don't exist, then let the lookup routine try
|
|
|
|
* the regular passwd.by* maps instead. If the lookup routine fails, it
|
|
|
|
* can return an error as needed.
|
|
|
|
*/
|
Add nsswitch support. By creating an /etc/nsswitch.conf file, you can
configure FreeBSD so that various databases such as passwd and group can be
looked up using flat files, NIS, or Hesiod.
= Hesiod has been added to libc (see hesiod(3)).
= A library routine for parsing nsswitch.conf and invoking callback
functions as specified has been added to libc (see nsdispatch(3)).
= The following C library functions have been modified to use nsdispatch:
. getgrent, getgrnam, getgrgid
. getpwent, getpwnam, getpwuid
. getusershell
. getaddrinfo
. gethostbyname, gethostbyname2, gethostbyaddr
. getnetbyname, getnetbyaddr
. getipnodebyname, getipnodebyaddr, getnodebyname, getnodebyaddr
= host.conf has been removed from src/etc. rc.network has been modified
to warn that host.conf is no longer used at boot time. In addition, if
there is a host.conf but no nsswitch.conf, the latter is created at boot
time from the former.
Obtained from: NetBSD
2000-09-06 18:16:48 +00:00
|
|
|
static int
|
2003-04-17 14:15:26 +00:00
|
|
|
nis_map(char *domain, enum nss_lookup_type how, char *buffer, size_t bufsize,
|
|
|
|
int *master)
|
1996-04-16 00:22:41 +00:00
|
|
|
{
|
2003-07-18 23:51:15 +00:00
|
|
|
int rv, order;
|
2003-04-17 14:15:26 +00:00
|
|
|
|
|
|
|
*master = 0;
|
2003-04-21 13:57:58 +00:00
|
|
|
if (geteuid() == 0) {
|
|
|
|
if (snprintf(buffer, bufsize, "master.passwd.by%s",
|
|
|
|
(how == nss_lt_id) ? "uid" : "name") >= bufsize)
|
|
|
|
return (NS_UNAVAIL);
|
2003-07-18 23:51:15 +00:00
|
|
|
rv = yp_order(domain, buffer, &order);
|
2003-04-21 13:57:58 +00:00
|
|
|
if (rv == 0) {
|
|
|
|
*master = 1;
|
|
|
|
return (NS_SUCCESS);
|
|
|
|
}
|
Add nsswitch support. By creating an /etc/nsswitch.conf file, you can
configure FreeBSD so that various databases such as passwd and group can be
looked up using flat files, NIS, or Hesiod.
= Hesiod has been added to libc (see hesiod(3)).
= A library routine for parsing nsswitch.conf and invoking callback
functions as specified has been added to libc (see nsdispatch(3)).
= The following C library functions have been modified to use nsdispatch:
. getgrent, getgrnam, getgrgid
. getpwent, getpwnam, getpwuid
. getusershell
. getaddrinfo
. gethostbyname, gethostbyname2, gethostbyaddr
. getnetbyname, getnetbyaddr
. getipnodebyname, getipnodebyaddr, getnodebyname, getnodebyaddr
= host.conf has been removed from src/etc. rc.network has been modified
to warn that host.conf is no longer used at boot time. In addition, if
there is a host.conf but no nsswitch.conf, the latter is created at boot
time from the former.
Obtained from: NetBSD
2000-09-06 18:16:48 +00:00
|
|
|
}
|
2003-07-18 23:51:15 +00:00
|
|
|
|
2003-04-17 14:15:26 +00:00
|
|
|
if (snprintf(buffer, bufsize, "passwd.by%s",
|
|
|
|
(how == nss_lt_id) ? "uid" : "name") >= bufsize)
|
|
|
|
return (NS_UNAVAIL);
|
2003-07-18 23:51:15 +00:00
|
|
|
|
|
|
|
return (NS_SUCCESS);
|
2003-04-17 14:15:26 +00:00
|
|
|
}
|
Add nsswitch support. By creating an /etc/nsswitch.conf file, you can
configure FreeBSD so that various databases such as passwd and group can be
looked up using flat files, NIS, or Hesiod.
= Hesiod has been added to libc (see hesiod(3)).
= A library routine for parsing nsswitch.conf and invoking callback
functions as specified has been added to libc (see nsdispatch(3)).
= The following C library functions have been modified to use nsdispatch:
. getgrent, getgrnam, getgrgid
. getpwent, getpwnam, getpwuid
. getusershell
. getaddrinfo
. gethostbyname, gethostbyname2, gethostbyaddr
. getnetbyname, getnetbyaddr
. getipnodebyname, getipnodebyaddr, getnodebyname, getnodebyaddr
= host.conf has been removed from src/etc. rc.network has been modified
to warn that host.conf is no longer used at boot time. In addition, if
there is a host.conf but no nsswitch.conf, the latter is created at boot
time from the former.
Obtained from: NetBSD
2000-09-06 18:16:48 +00:00
|
|
|
|
2003-04-17 14:15:26 +00:00
|
|
|
|
|
|
|
static int
|
|
|
|
nis_adjunct(char *domain, const char *name, char *buffer, size_t bufsize)
|
|
|
|
{
|
|
|
|
int rv;
|
|
|
|
char *result, *p, *q, *eor;
|
|
|
|
int resultlen;
|
|
|
|
|
|
|
|
result = NULL;
|
|
|
|
rv = yp_match(domain, "passwd.adjunct.byname", name, strlen(name),
|
|
|
|
&result, &resultlen);
|
|
|
|
if (rv != 0)
|
|
|
|
rv = 1;
|
|
|
|
else {
|
|
|
|
eor = &result[resultlen];
|
|
|
|
p = memchr(result, ':', eor - result);
|
|
|
|
if (p != NULL && ++p < eor &&
|
|
|
|
(q = memchr(p, ':', eor - p)) != NULL) {
|
|
|
|
if (q - p >= bufsize)
|
|
|
|
rv = -1;
|
|
|
|
else {
|
|
|
|
memcpy(buffer, p, q - p);
|
|
|
|
buffer[q - p] ='\0';
|
|
|
|
}
|
|
|
|
} else
|
|
|
|
rv = 1;
|
2004-01-12 13:33:24 +00:00
|
|
|
}
|
2003-04-17 14:15:26 +00:00
|
|
|
free(result);
|
|
|
|
return (rv);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static int
|
|
|
|
nis_setpwent(void *retval, void *mdata, va_list ap)
|
|
|
|
{
|
|
|
|
struct nis_state *st;
|
|
|
|
int rv;
|
|
|
|
|
|
|
|
rv = nis_getstate(&st);
|
|
|
|
if (rv != 0)
|
|
|
|
return (NS_UNAVAIL);
|
|
|
|
st->done = 0;
|
|
|
|
free(st->key);
|
|
|
|
st->key = NULL;
|
|
|
|
return (NS_UNAVAIL);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static int
|
|
|
|
nis_passwd(void *retval, void *mdata, va_list ap)
|
|
|
|
{
|
|
|
|
char map[YPMAXMAP];
|
|
|
|
struct nis_state *st;
|
|
|
|
struct passwd *pwd;
|
|
|
|
const char *name;
|
|
|
|
char *buffer, *key, *result;
|
|
|
|
size_t bufsize;
|
|
|
|
uid_t uid;
|
|
|
|
enum nss_lookup_type how;
|
|
|
|
int *errnop, keylen, resultlen, rv, master;
|
2004-01-12 13:33:24 +00:00
|
|
|
|
2003-04-17 14:15:26 +00:00
|
|
|
name = NULL;
|
|
|
|
uid = (uid_t)-1;
|
|
|
|
how = (enum nss_lookup_type)mdata;
|
|
|
|
switch (how) {
|
|
|
|
case nss_lt_name:
|
Add nsswitch support. By creating an /etc/nsswitch.conf file, you can
configure FreeBSD so that various databases such as passwd and group can be
looked up using flat files, NIS, or Hesiod.
= Hesiod has been added to libc (see hesiod(3)).
= A library routine for parsing nsswitch.conf and invoking callback
functions as specified has been added to libc (see nsdispatch(3)).
= The following C library functions have been modified to use nsdispatch:
. getgrent, getgrnam, getgrgid
. getpwent, getpwnam, getpwuid
. getusershell
. getaddrinfo
. gethostbyname, gethostbyname2, gethostbyaddr
. getnetbyname, getnetbyaddr
. getipnodebyname, getipnodebyaddr, getnodebyname, getnodebyaddr
= host.conf has been removed from src/etc. rc.network has been modified
to warn that host.conf is no longer used at boot time. In addition, if
there is a host.conf but no nsswitch.conf, the latter is created at boot
time from the former.
Obtained from: NetBSD
2000-09-06 18:16:48 +00:00
|
|
|
name = va_arg(ap, const char *);
|
|
|
|
break;
|
2003-04-17 14:15:26 +00:00
|
|
|
case nss_lt_id:
|
Add nsswitch support. By creating an /etc/nsswitch.conf file, you can
configure FreeBSD so that various databases such as passwd and group can be
looked up using flat files, NIS, or Hesiod.
= Hesiod has been added to libc (see hesiod(3)).
= A library routine for parsing nsswitch.conf and invoking callback
functions as specified has been added to libc (see nsdispatch(3)).
= The following C library functions have been modified to use nsdispatch:
. getgrent, getgrnam, getgrgid
. getpwent, getpwnam, getpwuid
. getusershell
. getaddrinfo
. gethostbyname, gethostbyname2, gethostbyaddr
. getnetbyname, getnetbyaddr
. getipnodebyname, getipnodebyaddr, getnodebyname, getnodebyaddr
= host.conf has been removed from src/etc. rc.network has been modified
to warn that host.conf is no longer used at boot time. In addition, if
there is a host.conf but no nsswitch.conf, the latter is created at boot
time from the former.
Obtained from: NetBSD
2000-09-06 18:16:48 +00:00
|
|
|
uid = va_arg(ap, uid_t);
|
|
|
|
break;
|
2003-04-17 14:15:26 +00:00
|
|
|
case nss_lt_all:
|
|
|
|
break;
|
Add nsswitch support. By creating an /etc/nsswitch.conf file, you can
configure FreeBSD so that various databases such as passwd and group can be
looked up using flat files, NIS, or Hesiod.
= Hesiod has been added to libc (see hesiod(3)).
= A library routine for parsing nsswitch.conf and invoking callback
functions as specified has been added to libc (see nsdispatch(3)).
= The following C library functions have been modified to use nsdispatch:
. getgrent, getgrnam, getgrgid
. getpwent, getpwnam, getpwuid
. getusershell
. getaddrinfo
. gethostbyname, gethostbyname2, gethostbyaddr
. getnetbyname, getnetbyaddr
. getipnodebyname, getipnodebyaddr, getnodebyname, getnodebyaddr
= host.conf has been removed from src/etc. rc.network has been modified
to warn that host.conf is no longer used at boot time. In addition, if
there is a host.conf but no nsswitch.conf, the latter is created at boot
time from the former.
Obtained from: NetBSD
2000-09-06 18:16:48 +00:00
|
|
|
}
|
2003-04-17 14:15:26 +00:00
|
|
|
pwd = va_arg(ap, struct passwd *);
|
|
|
|
buffer = va_arg(ap, char *);
|
|
|
|
bufsize = va_arg(ap, size_t);
|
|
|
|
errnop = va_arg(ap, int *);
|
|
|
|
*errnop = nis_getstate(&st);
|
|
|
|
if (*errnop != 0)
|
|
|
|
return (NS_UNAVAIL);
|
|
|
|
if (st->domain[0] == '\0') {
|
|
|
|
if (getdomainname(st->domain, sizeof(st->domain)) != 0) {
|
|
|
|
*errnop = errno;
|
|
|
|
return (NS_UNAVAIL);
|
1996-04-16 00:22:41 +00:00
|
|
|
}
|
Add nsswitch support. By creating an /etc/nsswitch.conf file, you can
configure FreeBSD so that various databases such as passwd and group can be
looked up using flat files, NIS, or Hesiod.
= Hesiod has been added to libc (see hesiod(3)).
= A library routine for parsing nsswitch.conf and invoking callback
functions as specified has been added to libc (see nsdispatch(3)).
= The following C library functions have been modified to use nsdispatch:
. getgrent, getgrnam, getgrgid
. getpwent, getpwnam, getpwuid
. getusershell
. getaddrinfo
. gethostbyname, gethostbyname2, gethostbyaddr
. getnetbyname, getnetbyaddr
. getipnodebyname, getipnodebyaddr, getnodebyname, getnodebyaddr
= host.conf has been removed from src/etc. rc.network has been modified
to warn that host.conf is no longer used at boot time. In addition, if
there is a host.conf but no nsswitch.conf, the latter is created at boot
time from the former.
Obtained from: NetBSD
2000-09-06 18:16:48 +00:00
|
|
|
}
|
2003-04-17 14:15:26 +00:00
|
|
|
rv = nis_map(st->domain, how, map, sizeof(map), &master);
|
|
|
|
if (rv != NS_SUCCESS)
|
|
|
|
return (rv);
|
|
|
|
result = NULL;
|
|
|
|
do {
|
|
|
|
rv = NS_NOTFOUND;
|
|
|
|
switch (how) {
|
|
|
|
case nss_lt_name:
|
2003-05-01 19:03:14 +00:00
|
|
|
if (strlcpy(buffer, name, bufsize) >= bufsize)
|
2003-04-17 14:15:26 +00:00
|
|
|
goto erange;
|
|
|
|
break;
|
|
|
|
case nss_lt_id:
|
|
|
|
if (snprintf(buffer, bufsize, "%lu",
|
|
|
|
(unsigned long)uid) >= bufsize)
|
|
|
|
goto erange;
|
|
|
|
break;
|
|
|
|
case nss_lt_all:
|
|
|
|
if (st->done)
|
|
|
|
goto fin;
|
|
|
|
break;
|
1995-03-23 00:59:15 +00:00
|
|
|
}
|
2003-04-17 14:15:26 +00:00
|
|
|
result = NULL;
|
|
|
|
if (how == nss_lt_all) {
|
|
|
|
if (st->key == NULL)
|
|
|
|
rv = yp_first(st->domain, map, &st->key,
|
|
|
|
&st->keylen, &result, &resultlen);
|
|
|
|
else {
|
|
|
|
key = st->key;
|
|
|
|
keylen = st->keylen;
|
|
|
|
st->key = NULL;
|
|
|
|
rv = yp_next(st->domain, map, key, keylen,
|
|
|
|
&st->key, &st->keylen, &result,
|
|
|
|
&resultlen);
|
Add nsswitch support. By creating an /etc/nsswitch.conf file, you can
configure FreeBSD so that various databases such as passwd and group can be
looked up using flat files, NIS, or Hesiod.
= Hesiod has been added to libc (see hesiod(3)).
= A library routine for parsing nsswitch.conf and invoking callback
functions as specified has been added to libc (see nsdispatch(3)).
= The following C library functions have been modified to use nsdispatch:
. getgrent, getgrnam, getgrgid
. getpwent, getpwnam, getpwuid
. getusershell
. getaddrinfo
. gethostbyname, gethostbyname2, gethostbyaddr
. getnetbyname, getnetbyaddr
. getipnodebyname, getipnodebyaddr, getnodebyname, getnodebyaddr
= host.conf has been removed from src/etc. rc.network has been modified
to warn that host.conf is no longer used at boot time. In addition, if
there is a host.conf but no nsswitch.conf, the latter is created at boot
time from the former.
Obtained from: NetBSD
2000-09-06 18:16:48 +00:00
|
|
|
free(key);
|
2003-04-17 14:15:26 +00:00
|
|
|
}
|
|
|
|
if (rv != 0) {
|
|
|
|
free(result);
|
|
|
|
free(st->key);
|
|
|
|
st->key = NULL;
|
|
|
|
if (rv == YPERR_NOMORE)
|
|
|
|
st->done = 1;
|
|
|
|
else
|
|
|
|
rv = NS_UNAVAIL;
|
|
|
|
goto fin;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
rv = yp_match(st->domain, map, buffer, strlen(buffer),
|
|
|
|
&result, &resultlen);
|
|
|
|
if (rv == YPERR_KEY) {
|
|
|
|
rv = NS_NOTFOUND;
|
|
|
|
continue;
|
|
|
|
} else if (rv != 0) {
|
|
|
|
free(result);
|
|
|
|
rv = NS_UNAVAIL;
|
|
|
|
continue;
|
|
|
|
}
|
1995-03-23 00:59:15 +00:00
|
|
|
}
|
2003-04-17 14:15:26 +00:00
|
|
|
if (resultlen >= bufsize)
|
|
|
|
goto erange;
|
|
|
|
memcpy(buffer, result, resultlen);
|
|
|
|
buffer[resultlen] = '\0';
|
|
|
|
free(result);
|
|
|
|
rv = __pw_match_entry(buffer, resultlen, how, name, uid);
|
|
|
|
if (rv == NS_SUCCESS)
|
|
|
|
rv = __pw_parse_entry(buffer, resultlen, pwd, master,
|
|
|
|
errnop);
|
|
|
|
} while (how == nss_lt_all && !(rv & NS_TERMINATE));
|
2004-01-12 13:33:24 +00:00
|
|
|
fin:
|
2003-04-17 14:15:26 +00:00
|
|
|
if (rv == NS_SUCCESS) {
|
|
|
|
if (strstr(pwd->pw_passwd, "##") != NULL) {
|
2004-01-12 13:29:54 +00:00
|
|
|
rv = nis_adjunct(st->domain, pwd->pw_name,
|
2003-04-17 14:15:26 +00:00
|
|
|
&buffer[resultlen+1], bufsize-resultlen-1);
|
|
|
|
if (rv < 0)
|
|
|
|
goto erange;
|
|
|
|
else if (rv == 0)
|
|
|
|
pwd->pw_passwd = &buffer[resultlen+1];
|
2002-04-14 22:24:55 +00:00
|
|
|
}
|
2003-04-17 14:15:26 +00:00
|
|
|
pwd->pw_fields &= ~_PWF_SOURCE;
|
|
|
|
pwd->pw_fields |= _PWF_NIS;
|
|
|
|
if (retval != NULL)
|
|
|
|
*(struct passwd **)retval = pwd;
|
2004-04-21 21:15:08 +00:00
|
|
|
rv = NS_SUCCESS;
|
1995-03-23 00:59:15 +00:00
|
|
|
}
|
2004-01-12 13:33:24 +00:00
|
|
|
return (rv);
|
2003-04-17 14:15:26 +00:00
|
|
|
erange:
|
|
|
|
*errnop = ERANGE;
|
|
|
|
return (NS_RETURN);
|
|
|
|
}
|
|
|
|
#endif /* YP */
|
|
|
|
|
1995-03-23 00:59:15 +00:00
|
|
|
|
|
|
|
/*
|
2003-04-17 14:15:26 +00:00
|
|
|
* compat backend
|
1995-03-23 00:59:15 +00:00
|
|
|
*/
|
2003-04-17 14:15:26 +00:00
|
|
|
static void
|
|
|
|
compat_clear_template(struct passwd *template)
|
1995-03-23 00:59:15 +00:00
|
|
|
{
|
2003-04-17 14:15:26 +00:00
|
|
|
|
|
|
|
free(template->pw_passwd);
|
|
|
|
free(template->pw_gecos);
|
|
|
|
free(template->pw_dir);
|
|
|
|
free(template->pw_shell);
|
|
|
|
memset(template, 0, sizeof(*template));
|
1995-03-23 00:59:15 +00:00
|
|
|
}
|
|
|
|
|
1996-04-16 00:22:41 +00:00
|
|
|
|
Add nsswitch support. By creating an /etc/nsswitch.conf file, you can
configure FreeBSD so that various databases such as passwd and group can be
looked up using flat files, NIS, or Hesiod.
= Hesiod has been added to libc (see hesiod(3)).
= A library routine for parsing nsswitch.conf and invoking callback
functions as specified has been added to libc (see nsdispatch(3)).
= The following C library functions have been modified to use nsdispatch:
. getgrent, getgrnam, getgrgid
. getpwent, getpwnam, getpwuid
. getusershell
. getaddrinfo
. gethostbyname, gethostbyname2, gethostbyaddr
. getnetbyname, getnetbyaddr
. getipnodebyname, getipnodebyaddr, getnodebyname, getnodebyaddr
= host.conf has been removed from src/etc. rc.network has been modified
to warn that host.conf is no longer used at boot time. In addition, if
there is a host.conf but no nsswitch.conf, the latter is created at boot
time from the former.
Obtained from: NetBSD
2000-09-06 18:16:48 +00:00
|
|
|
static int
|
2003-04-17 14:15:26 +00:00
|
|
|
compat_set_template(struct passwd *src, struct passwd *template)
|
Add nsswitch support. By creating an /etc/nsswitch.conf file, you can
configure FreeBSD so that various databases such as passwd and group can be
looked up using flat files, NIS, or Hesiod.
= Hesiod has been added to libc (see hesiod(3)).
= A library routine for parsing nsswitch.conf and invoking callback
functions as specified has been added to libc (see nsdispatch(3)).
= The following C library functions have been modified to use nsdispatch:
. getgrent, getgrnam, getgrgid
. getpwent, getpwnam, getpwuid
. getusershell
. getaddrinfo
. gethostbyname, gethostbyname2, gethostbyaddr
. getnetbyname, getnetbyaddr
. getipnodebyname, getipnodebyaddr, getnodebyname, getnodebyaddr
= host.conf has been removed from src/etc. rc.network has been modified
to warn that host.conf is no longer used at boot time. In addition, if
there is a host.conf but no nsswitch.conf, the latter is created at boot
time from the former.
Obtained from: NetBSD
2000-09-06 18:16:48 +00:00
|
|
|
{
|
2003-04-17 14:15:26 +00:00
|
|
|
|
|
|
|
compat_clear_template(template);
|
|
|
|
#ifdef PW_OVERRIDE_PASSWD
|
|
|
|
if ((src->pw_fields & _PWF_PASSWD) &&
|
|
|
|
(template->pw_passwd = strdup(src->pw_passwd)) == NULL)
|
|
|
|
goto enomem;
|
|
|
|
#endif
|
|
|
|
if (src->pw_fields & _PWF_UID)
|
|
|
|
template->pw_uid = src->pw_uid;
|
|
|
|
if (src->pw_fields & _PWF_GID)
|
|
|
|
template->pw_gid = src->pw_gid;
|
|
|
|
if ((src->pw_fields & _PWF_GECOS) &&
|
|
|
|
(template->pw_gecos = strdup(src->pw_gecos)) == NULL)
|
|
|
|
goto enomem;
|
|
|
|
if ((src->pw_fields & _PWF_DIR) &&
|
|
|
|
(template->pw_dir = strdup(src->pw_dir)) == NULL)
|
|
|
|
goto enomem;
|
|
|
|
if ((src->pw_fields & _PWF_SHELL) &&
|
|
|
|
(template->pw_shell = strdup(src->pw_shell)) == NULL)
|
|
|
|
goto enomem;
|
|
|
|
template->pw_fields = src->pw_fields;
|
|
|
|
return (0);
|
|
|
|
enomem:
|
|
|
|
syslog(LOG_ERR, "getpwent memory allocation failure");
|
|
|
|
return (-1);
|
1995-09-02 04:08:55 +00:00
|
|
|
}
|
1996-12-03 17:55:49 +00:00
|
|
|
|
|
|
|
|
Add nsswitch support. By creating an /etc/nsswitch.conf file, you can
configure FreeBSD so that various databases such as passwd and group can be
looked up using flat files, NIS, or Hesiod.
= Hesiod has been added to libc (see hesiod(3)).
= A library routine for parsing nsswitch.conf and invoking callback
functions as specified has been added to libc (see nsdispatch(3)).
= The following C library functions have been modified to use nsdispatch:
. getgrent, getgrnam, getgrgid
. getpwent, getpwnam, getpwuid
. getusershell
. getaddrinfo
. gethostbyname, gethostbyname2, gethostbyaddr
. getnetbyname, getnetbyaddr
. getipnodebyname, getipnodebyaddr, getnodebyname, getnodebyaddr
= host.conf has been removed from src/etc. rc.network has been modified
to warn that host.conf is no longer used at boot time. In addition, if
there is a host.conf but no nsswitch.conf, the latter is created at boot
time from the former.
Obtained from: NetBSD
2000-09-06 18:16:48 +00:00
|
|
|
static int
|
2003-04-17 14:15:26 +00:00
|
|
|
compat_use_template(struct passwd *pwd, struct passwd *template, char *buffer,
|
|
|
|
size_t bufsize)
|
Add nsswitch support. By creating an /etc/nsswitch.conf file, you can
configure FreeBSD so that various databases such as passwd and group can be
looked up using flat files, NIS, or Hesiod.
= Hesiod has been added to libc (see hesiod(3)).
= A library routine for parsing nsswitch.conf and invoking callback
functions as specified has been added to libc (see nsdispatch(3)).
= The following C library functions have been modified to use nsdispatch:
. getgrent, getgrnam, getgrgid
. getpwent, getpwnam, getpwuid
. getusershell
. getaddrinfo
. gethostbyname, gethostbyname2, gethostbyaddr
. getnetbyname, getnetbyaddr
. getipnodebyname, getipnodebyaddr, getnodebyname, getnodebyaddr
= host.conf has been removed from src/etc. rc.network has been modified
to warn that host.conf is no longer used at boot time. In addition, if
there is a host.conf but no nsswitch.conf, the latter is created at boot
time from the former.
Obtained from: NetBSD
2000-09-06 18:16:48 +00:00
|
|
|
{
|
2003-04-17 14:15:26 +00:00
|
|
|
struct passwd hold;
|
|
|
|
char *copy, *p, *q, *eob;
|
|
|
|
size_t n;
|
Add nsswitch support. By creating an /etc/nsswitch.conf file, you can
configure FreeBSD so that various databases such as passwd and group can be
looked up using flat files, NIS, or Hesiod.
= Hesiod has been added to libc (see hesiod(3)).
= A library routine for parsing nsswitch.conf and invoking callback
functions as specified has been added to libc (see nsdispatch(3)).
= The following C library functions have been modified to use nsdispatch:
. getgrent, getgrnam, getgrgid
. getpwent, getpwnam, getpwuid
. getusershell
. getaddrinfo
. gethostbyname, gethostbyname2, gethostbyaddr
. getnetbyname, getnetbyaddr
. getipnodebyname, getipnodebyaddr, getnodebyname, getnodebyaddr
= host.conf has been removed from src/etc. rc.network has been modified
to warn that host.conf is no longer used at boot time. In addition, if
there is a host.conf but no nsswitch.conf, the latter is created at boot
time from the former.
Obtained from: NetBSD
2000-09-06 18:16:48 +00:00
|
|
|
|
2003-04-17 14:15:26 +00:00
|
|
|
/* We cannot know the layout of the password fields in `buffer',
|
|
|
|
* so we have to copy everything.
|
|
|
|
*/
|
|
|
|
if (template->pw_fields == 0) /* nothing to fill-in */
|
|
|
|
return (0);
|
|
|
|
n = 0;
|
|
|
|
n += pwd->pw_name != NULL ? strlen(pwd->pw_name) + 1 : 0;
|
|
|
|
n += pwd->pw_passwd != NULL ? strlen(pwd->pw_passwd) + 1 : 0;
|
|
|
|
n += pwd->pw_class != NULL ? strlen(pwd->pw_class) + 1 : 0;
|
|
|
|
n += pwd->pw_gecos != NULL ? strlen(pwd->pw_gecos) + 1 : 0;
|
|
|
|
n += pwd->pw_dir != NULL ? strlen(pwd->pw_dir) + 1 : 0;
|
|
|
|
n += pwd->pw_shell != NULL ? strlen(pwd->pw_shell) + 1 : 0;
|
|
|
|
copy = malloc(n);
|
|
|
|
if (copy == NULL) {
|
|
|
|
syslog(LOG_ERR, "getpwent memory allocation failure");
|
|
|
|
return (ENOMEM);
|
Add nsswitch support. By creating an /etc/nsswitch.conf file, you can
configure FreeBSD so that various databases such as passwd and group can be
looked up using flat files, NIS, or Hesiod.
= Hesiod has been added to libc (see hesiod(3)).
= A library routine for parsing nsswitch.conf and invoking callback
functions as specified has been added to libc (see nsdispatch(3)).
= The following C library functions have been modified to use nsdispatch:
. getgrent, getgrnam, getgrgid
. getpwent, getpwnam, getpwuid
. getusershell
. getaddrinfo
. gethostbyname, gethostbyname2, gethostbyaddr
. getnetbyname, getnetbyaddr
. getipnodebyname, getipnodebyaddr, getnodebyname, getnodebyaddr
= host.conf has been removed from src/etc. rc.network has been modified
to warn that host.conf is no longer used at boot time. In addition, if
there is a host.conf but no nsswitch.conf, the latter is created at boot
time from the former.
Obtained from: NetBSD
2000-09-06 18:16:48 +00:00
|
|
|
}
|
2003-04-17 14:15:26 +00:00
|
|
|
p = copy;
|
|
|
|
eob = ©[n];
|
|
|
|
#define COPY(field) do { \
|
|
|
|
if (pwd->field == NULL) \
|
|
|
|
hold.field = NULL; \
|
|
|
|
else { \
|
|
|
|
hold.field = p; \
|
2003-05-01 19:03:14 +00:00
|
|
|
p += strlcpy(p, pwd->field, eob-p) + 1; \
|
2003-04-17 14:15:26 +00:00
|
|
|
} \
|
|
|
|
} while (0)
|
|
|
|
COPY(pw_name);
|
|
|
|
COPY(pw_passwd);
|
|
|
|
COPY(pw_class);
|
|
|
|
COPY(pw_gecos);
|
|
|
|
COPY(pw_dir);
|
|
|
|
COPY(pw_shell);
|
|
|
|
#undef COPY
|
|
|
|
p = buffer;
|
|
|
|
eob = &buffer[bufsize];
|
|
|
|
#define COPY(field, flag) do { \
|
|
|
|
q = (template->pw_fields & flag) ? template->field : hold.field; \
|
|
|
|
if (q == NULL) \
|
|
|
|
pwd->field = NULL; \
|
|
|
|
else { \
|
|
|
|
pwd->field = p; \
|
2003-05-01 19:03:14 +00:00
|
|
|
if ((n = strlcpy(p, q, eob-p)) >= eob-p) { \
|
2003-04-17 14:15:26 +00:00
|
|
|
free(copy); \
|
|
|
|
return (ERANGE); \
|
|
|
|
} \
|
|
|
|
p += n + 1; \
|
|
|
|
} \
|
|
|
|
} while (0)
|
|
|
|
COPY(pw_name, 0);
|
|
|
|
#ifdef PW_OVERRIDE_PASSWD
|
|
|
|
COPY(pw_passwd, _PWF_PASSWD);
|
|
|
|
#else
|
|
|
|
COPY(pw_passwd, 0);
|
|
|
|
#endif
|
|
|
|
COPY(pw_class, 0);
|
|
|
|
COPY(pw_gecos, _PWF_GECOS);
|
|
|
|
COPY(pw_dir, _PWF_DIR);
|
|
|
|
COPY(pw_shell, _PWF_SHELL);
|
|
|
|
#undef COPY
|
|
|
|
#define COPY(field, flag) do { \
|
|
|
|
if (template->pw_fields & flag) \
|
|
|
|
pwd->field = template->field; \
|
|
|
|
} while (0)
|
|
|
|
COPY(pw_uid, _PWF_UID);
|
|
|
|
COPY(pw_gid, _PWF_GID);
|
|
|
|
#undef COPY
|
|
|
|
free(copy);
|
|
|
|
return (0);
|
1996-12-03 17:55:49 +00:00
|
|
|
}
|
Add nsswitch support. By creating an /etc/nsswitch.conf file, you can
configure FreeBSD so that various databases such as passwd and group can be
looked up using flat files, NIS, or Hesiod.
= Hesiod has been added to libc (see hesiod(3)).
= A library routine for parsing nsswitch.conf and invoking callback
functions as specified has been added to libc (see nsdispatch(3)).
= The following C library functions have been modified to use nsdispatch:
. getgrent, getgrnam, getgrgid
. getpwent, getpwnam, getpwuid
. getusershell
. getaddrinfo
. gethostbyname, gethostbyname2, gethostbyaddr
. getnetbyname, getnetbyaddr
. getipnodebyname, getipnodebyaddr, getnodebyname, getnodebyaddr
= host.conf has been removed from src/etc. rc.network has been modified
to warn that host.conf is no longer used at boot time. In addition, if
there is a host.conf but no nsswitch.conf, the latter is created at boot
time from the former.
Obtained from: NetBSD
2000-09-06 18:16:48 +00:00
|
|
|
|
1996-12-03 17:55:49 +00:00
|
|
|
|
1995-06-26 16:04:57 +00:00
|
|
|
static int
|
2003-04-17 14:15:26 +00:00
|
|
|
compat_exclude(const char *name, DB **db)
|
1994-09-20 01:23:45 +00:00
|
|
|
{
|
2003-04-17 14:15:26 +00:00
|
|
|
DBT key, data;
|
1995-06-11 19:33:05 +00:00
|
|
|
|
2003-04-17 14:15:26 +00:00
|
|
|
if (*db == NULL &&
|
|
|
|
(*db = dbopen(NULL, O_RDWR, 600, DB_HASH, 0)) == NULL)
|
|
|
|
return (errno);
|
|
|
|
key.size = strlen(name);
|
|
|
|
key.data = (char *)name;
|
|
|
|
data.size = 0;
|
|
|
|
data.data = NULL;
|
1995-10-11 21:35:08 +00:00
|
|
|
|
2003-04-17 14:15:26 +00:00
|
|
|
if ((*db)->put(*db, &key, &data, 0) == -1)
|
|
|
|
return (errno);
|
|
|
|
return (0);
|
|
|
|
}
|
1994-09-20 01:23:45 +00:00
|
|
|
|
Add nsswitch support. By creating an /etc/nsswitch.conf file, you can
configure FreeBSD so that various databases such as passwd and group can be
looked up using flat files, NIS, or Hesiod.
= Hesiod has been added to libc (see hesiod(3)).
= A library routine for parsing nsswitch.conf and invoking callback
functions as specified has been added to libc (see nsdispatch(3)).
= The following C library functions have been modified to use nsdispatch:
. getgrent, getgrnam, getgrgid
. getpwent, getpwnam, getpwuid
. getusershell
. getaddrinfo
. gethostbyname, gethostbyname2, gethostbyaddr
. getnetbyname, getnetbyaddr
. getipnodebyname, getipnodebyaddr, getnodebyname, getnodebyaddr
= host.conf has been removed from src/etc. rc.network has been modified
to warn that host.conf is no longer used at boot time. In addition, if
there is a host.conf but no nsswitch.conf, the latter is created at boot
time from the former.
Obtained from: NetBSD
2000-09-06 18:16:48 +00:00
|
|
|
|
2003-04-17 14:15:26 +00:00
|
|
|
static int
|
|
|
|
compat_is_excluded(const char *name, DB *db)
|
|
|
|
{
|
|
|
|
DBT key, data;
|
Add nsswitch support. By creating an /etc/nsswitch.conf file, you can
configure FreeBSD so that various databases such as passwd and group can be
looked up using flat files, NIS, or Hesiod.
= Hesiod has been added to libc (see hesiod(3)).
= A library routine for parsing nsswitch.conf and invoking callback
functions as specified has been added to libc (see nsdispatch(3)).
= The following C library functions have been modified to use nsdispatch:
. getgrent, getgrnam, getgrgid
. getpwent, getpwnam, getpwuid
. getusershell
. getaddrinfo
. gethostbyname, gethostbyname2, gethostbyaddr
. getnetbyname, getnetbyaddr
. getipnodebyname, getipnodebyaddr, getnodebyname, getnodebyaddr
= host.conf has been removed from src/etc. rc.network has been modified
to warn that host.conf is no longer used at boot time. In addition, if
there is a host.conf but no nsswitch.conf, the latter is created at boot
time from the former.
Obtained from: NetBSD
2000-09-06 18:16:48 +00:00
|
|
|
|
2003-04-17 14:15:26 +00:00
|
|
|
if (db == NULL)
|
|
|
|
return (0);
|
|
|
|
key.size = strlen(name);
|
|
|
|
key.data = (char *)name;
|
|
|
|
return (db->get(db, &key, &data, 0) == 0);
|
|
|
|
}
|
Add nsswitch support. By creating an /etc/nsswitch.conf file, you can
configure FreeBSD so that various databases such as passwd and group can be
looked up using flat files, NIS, or Hesiod.
= Hesiod has been added to libc (see hesiod(3)).
= A library routine for parsing nsswitch.conf and invoking callback
functions as specified has been added to libc (see nsdispatch(3)).
= The following C library functions have been modified to use nsdispatch:
. getgrent, getgrnam, getgrgid
. getpwent, getpwnam, getpwuid
. getusershell
. getaddrinfo
. gethostbyname, gethostbyname2, gethostbyaddr
. getnetbyname, getnetbyaddr
. getipnodebyname, getipnodebyaddr, getnodebyname, getnodebyaddr
= host.conf has been removed from src/etc. rc.network has been modified
to warn that host.conf is no longer used at boot time. In addition, if
there is a host.conf but no nsswitch.conf, the latter is created at boot
time from the former.
Obtained from: NetBSD
2000-09-06 18:16:48 +00:00
|
|
|
|
|
|
|
|
2003-04-17 14:15:26 +00:00
|
|
|
static int
|
|
|
|
compat_redispatch(struct compat_state *st, enum nss_lookup_type how,
|
|
|
|
enum nss_lookup_type lookup_how, const char *name, const char *lookup_name,
|
|
|
|
uid_t uid, struct passwd *pwd, char *buffer, size_t bufsize, int *errnop)
|
|
|
|
{
|
|
|
|
static const ns_src compatsrc[] = {
|
|
|
|
#ifdef YP
|
|
|
|
{ NSSRC_NIS, NS_SUCCESS },
|
Add nsswitch support. By creating an /etc/nsswitch.conf file, you can
configure FreeBSD so that various databases such as passwd and group can be
looked up using flat files, NIS, or Hesiod.
= Hesiod has been added to libc (see hesiod(3)).
= A library routine for parsing nsswitch.conf and invoking callback
functions as specified has been added to libc (see nsdispatch(3)).
= The following C library functions have been modified to use nsdispatch:
. getgrent, getgrnam, getgrgid
. getpwent, getpwnam, getpwuid
. getusershell
. getaddrinfo
. gethostbyname, gethostbyname2, gethostbyaddr
. getnetbyname, getnetbyaddr
. getipnodebyname, getipnodebyaddr, getnodebyname, getnodebyaddr
= host.conf has been removed from src/etc. rc.network has been modified
to warn that host.conf is no longer used at boot time. In addition, if
there is a host.conf but no nsswitch.conf, the latter is created at boot
time from the former.
Obtained from: NetBSD
2000-09-06 18:16:48 +00:00
|
|
|
#endif
|
2003-04-17 14:15:26 +00:00
|
|
|
{ NULL, 0 }
|
|
|
|
};
|
|
|
|
ns_dtab dtab[] = {
|
|
|
|
#ifdef YP
|
|
|
|
{ NSSRC_NIS, nis_passwd, NULL },
|
|
|
|
#endif
|
|
|
|
#ifdef HESIOD
|
|
|
|
{ NSSRC_DNS, dns_passwd, NULL },
|
Add nsswitch support. By creating an /etc/nsswitch.conf file, you can
configure FreeBSD so that various databases such as passwd and group can be
looked up using flat files, NIS, or Hesiod.
= Hesiod has been added to libc (see hesiod(3)).
= A library routine for parsing nsswitch.conf and invoking callback
functions as specified has been added to libc (see nsdispatch(3)).
= The following C library functions have been modified to use nsdispatch:
. getgrent, getgrnam, getgrgid
. getpwent, getpwnam, getpwuid
. getusershell
. getaddrinfo
. gethostbyname, gethostbyname2, gethostbyaddr
. getnetbyname, getnetbyaddr
. getipnodebyname, getipnodebyaddr, getnodebyname, getnodebyaddr
= host.conf has been removed from src/etc. rc.network has been modified
to warn that host.conf is no longer used at boot time. In addition, if
there is a host.conf but no nsswitch.conf, the latter is created at boot
time from the former.
Obtained from: NetBSD
2000-09-06 18:16:48 +00:00
|
|
|
#endif
|
2003-04-17 14:15:26 +00:00
|
|
|
{ NULL, NULL, NULL }
|
|
|
|
};
|
|
|
|
void *discard;
|
|
|
|
int rv, e, i;
|
|
|
|
|
|
|
|
for (i = 0; i < sizeof(dtab)/sizeof(dtab[0]) - 1; i++)
|
|
|
|
dtab[i].mdata = (void *)lookup_how;
|
|
|
|
more:
|
2003-04-24 23:56:58 +00:00
|
|
|
pwd_init(pwd);
|
2003-04-17 14:15:26 +00:00
|
|
|
switch (lookup_how) {
|
|
|
|
case nss_lt_all:
|
|
|
|
rv = _nsdispatch(&discard, dtab, NSDB_PASSWD_COMPAT,
|
|
|
|
"getpwent_r", compatsrc, pwd, buffer, bufsize,
|
|
|
|
errnop);
|
|
|
|
break;
|
|
|
|
case nss_lt_id:
|
|
|
|
rv = _nsdispatch(&discard, dtab, NSDB_PASSWD_COMPAT,
|
|
|
|
"getpwuid_r", compatsrc, uid, pwd, buffer,
|
|
|
|
bufsize, errnop);
|
|
|
|
break;
|
|
|
|
case nss_lt_name:
|
|
|
|
rv = _nsdispatch(&discard, dtab, NSDB_PASSWD_COMPAT,
|
|
|
|
"getpwnam_r", compatsrc, lookup_name, pwd, buffer,
|
|
|
|
bufsize, errnop);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return (NS_UNAVAIL);
|
|
|
|
}
|
|
|
|
if (rv != NS_SUCCESS)
|
|
|
|
return (rv);
|
|
|
|
if (compat_is_excluded(pwd->pw_name, st->exclude)) {
|
|
|
|
if (how == nss_lt_all)
|
|
|
|
goto more;
|
|
|
|
return (NS_NOTFOUND);
|
|
|
|
}
|
|
|
|
e = compat_use_template(pwd, &st->template, buffer, bufsize);
|
|
|
|
if (e != 0) {
|
|
|
|
*errnop = e;
|
|
|
|
if (e == ERANGE)
|
|
|
|
return (NS_RETURN);
|
|
|
|
else
|
|
|
|
return (NS_UNAVAIL);
|
|
|
|
}
|
|
|
|
switch (how) {
|
|
|
|
case nss_lt_name:
|
|
|
|
if (strcmp(name, pwd->pw_name) != 0)
|
|
|
|
return (NS_NOTFOUND);
|
|
|
|
break;
|
|
|
|
case nss_lt_id:
|
|
|
|
if (uid != pwd->pw_uid)
|
|
|
|
return (NS_NOTFOUND);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
1994-09-20 01:23:45 +00:00
|
|
|
}
|
2003-04-17 14:15:26 +00:00
|
|
|
return (NS_SUCCESS);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
compat_endstate(void *p)
|
|
|
|
{
|
|
|
|
struct compat_state *st;
|
|
|
|
|
|
|
|
if (p == NULL)
|
|
|
|
return;
|
|
|
|
st = (struct compat_state *)p;
|
|
|
|
if (st->db != NULL)
|
|
|
|
st->db->close(st->db);
|
|
|
|
if (st->exclude != NULL)
|
|
|
|
st->exclude->close(st->exclude);
|
|
|
|
compat_clear_template(&st->template);
|
|
|
|
free(p);
|
Add nsswitch support. By creating an /etc/nsswitch.conf file, you can
configure FreeBSD so that various databases such as passwd and group can be
looked up using flat files, NIS, or Hesiod.
= Hesiod has been added to libc (see hesiod(3)).
= A library routine for parsing nsswitch.conf and invoking callback
functions as specified has been added to libc (see nsdispatch(3)).
= The following C library functions have been modified to use nsdispatch:
. getgrent, getgrnam, getgrgid
. getpwent, getpwnam, getpwuid
. getusershell
. getaddrinfo
. gethostbyname, gethostbyname2, gethostbyaddr
. getnetbyname, getnetbyaddr
. getipnodebyname, getipnodebyaddr, getnodebyname, getnodebyaddr
= host.conf has been removed from src/etc. rc.network has been modified
to warn that host.conf is no longer used at boot time. In addition, if
there is a host.conf but no nsswitch.conf, the latter is created at boot
time from the former.
Obtained from: NetBSD
2000-09-06 18:16:48 +00:00
|
|
|
}
|
1994-09-20 01:23:45 +00:00
|
|
|
|
1995-01-31 10:04:18 +00:00
|
|
|
|
Add nsswitch support. By creating an /etc/nsswitch.conf file, you can
configure FreeBSD so that various databases such as passwd and group can be
looked up using flat files, NIS, or Hesiod.
= Hesiod has been added to libc (see hesiod(3)).
= A library routine for parsing nsswitch.conf and invoking callback
functions as specified has been added to libc (see nsdispatch(3)).
= The following C library functions have been modified to use nsdispatch:
. getgrent, getgrnam, getgrgid
. getpwent, getpwnam, getpwuid
. getusershell
. getaddrinfo
. gethostbyname, gethostbyname2, gethostbyaddr
. getnetbyname, getnetbyaddr
. getipnodebyname, getipnodebyaddr, getnodebyname, getnodebyaddr
= host.conf has been removed from src/etc. rc.network has been modified
to warn that host.conf is no longer used at boot time. In addition, if
there is a host.conf but no nsswitch.conf, the latter is created at boot
time from the former.
Obtained from: NetBSD
2000-09-06 18:16:48 +00:00
|
|
|
static int
|
2003-04-17 14:15:26 +00:00
|
|
|
compat_setpwent(void *retval, void *mdata, va_list ap)
|
Add nsswitch support. By creating an /etc/nsswitch.conf file, you can
configure FreeBSD so that various databases such as passwd and group can be
looked up using flat files, NIS, or Hesiod.
= Hesiod has been added to libc (see hesiod(3)).
= A library routine for parsing nsswitch.conf and invoking callback
functions as specified has been added to libc (see nsdispatch(3)).
= The following C library functions have been modified to use nsdispatch:
. getgrent, getgrnam, getgrgid
. getpwent, getpwnam, getpwuid
. getusershell
. getaddrinfo
. gethostbyname, gethostbyname2, gethostbyaddr
. getnetbyname, getnetbyaddr
. getipnodebyname, getipnodebyaddr, getnodebyname, getnodebyaddr
= host.conf has been removed from src/etc. rc.network has been modified
to warn that host.conf is no longer used at boot time. In addition, if
there is a host.conf but no nsswitch.conf, the latter is created at boot
time from the former.
Obtained from: NetBSD
2000-09-06 18:16:48 +00:00
|
|
|
{
|
2003-04-25 18:25:19 +00:00
|
|
|
static const ns_src compatsrc[] = {
|
|
|
|
#ifdef YP
|
|
|
|
{ NSSRC_NIS, NS_SUCCESS },
|
|
|
|
#endif
|
|
|
|
{ NULL, 0 }
|
|
|
|
};
|
|
|
|
ns_dtab dtab[] = {
|
|
|
|
#ifdef YP
|
|
|
|
{ NSSRC_NIS, nis_setpwent, NULL },
|
|
|
|
#endif
|
|
|
|
#ifdef HESIOD
|
|
|
|
{ NSSRC_DNS, dns_setpwent, NULL },
|
|
|
|
#endif
|
|
|
|
{ NULL, NULL, NULL }
|
|
|
|
};
|
2003-04-17 14:15:26 +00:00
|
|
|
struct compat_state *st;
|
|
|
|
int rv, stayopen;
|
|
|
|
|
2003-04-25 18:25:19 +00:00
|
|
|
#define set_setent(x, y) do { \
|
|
|
|
int i; \
|
|
|
|
\
|
|
|
|
for (i = 0; i < (sizeof(x)/sizeof(x[0])) - 1; i++) \
|
|
|
|
x[i].mdata = (void *)y; \
|
|
|
|
} while (0)
|
|
|
|
|
2003-04-17 14:15:26 +00:00
|
|
|
rv = compat_getstate(&st);
|
|
|
|
if (rv != 0)
|
|
|
|
return (NS_UNAVAIL);
|
|
|
|
switch ((enum constants)mdata) {
|
|
|
|
case SETPWENT:
|
|
|
|
stayopen = va_arg(ap, int);
|
|
|
|
st->keynum = 0;
|
|
|
|
if (stayopen)
|
|
|
|
st->db = pwdbopen(&st->version);
|
|
|
|
st->stayopen = stayopen;
|
2003-04-25 18:25:19 +00:00
|
|
|
set_setent(dtab, mdata);
|
|
|
|
(void)_nsdispatch(NULL, dtab, NSDB_PASSWD_COMPAT, "setpwent",
|
|
|
|
compatsrc, 0);
|
2003-04-17 14:15:26 +00:00
|
|
|
break;
|
|
|
|
case ENDPWENT:
|
|
|
|
if (st->db != NULL) {
|
|
|
|
(void)st->db->close(st->db);
|
|
|
|
st->db = NULL;
|
|
|
|
}
|
2003-04-25 18:25:19 +00:00
|
|
|
set_setent(dtab, mdata);
|
|
|
|
(void)_nsdispatch(NULL, dtab, NSDB_PASSWD_COMPAT, "endpwent",
|
|
|
|
compatsrc, 0);
|
2003-04-17 14:15:26 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return (NS_UNAVAIL);
|
2003-04-25 18:25:19 +00:00
|
|
|
#undef set_setent
|
2003-04-17 14:15:26 +00:00
|
|
|
}
|
1995-01-31 10:04:18 +00:00
|
|
|
|
|
|
|
|
2003-04-17 14:15:26 +00:00
|
|
|
static int
|
|
|
|
compat_passwd(void *retval, void *mdata, va_list ap)
|
|
|
|
{
|
|
|
|
char keybuf[MAXLOGNAME + 1];
|
|
|
|
DBT key, entry;
|
|
|
|
struct compat_state *st;
|
|
|
|
enum nss_lookup_type how;
|
|
|
|
const char *name;
|
|
|
|
struct passwd *pwd;
|
|
|
|
char *buffer, *pw_name;
|
|
|
|
char *host, *user, *domain;
|
|
|
|
size_t bufsize;
|
|
|
|
uid_t uid;
|
|
|
|
uint32_t store;
|
2003-04-18 21:13:35 +00:00
|
|
|
int rv, from_compat, stayopen, *errnop;
|
Add nsswitch support. By creating an /etc/nsswitch.conf file, you can
configure FreeBSD so that various databases such as passwd and group can be
looked up using flat files, NIS, or Hesiod.
= Hesiod has been added to libc (see hesiod(3)).
= A library routine for parsing nsswitch.conf and invoking callback
functions as specified has been added to libc (see nsdispatch(3)).
= The following C library functions have been modified to use nsdispatch:
. getgrent, getgrnam, getgrgid
. getpwent, getpwnam, getpwuid
. getusershell
. getaddrinfo
. gethostbyname, gethostbyname2, gethostbyaddr
. getnetbyname, getnetbyaddr
. getipnodebyname, getipnodebyaddr, getnodebyname, getnodebyaddr
= host.conf has been removed from src/etc. rc.network has been modified
to warn that host.conf is no longer used at boot time. In addition, if
there is a host.conf but no nsswitch.conf, the latter is created at boot
time from the former.
Obtained from: NetBSD
2000-09-06 18:16:48 +00:00
|
|
|
|
2003-04-18 21:13:35 +00:00
|
|
|
from_compat = 0;
|
Add nsswitch support. By creating an /etc/nsswitch.conf file, you can
configure FreeBSD so that various databases such as passwd and group can be
looked up using flat files, NIS, or Hesiod.
= Hesiod has been added to libc (see hesiod(3)).
= A library routine for parsing nsswitch.conf and invoking callback
functions as specified has been added to libc (see nsdispatch(3)).
= The following C library functions have been modified to use nsdispatch:
. getgrent, getgrnam, getgrgid
. getpwent, getpwnam, getpwuid
. getusershell
. getaddrinfo
. gethostbyname, gethostbyname2, gethostbyaddr
. getnetbyname, getnetbyaddr
. getipnodebyname, getipnodebyaddr, getnodebyname, getnodebyaddr
= host.conf has been removed from src/etc. rc.network has been modified
to warn that host.conf is no longer used at boot time. In addition, if
there is a host.conf but no nsswitch.conf, the latter is created at boot
time from the former.
Obtained from: NetBSD
2000-09-06 18:16:48 +00:00
|
|
|
name = NULL;
|
2003-04-17 14:15:26 +00:00
|
|
|
uid = (uid_t)-1;
|
|
|
|
how = (enum nss_lookup_type)mdata;
|
|
|
|
switch (how) {
|
|
|
|
case nss_lt_name:
|
|
|
|
name = va_arg(ap, const char *);
|
Add nsswitch support. By creating an /etc/nsswitch.conf file, you can
configure FreeBSD so that various databases such as passwd and group can be
looked up using flat files, NIS, or Hesiod.
= Hesiod has been added to libc (see hesiod(3)).
= A library routine for parsing nsswitch.conf and invoking callback
functions as specified has been added to libc (see nsdispatch(3)).
= The following C library functions have been modified to use nsdispatch:
. getgrent, getgrnam, getgrgid
. getpwent, getpwnam, getpwuid
. getusershell
. getaddrinfo
. gethostbyname, gethostbyname2, gethostbyaddr
. getnetbyname, getnetbyaddr
. getipnodebyname, getipnodebyaddr, getnodebyname, getnodebyaddr
= host.conf has been removed from src/etc. rc.network has been modified
to warn that host.conf is no longer used at boot time. In addition, if
there is a host.conf but no nsswitch.conf, the latter is created at boot
time from the former.
Obtained from: NetBSD
2000-09-06 18:16:48 +00:00
|
|
|
break;
|
2003-04-17 14:15:26 +00:00
|
|
|
case nss_lt_id:
|
Add nsswitch support. By creating an /etc/nsswitch.conf file, you can
configure FreeBSD so that various databases such as passwd and group can be
looked up using flat files, NIS, or Hesiod.
= Hesiod has been added to libc (see hesiod(3)).
= A library routine for parsing nsswitch.conf and invoking callback
functions as specified has been added to libc (see nsdispatch(3)).
= The following C library functions have been modified to use nsdispatch:
. getgrent, getgrnam, getgrgid
. getpwent, getpwnam, getpwuid
. getusershell
. getaddrinfo
. gethostbyname, gethostbyname2, gethostbyaddr
. getnetbyname, getnetbyaddr
. getipnodebyname, getipnodebyaddr, getnodebyname, getnodebyaddr
= host.conf has been removed from src/etc. rc.network has been modified
to warn that host.conf is no longer used at boot time. In addition, if
there is a host.conf but no nsswitch.conf, the latter is created at boot
time from the former.
Obtained from: NetBSD
2000-09-06 18:16:48 +00:00
|
|
|
uid = va_arg(ap, uid_t);
|
|
|
|
break;
|
2003-04-17 14:15:26 +00:00
|
|
|
case nss_lt_all:
|
|
|
|
break;
|
Add nsswitch support. By creating an /etc/nsswitch.conf file, you can
configure FreeBSD so that various databases such as passwd and group can be
looked up using flat files, NIS, or Hesiod.
= Hesiod has been added to libc (see hesiod(3)).
= A library routine for parsing nsswitch.conf and invoking callback
functions as specified has been added to libc (see nsdispatch(3)).
= The following C library functions have been modified to use nsdispatch:
. getgrent, getgrnam, getgrgid
. getpwent, getpwnam, getpwuid
. getusershell
. getaddrinfo
. gethostbyname, gethostbyname2, gethostbyaddr
. getnetbyname, getnetbyaddr
. getipnodebyname, getipnodebyaddr, getnodebyname, getnodebyaddr
= host.conf has been removed from src/etc. rc.network has been modified
to warn that host.conf is no longer used at boot time. In addition, if
there is a host.conf but no nsswitch.conf, the latter is created at boot
time from the former.
Obtained from: NetBSD
2000-09-06 18:16:48 +00:00
|
|
|
default:
|
2003-04-17 14:15:26 +00:00
|
|
|
rv = NS_NOTFOUND;
|
|
|
|
goto fin;
|
1995-01-31 10:04:18 +00:00
|
|
|
}
|
2003-04-17 14:15:26 +00:00
|
|
|
pwd = va_arg(ap, struct passwd *);
|
|
|
|
buffer = va_arg(ap, char *);
|
|
|
|
bufsize = va_arg(ap, size_t);
|
|
|
|
errnop = va_arg(ap, int *);
|
|
|
|
*errnop = compat_getstate(&st);
|
|
|
|
if (*errnop != 0)
|
|
|
|
return (NS_UNAVAIL);
|
|
|
|
if (how == nss_lt_all && st->keynum < 0) {
|
|
|
|
rv = NS_NOTFOUND;
|
|
|
|
goto fin;
|
|
|
|
}
|
|
|
|
if (st->db == NULL &&
|
|
|
|
(st->db = pwdbopen(&st->version)) == NULL) {
|
|
|
|
*errnop = errno;
|
|
|
|
rv = NS_UNAVAIL;
|
|
|
|
goto fin;
|
|
|
|
}
|
|
|
|
if (how == nss_lt_all) {
|
|
|
|
if (st->keynum < 0) {
|
|
|
|
rv = NS_NOTFOUND;
|
|
|
|
goto fin;
|
|
|
|
}
|
|
|
|
stayopen = 1;
|
|
|
|
} else {
|
|
|
|
st->keynum = 0;
|
|
|
|
stayopen = st->stayopen;
|
|
|
|
}
|
|
|
|
docompat:
|
|
|
|
rv = NS_NOTFOUND;
|
|
|
|
switch (st->compat) {
|
|
|
|
case COMPAT_MODE_ALL:
|
|
|
|
rv = compat_redispatch(st, how, how, name, name, uid, pwd,
|
|
|
|
buffer, bufsize, errnop);
|
|
|
|
if (rv != NS_SUCCESS)
|
|
|
|
st->compat = COMPAT_MODE_OFF;
|
|
|
|
break;
|
|
|
|
case COMPAT_MODE_NETGROUP:
|
|
|
|
/* XXX getnetgrent is not thread-safe. */
|
|
|
|
do {
|
|
|
|
rv = getnetgrent(&host, &user, &domain);
|
|
|
|
if (rv == 0) {
|
|
|
|
endnetgrent();
|
|
|
|
st->compat = COMPAT_MODE_OFF;
|
|
|
|
rv = NS_NOTFOUND;
|
|
|
|
continue;
|
|
|
|
} else if (user == NULL || user[0] == '\0')
|
|
|
|
continue;
|
|
|
|
rv = compat_redispatch(st, how, nss_lt_name, name,
|
|
|
|
user, uid, pwd, buffer, bufsize, errnop);
|
|
|
|
} while (st->compat == COMPAT_MODE_NETGROUP &&
|
|
|
|
!(rv & NS_TERMINATE));
|
|
|
|
break;
|
|
|
|
case COMPAT_MODE_NAME:
|
|
|
|
rv = compat_redispatch(st, how, nss_lt_name, name, st->name,
|
|
|
|
uid, pwd, buffer, bufsize, errnop);
|
|
|
|
free(st->name);
|
|
|
|
st->name = NULL;
|
|
|
|
st->compat = COMPAT_MODE_OFF;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2003-04-18 21:13:35 +00:00
|
|
|
if (rv & NS_TERMINATE) {
|
|
|
|
from_compat = 1;
|
2003-04-17 14:15:26 +00:00
|
|
|
goto fin;
|
2003-04-18 21:13:35 +00:00
|
|
|
}
|
2003-04-17 14:15:26 +00:00
|
|
|
key.data = keybuf;
|
|
|
|
rv = NS_NOTFOUND;
|
|
|
|
while (st->keynum >= 0) {
|
|
|
|
st->keynum++;
|
|
|
|
if (st->version < _PWD_CURRENT_VERSION) {
|
|
|
|
memcpy(&keybuf[1], &st->keynum, sizeof(st->keynum));
|
|
|
|
key.size = sizeof(st->keynum) + 1;
|
|
|
|
} else {
|
|
|
|
store = htonl(st->keynum);
|
|
|
|
memcpy(&keybuf[1], &store, sizeof(store));
|
|
|
|
key.size = sizeof(store) + 1;
|
|
|
|
}
|
2003-04-18 14:11:17 +00:00
|
|
|
keybuf[0] = _PW_VERSIONED(_PW_KEYBYNUM, st->version);
|
2003-04-17 14:15:26 +00:00
|
|
|
rv = st->db->get(st->db, &key, &entry, 0);
|
|
|
|
if (rv < 0 || rv > 1) { /* should never return > 1 */
|
|
|
|
*errnop = errno;
|
|
|
|
rv = NS_UNAVAIL;
|
|
|
|
goto fin;
|
|
|
|
} else if (rv == 1) {
|
|
|
|
st->keynum = -1;
|
|
|
|
rv = NS_NOTFOUND;
|
|
|
|
goto fin;
|
|
|
|
}
|
|
|
|
pw_name = (char *)entry.data;
|
|
|
|
switch (pw_name[0]) {
|
Add nsswitch support. By creating an /etc/nsswitch.conf file, you can
configure FreeBSD so that various databases such as passwd and group can be
looked up using flat files, NIS, or Hesiod.
= Hesiod has been added to libc (see hesiod(3)).
= A library routine for parsing nsswitch.conf and invoking callback
functions as specified has been added to libc (see nsdispatch(3)).
= The following C library functions have been modified to use nsdispatch:
. getgrent, getgrnam, getgrgid
. getpwent, getpwnam, getpwuid
. getusershell
. getaddrinfo
. gethostbyname, gethostbyname2, gethostbyaddr
. getnetbyname, getnetbyaddr
. getipnodebyname, getipnodebyaddr, getnodebyname, getnodebyaddr
= host.conf has been removed from src/etc. rc.network has been modified
to warn that host.conf is no longer used at boot time. In addition, if
there is a host.conf but no nsswitch.conf, the latter is created at boot
time from the former.
Obtained from: NetBSD
2000-09-06 18:16:48 +00:00
|
|
|
case '+':
|
2003-04-17 14:15:26 +00:00
|
|
|
switch (pw_name[1]) {
|
Add nsswitch support. By creating an /etc/nsswitch.conf file, you can
configure FreeBSD so that various databases such as passwd and group can be
looked up using flat files, NIS, or Hesiod.
= Hesiod has been added to libc (see hesiod(3)).
= A library routine for parsing nsswitch.conf and invoking callback
functions as specified has been added to libc (see nsdispatch(3)).
= The following C library functions have been modified to use nsdispatch:
. getgrent, getgrnam, getgrgid
. getpwent, getpwnam, getpwuid
. getusershell
. getaddrinfo
. gethostbyname, gethostbyname2, gethostbyaddr
. getnetbyname, getnetbyaddr
. getipnodebyname, getipnodebyaddr, getnodebyname, getnodebyaddr
= host.conf has been removed from src/etc. rc.network has been modified
to warn that host.conf is no longer used at boot time. In addition, if
there is a host.conf but no nsswitch.conf, the latter is created at boot
time from the former.
Obtained from: NetBSD
2000-09-06 18:16:48 +00:00
|
|
|
case '\0':
|
2003-04-17 14:15:26 +00:00
|
|
|
st->compat = COMPAT_MODE_ALL;
|
Add nsswitch support. By creating an /etc/nsswitch.conf file, you can
configure FreeBSD so that various databases such as passwd and group can be
looked up using flat files, NIS, or Hesiod.
= Hesiod has been added to libc (see hesiod(3)).
= A library routine for parsing nsswitch.conf and invoking callback
functions as specified has been added to libc (see nsdispatch(3)).
= The following C library functions have been modified to use nsdispatch:
. getgrent, getgrnam, getgrgid
. getpwent, getpwnam, getpwuid
. getusershell
. getaddrinfo
. gethostbyname, gethostbyname2, gethostbyaddr
. getnetbyname, getnetbyaddr
. getipnodebyname, getipnodebyaddr, getnodebyname, getnodebyaddr
= host.conf has been removed from src/etc. rc.network has been modified
to warn that host.conf is no longer used at boot time. In addition, if
there is a host.conf but no nsswitch.conf, the latter is created at boot
time from the former.
Obtained from: NetBSD
2000-09-06 18:16:48 +00:00
|
|
|
break;
|
|
|
|
case '@':
|
2003-04-17 14:15:26 +00:00
|
|
|
setnetgrent(&pw_name[2]);
|
|
|
|
st->compat = COMPAT_MODE_NETGROUP;
|
Add nsswitch support. By creating an /etc/nsswitch.conf file, you can
configure FreeBSD so that various databases such as passwd and group can be
looked up using flat files, NIS, or Hesiod.
= Hesiod has been added to libc (see hesiod(3)).
= A library routine for parsing nsswitch.conf and invoking callback
functions as specified has been added to libc (see nsdispatch(3)).
= The following C library functions have been modified to use nsdispatch:
. getgrent, getgrnam, getgrgid
. getpwent, getpwnam, getpwuid
. getusershell
. getaddrinfo
. gethostbyname, gethostbyname2, gethostbyaddr
. getnetbyname, getnetbyaddr
. getipnodebyname, getipnodebyaddr, getnodebyname, getnodebyaddr
= host.conf has been removed from src/etc. rc.network has been modified
to warn that host.conf is no longer used at boot time. In addition, if
there is a host.conf but no nsswitch.conf, the latter is created at boot
time from the former.
Obtained from: NetBSD
2000-09-06 18:16:48 +00:00
|
|
|
break;
|
|
|
|
default:
|
2003-04-17 14:15:26 +00:00
|
|
|
st->name = strdup(&pw_name[1]);
|
|
|
|
if (st->name == NULL) {
|
|
|
|
syslog(LOG_ERR,
|
|
|
|
"getpwent memory allocation failure");
|
|
|
|
*errnop = ENOMEM;
|
|
|
|
rv = NS_UNAVAIL;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
st->compat = COMPAT_MODE_NAME;
|
Add nsswitch support. By creating an /etc/nsswitch.conf file, you can
configure FreeBSD so that various databases such as passwd and group can be
looked up using flat files, NIS, or Hesiod.
= Hesiod has been added to libc (see hesiod(3)).
= A library routine for parsing nsswitch.conf and invoking callback
functions as specified has been added to libc (see nsdispatch(3)).
= The following C library functions have been modified to use nsdispatch:
. getgrent, getgrnam, getgrgid
. getpwent, getpwnam, getpwuid
. getusershell
. getaddrinfo
. gethostbyname, gethostbyname2, gethostbyaddr
. getnetbyname, getnetbyaddr
. getipnodebyname, getipnodebyaddr, getnodebyname, getnodebyaddr
= host.conf has been removed from src/etc. rc.network has been modified
to warn that host.conf is no longer used at boot time. In addition, if
there is a host.conf but no nsswitch.conf, the latter is created at boot
time from the former.
Obtained from: NetBSD
2000-09-06 18:16:48 +00:00
|
|
|
}
|
2003-04-17 14:15:26 +00:00
|
|
|
if (entry.size > bufsize) {
|
|
|
|
*errnop = ERANGE;
|
|
|
|
rv = NS_RETURN;
|
|
|
|
goto fin;
|
Add nsswitch support. By creating an /etc/nsswitch.conf file, you can
configure FreeBSD so that various databases such as passwd and group can be
looked up using flat files, NIS, or Hesiod.
= Hesiod has been added to libc (see hesiod(3)).
= A library routine for parsing nsswitch.conf and invoking callback
functions as specified has been added to libc (see nsdispatch(3)).
= The following C library functions have been modified to use nsdispatch:
. getgrent, getgrnam, getgrgid
. getpwent, getpwnam, getpwuid
. getusershell
. getaddrinfo
. gethostbyname, gethostbyname2, gethostbyaddr
. getnetbyname, getnetbyaddr
. getipnodebyname, getipnodebyaddr, getnodebyname, getnodebyaddr
= host.conf has been removed from src/etc. rc.network has been modified
to warn that host.conf is no longer used at boot time. In addition, if
there is a host.conf but no nsswitch.conf, the latter is created at boot
time from the former.
Obtained from: NetBSD
2000-09-06 18:16:48 +00:00
|
|
|
}
|
2003-04-17 14:15:26 +00:00
|
|
|
memcpy(buffer, entry.data, entry.size);
|
|
|
|
rv = pwdb_versions[st->version].parse(buffer,
|
|
|
|
entry.size, pwd, errnop);
|
|
|
|
if (rv != NS_SUCCESS)
|
|
|
|
;
|
|
|
|
else if (compat_set_template(pwd, &st->template) < 0) {
|
|
|
|
*errnop = ENOMEM;
|
|
|
|
rv = NS_UNAVAIL;
|
|
|
|
goto fin;
|
|
|
|
}
|
|
|
|
goto docompat;
|
Add nsswitch support. By creating an /etc/nsswitch.conf file, you can
configure FreeBSD so that various databases such as passwd and group can be
looked up using flat files, NIS, or Hesiod.
= Hesiod has been added to libc (see hesiod(3)).
= A library routine for parsing nsswitch.conf and invoking callback
functions as specified has been added to libc (see nsdispatch(3)).
= The following C library functions have been modified to use nsdispatch:
. getgrent, getgrnam, getgrgid
. getpwent, getpwnam, getpwuid
. getusershell
. getaddrinfo
. gethostbyname, gethostbyname2, gethostbyaddr
. getnetbyname, getnetbyaddr
. getipnodebyname, getipnodebyaddr, getnodebyname, getnodebyaddr
= host.conf has been removed from src/etc. rc.network has been modified
to warn that host.conf is no longer used at boot time. In addition, if
there is a host.conf but no nsswitch.conf, the latter is created at boot
time from the former.
Obtained from: NetBSD
2000-09-06 18:16:48 +00:00
|
|
|
case '-':
|
2003-04-17 14:15:26 +00:00
|
|
|
switch (pw_name[1]) {
|
Add nsswitch support. By creating an /etc/nsswitch.conf file, you can
configure FreeBSD so that various databases such as passwd and group can be
looked up using flat files, NIS, or Hesiod.
= Hesiod has been added to libc (see hesiod(3)).
= A library routine for parsing nsswitch.conf and invoking callback
functions as specified has been added to libc (see nsdispatch(3)).
= The following C library functions have been modified to use nsdispatch:
. getgrent, getgrnam, getgrgid
. getpwent, getpwnam, getpwuid
. getusershell
. getaddrinfo
. gethostbyname, gethostbyname2, gethostbyaddr
. getnetbyname, getnetbyaddr
. getipnodebyname, getipnodebyaddr, getnodebyname, getnodebyaddr
= host.conf has been removed from src/etc. rc.network has been modified
to warn that host.conf is no longer used at boot time. In addition, if
there is a host.conf but no nsswitch.conf, the latter is created at boot
time from the former.
Obtained from: NetBSD
2000-09-06 18:16:48 +00:00
|
|
|
case '\0':
|
2003-04-17 14:15:26 +00:00
|
|
|
/* XXX Maybe syslog warning */
|
|
|
|
continue;
|
Add nsswitch support. By creating an /etc/nsswitch.conf file, you can
configure FreeBSD so that various databases such as passwd and group can be
looked up using flat files, NIS, or Hesiod.
= Hesiod has been added to libc (see hesiod(3)).
= A library routine for parsing nsswitch.conf and invoking callback
functions as specified has been added to libc (see nsdispatch(3)).
= The following C library functions have been modified to use nsdispatch:
. getgrent, getgrnam, getgrgid
. getpwent, getpwnam, getpwuid
. getusershell
. getaddrinfo
. gethostbyname, gethostbyname2, gethostbyaddr
. getnetbyname, getnetbyaddr
. getipnodebyname, getipnodebyaddr, getnodebyname, getnodebyaddr
= host.conf has been removed from src/etc. rc.network has been modified
to warn that host.conf is no longer used at boot time. In addition, if
there is a host.conf but no nsswitch.conf, the latter is created at boot
time from the former.
Obtained from: NetBSD
2000-09-06 18:16:48 +00:00
|
|
|
case '@':
|
2003-04-17 14:15:26 +00:00
|
|
|
setnetgrent(&pw_name[2]);
|
|
|
|
while (getnetgrent(&host, &user, &domain) !=
|
2004-03-05 08:10:19 +00:00
|
|
|
0) {
|
2003-04-17 14:15:26 +00:00
|
|
|
if (user != NULL && user[0] != '\0')
|
|
|
|
compat_exclude(user,
|
|
|
|
&st->exclude);
|
Add nsswitch support. By creating an /etc/nsswitch.conf file, you can
configure FreeBSD so that various databases such as passwd and group can be
looked up using flat files, NIS, or Hesiod.
= Hesiod has been added to libc (see hesiod(3)).
= A library routine for parsing nsswitch.conf and invoking callback
functions as specified has been added to libc (see nsdispatch(3)).
= The following C library functions have been modified to use nsdispatch:
. getgrent, getgrnam, getgrgid
. getpwent, getpwnam, getpwuid
. getusershell
. getaddrinfo
. gethostbyname, gethostbyname2, gethostbyaddr
. getnetbyname, getnetbyaddr
. getipnodebyname, getipnodebyaddr, getnodebyname, getnodebyaddr
= host.conf has been removed from src/etc. rc.network has been modified
to warn that host.conf is no longer used at boot time. In addition, if
there is a host.conf but no nsswitch.conf, the latter is created at boot
time from the former.
Obtained from: NetBSD
2000-09-06 18:16:48 +00:00
|
|
|
}
|
|
|
|
endnetgrent();
|
2003-04-17 14:15:26 +00:00
|
|
|
continue;
|
Add nsswitch support. By creating an /etc/nsswitch.conf file, you can
configure FreeBSD so that various databases such as passwd and group can be
looked up using flat files, NIS, or Hesiod.
= Hesiod has been added to libc (see hesiod(3)).
= A library routine for parsing nsswitch.conf and invoking callback
functions as specified has been added to libc (see nsdispatch(3)).
= The following C library functions have been modified to use nsdispatch:
. getgrent, getgrnam, getgrgid
. getpwent, getpwnam, getpwuid
. getusershell
. getaddrinfo
. gethostbyname, gethostbyname2, gethostbyaddr
. getnetbyname, getnetbyaddr
. getipnodebyname, getipnodebyaddr, getnodebyname, getnodebyaddr
= host.conf has been removed from src/etc. rc.network has been modified
to warn that host.conf is no longer used at boot time. In addition, if
there is a host.conf but no nsswitch.conf, the latter is created at boot
time from the former.
Obtained from: NetBSD
2000-09-06 18:16:48 +00:00
|
|
|
default:
|
2003-04-17 14:15:26 +00:00
|
|
|
compat_exclude(&pw_name[1], &st->exclude);
|
|
|
|
continue;
|
Add nsswitch support. By creating an /etc/nsswitch.conf file, you can
configure FreeBSD so that various databases such as passwd and group can be
looked up using flat files, NIS, or Hesiod.
= Hesiod has been added to libc (see hesiod(3)).
= A library routine for parsing nsswitch.conf and invoking callback
functions as specified has been added to libc (see nsdispatch(3)).
= The following C library functions have been modified to use nsdispatch:
. getgrent, getgrnam, getgrgid
. getpwent, getpwnam, getpwuid
. getusershell
. getaddrinfo
. gethostbyname, gethostbyname2, gethostbyaddr
. getnetbyname, getnetbyaddr
. getipnodebyname, getipnodebyaddr, getnodebyname, getnodebyaddr
= host.conf has been removed from src/etc. rc.network has been modified
to warn that host.conf is no longer used at boot time. In addition, if
there is a host.conf but no nsswitch.conf, the latter is created at boot
time from the former.
Obtained from: NetBSD
2000-09-06 18:16:48 +00:00
|
|
|
}
|
|
|
|
break;
|
2002-05-07 23:26:00 +00:00
|
|
|
default:
|
2003-04-17 14:15:26 +00:00
|
|
|
break;
|
Add nsswitch support. By creating an /etc/nsswitch.conf file, you can
configure FreeBSD so that various databases such as passwd and group can be
looked up using flat files, NIS, or Hesiod.
= Hesiod has been added to libc (see hesiod(3)).
= A library routine for parsing nsswitch.conf and invoking callback
functions as specified has been added to libc (see nsdispatch(3)).
= The following C library functions have been modified to use nsdispatch:
. getgrent, getgrnam, getgrgid
. getpwent, getpwnam, getpwuid
. getusershell
. getaddrinfo
. gethostbyname, gethostbyname2, gethostbyaddr
. getnetbyname, getnetbyaddr
. getipnodebyname, getipnodebyaddr, getnodebyname, getnodebyaddr
= host.conf has been removed from src/etc. rc.network has been modified
to warn that host.conf is no longer used at boot time. In addition, if
there is a host.conf but no nsswitch.conf, the latter is created at boot
time from the former.
Obtained from: NetBSD
2000-09-06 18:16:48 +00:00
|
|
|
}
|
2003-04-17 14:15:26 +00:00
|
|
|
if (compat_is_excluded((char *)entry.data, st->exclude))
|
|
|
|
continue;
|
|
|
|
rv = pwdb_versions[st->version].match(entry.data, entry.size,
|
|
|
|
how, name, uid);
|
|
|
|
if (rv == NS_RETURN)
|
|
|
|
break;
|
|
|
|
else if (rv != NS_SUCCESS)
|
|
|
|
continue;
|
|
|
|
if (entry.size > bufsize) {
|
|
|
|
*errnop = ERANGE;
|
|
|
|
rv = NS_RETURN;
|
Add nsswitch support. By creating an /etc/nsswitch.conf file, you can
configure FreeBSD so that various databases such as passwd and group can be
looked up using flat files, NIS, or Hesiod.
= Hesiod has been added to libc (see hesiod(3)).
= A library routine for parsing nsswitch.conf and invoking callback
functions as specified has been added to libc (see nsdispatch(3)).
= The following C library functions have been modified to use nsdispatch:
. getgrent, getgrnam, getgrgid
. getpwent, getpwnam, getpwuid
. getusershell
. getaddrinfo
. gethostbyname, gethostbyname2, gethostbyaddr
. getnetbyname, getnetbyaddr
. getipnodebyname, getipnodebyaddr, getnodebyname, getnodebyaddr
= host.conf has been removed from src/etc. rc.network has been modified
to warn that host.conf is no longer used at boot time. In addition, if
there is a host.conf but no nsswitch.conf, the latter is created at boot
time from the former.
Obtained from: NetBSD
2000-09-06 18:16:48 +00:00
|
|
|
break;
|
|
|
|
}
|
2003-04-17 14:15:26 +00:00
|
|
|
memcpy(buffer, entry.data, entry.size);
|
|
|
|
rv = pwdb_versions[st->version].parse(buffer, entry.size, pwd,
|
|
|
|
errnop);
|
|
|
|
if (rv & NS_TERMINATE)
|
|
|
|
break;
|
1995-01-31 10:04:18 +00:00
|
|
|
}
|
2003-04-17 14:15:26 +00:00
|
|
|
fin:
|
|
|
|
if (!stayopen && st->db != NULL) {
|
|
|
|
(void)st->db->close(st->db);
|
|
|
|
st->db = NULL;
|
Add nsswitch support. By creating an /etc/nsswitch.conf file, you can
configure FreeBSD so that various databases such as passwd and group can be
looked up using flat files, NIS, or Hesiod.
= Hesiod has been added to libc (see hesiod(3)).
= A library routine for parsing nsswitch.conf and invoking callback
functions as specified has been added to libc (see nsdispatch(3)).
= The following C library functions have been modified to use nsdispatch:
. getgrent, getgrnam, getgrgid
. getpwent, getpwnam, getpwuid
. getusershell
. getaddrinfo
. gethostbyname, gethostbyname2, gethostbyaddr
. getnetbyname, getnetbyaddr
. getipnodebyname, getipnodebyaddr, getnodebyname, getnodebyaddr
= host.conf has been removed from src/etc. rc.network has been modified
to warn that host.conf is no longer used at boot time. In addition, if
there is a host.conf but no nsswitch.conf, the latter is created at boot
time from the former.
Obtained from: NetBSD
2000-09-06 18:16:48 +00:00
|
|
|
}
|
2004-01-12 13:33:24 +00:00
|
|
|
if (rv == NS_SUCCESS) {
|
2003-04-18 21:13:35 +00:00
|
|
|
if (!from_compat) {
|
|
|
|
pwd->pw_fields &= ~_PWF_SOURCE;
|
|
|
|
pwd->pw_fields |= _PWF_FILES;
|
|
|
|
}
|
|
|
|
if (retval != NULL)
|
|
|
|
*(struct passwd **)retval = pwd;
|
|
|
|
}
|
2003-04-17 14:15:26 +00:00
|
|
|
return (rv);
|
1995-01-31 10:04:18 +00:00
|
|
|
}
|
|
|
|
|
1996-12-03 17:55:49 +00:00
|
|
|
|
2003-04-17 14:15:26 +00:00
|
|
|
/*
|
|
|
|
* common passwd line matching and parsing
|
|
|
|
*/
|
Add nsswitch support. By creating an /etc/nsswitch.conf file, you can
configure FreeBSD so that various databases such as passwd and group can be
looked up using flat files, NIS, or Hesiod.
= Hesiod has been added to libc (see hesiod(3)).
= A library routine for parsing nsswitch.conf and invoking callback
functions as specified has been added to libc (see nsdispatch(3)).
= The following C library functions have been modified to use nsdispatch:
. getgrent, getgrnam, getgrgid
. getpwent, getpwnam, getpwuid
. getusershell
. getaddrinfo
. gethostbyname, gethostbyname2, gethostbyaddr
. getnetbyname, getnetbyaddr
. getipnodebyname, getipnodebyaddr, getnodebyname, getnodebyaddr
= host.conf has been removed from src/etc. rc.network has been modified
to warn that host.conf is no longer used at boot time. In addition, if
there is a host.conf but no nsswitch.conf, the latter is created at boot
time from the former.
Obtained from: NetBSD
2000-09-06 18:16:48 +00:00
|
|
|
int
|
2003-04-17 14:15:26 +00:00
|
|
|
__pw_match_entry(const char *entry, size_t entrysize, enum nss_lookup_type how,
|
|
|
|
const char *name, uid_t uid)
|
1994-09-20 01:23:45 +00:00
|
|
|
{
|
2003-04-17 14:15:26 +00:00
|
|
|
const char *p, *eom;
|
|
|
|
char *q;
|
|
|
|
size_t len;
|
|
|
|
unsigned long m;
|
|
|
|
|
|
|
|
eom = entry + entrysize;
|
|
|
|
for (p = entry; p < eom; p++)
|
|
|
|
if (*p == ':')
|
|
|
|
break;
|
|
|
|
if (*p != ':')
|
|
|
|
return (NS_NOTFOUND);
|
|
|
|
if (how == nss_lt_all)
|
|
|
|
return (NS_SUCCESS);
|
|
|
|
if (how == nss_lt_name) {
|
|
|
|
len = strlen(name);
|
|
|
|
if (len == (p - entry) && memcmp(name, entry, len) == 0)
|
|
|
|
return (NS_SUCCESS);
|
|
|
|
else
|
|
|
|
return (NS_NOTFOUND);
|
1999-03-27 21:51:33 +00:00
|
|
|
}
|
2003-04-17 14:15:26 +00:00
|
|
|
for (p++; p < eom; p++)
|
|
|
|
if (*p == ':')
|
|
|
|
break;
|
|
|
|
if (*p != ':')
|
|
|
|
return (NS_NOTFOUND);
|
|
|
|
m = strtoul(++p, &q, 10);
|
|
|
|
if (q[0] != ':' || (uid_t)m != uid)
|
|
|
|
return (NS_NOTFOUND);
|
|
|
|
else
|
|
|
|
return (NS_SUCCESS);
|
Add nsswitch support. By creating an /etc/nsswitch.conf file, you can
configure FreeBSD so that various databases such as passwd and group can be
looked up using flat files, NIS, or Hesiod.
= Hesiod has been added to libc (see hesiod(3)).
= A library routine for parsing nsswitch.conf and invoking callback
functions as specified has been added to libc (see nsdispatch(3)).
= The following C library functions have been modified to use nsdispatch:
. getgrent, getgrnam, getgrgid
. getpwent, getpwnam, getpwuid
. getusershell
. getaddrinfo
. gethostbyname, gethostbyname2, gethostbyaddr
. getnetbyname, getnetbyaddr
. getipnodebyname, getipnodebyaddr, getnodebyname, getnodebyaddr
= host.conf has been removed from src/etc. rc.network has been modified
to warn that host.conf is no longer used at boot time. In addition, if
there is a host.conf but no nsswitch.conf, the latter is created at boot
time from the former.
Obtained from: NetBSD
2000-09-06 18:16:48 +00:00
|
|
|
}
|
1994-09-20 01:23:45 +00:00
|
|
|
|
|
|
|
|
2003-04-17 14:15:26 +00:00
|
|
|
/* XXX buffer must be NUL-terminated. errnop is not set correctly. */
|
|
|
|
int
|
|
|
|
__pw_parse_entry(char *buffer, size_t bufsize __unused, struct passwd *pwd,
|
|
|
|
int master, int *errnop __unused)
|
1994-09-20 01:23:45 +00:00
|
|
|
{
|
1996-04-16 00:22:41 +00:00
|
|
|
|
2003-04-17 14:15:26 +00:00
|
|
|
if (__pw_scan(buffer, pwd, master ? _PWSCAN_MASTER : 0) == 0)
|
|
|
|
return (NS_NOTFOUND);
|
|
|
|
else
|
|
|
|
return (NS_SUCCESS);
|
1994-09-20 01:23:45 +00:00
|
|
|
}
|