-/* Copyright (C) 1996-1998,2001,2002,2003,2006 Free Software Foundation, Inc.
+/* Copyright (C) 1996-2019 Free Software Foundation, Inc.
This file is part of the GNU C Library.
Contributed by Thorsten Kukuk <kukuk@vt.uni-paderborn.de>, 1996.
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
- License along with the GNU C Library; if not, write to the Free
- Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
- 02111-1307 USA. */
+ License along with the GNU C Library; if not, see
+ <https://www.gnu.org/licenses/>. */
#include <assert.h>
#include <ctype.h>
#include <nss.h>
#include <pwd.h>
#include <string.h>
-#include <bits/libc-lock.h>
+#include <libc-lock.h>
#include <rpcsvc/yp.h>
#include <rpcsvc/ypclnt.h>
/* Protect global state against multiple changers */
__libc_lock_define_initialized (static, lock)
-static bool_t new_start = 1;
+static bool new_start = true;
static char *oldkey;
static int oldkeylen;
static intern_t intern;
{
struct response_t *bucket = intern->next;
- if (__builtin_expect (bucket == NULL, 0))
+ if (__glibc_unlikely (bucket == NULL))
{
#define MINSIZE 4096 - 4 * sizeof (void *)
const size_t minsize = MAX (MINSIZE, 2 * (invallen + 1));
}
char *p = mempcpy (&bucket->mem[intern->offset], inval, invallen);
- if (__builtin_expect (p[-1] != '\0', 0))
+ if (__glibc_unlikely (p[-1] != '\0'))
{
*p = '\0';
++invallen;
static void
internal_nis_endpwent (void)
{
- new_start = 1;
- if (oldkey != NULL)
- {
- free (oldkey);
- oldkey = NULL;
- oldkeylen = 0;
- }
+ new_start = true;
+ free (oldkey);
+ oldkey = NULL;
+ oldkeylen = 0;
- struct response_t *curr = intern.next;
+ struct response_t *curr = intern.start;
while (curr != NULL)
{
{
/* We have to read all the data now. */
char *domain;
- if (__builtin_expect (yp_get_default_domain (&domain), 0))
+ if (__glibc_unlikely (yp_get_default_domain (&domain)))
return NSS_STATUS_UNAVAIL;
struct ypall_callback ypcb;
handle_batch_read:
bucket = intern.next;
- if (__builtin_expect (intern.offset >= bucket->size, 0))
+ if (__glibc_unlikely (intern.offset >= bucket->size))
{
if (bucket->next == NULL)
return NSS_STATUS_NOTFOUND;
yperr = yp_next (domain, "passwd.byname", oldkey, oldkeylen,
&outkey, &keylen, &result, &len);
- if (__builtin_expect (yperr != YPERR_SUCCESS, 0))
+ if (__glibc_unlikely (yperr != YPERR_SUCCESS))
{
enum nss_status retval = yperr2nss (yperr);
}
/* Check for adjunct style secret passwords. They can be
- recognized by a password starting with "##". */
+ recognized by a password starting with "##". We do not use
+ it if the passwd.adjunct.byname table is supposed to be used
+ as a shadow.byname replacement. */
char *p = strchr (result, ':');
size_t namelen;
char *result2;
int len2;
- if (p != NULL /* This better should be true in all cases. */
+ if ((_nsl_default_nss () & NSS_FLAG_ADJUNCT_AS_SHADOW) == 0
+ && p != NULL /* This better should be true in all cases. */
&& p[1] == '#' && p[2] == '#'
&& (namelen = p - result,
yp_match (domain, "passwd.adjunct.byname", result, namelen,
&result2, &len2)) == YPERR_SUCCESS)
{
- /* We found a passwd.adjunct entry. Merge encrypted
+ /* We found a passwd.adjunct.byname entry. Merge encrypted
password therein into original result. */
char *encrypted = strchr (result2, ':');
char *endp;
else
{
non_adjunct:
- if (__builtin_expect ((size_t) (len + 1) > buflen, 0))
+ if (__glibc_unlikely ((size_t) (len + 1) > buflen))
{
free (result);
*errnop = ERANGE;
}
while (isspace (*p))
- ++p;
+ ++p;
if (!batch_read)
free (result);
parse_res = _nss_files_parse_pwent (p, pwd, (void *) buffer, buflen,
errnop);
- if (__builtin_expect (parse_res == -1, 0))
+ if (__glibc_unlikely (parse_res == -1))
{
- free (outkey);
+ if (!batch_read)
+ free (outkey);
*errnop = ERANGE;
return NSS_STATUS_TRYAGAIN;
}
free (oldkey);
oldkey = outkey;
oldkeylen = keylen;
- new_start = 0;
+ new_start = false;
}
}
while (parse_res < 1);
}
char *domain;
- if (__builtin_expect (yp_get_default_domain (&domain), 0))
+ if (__glibc_unlikely (yp_get_default_domain (&domain)))
return NSS_STATUS_UNAVAIL;
size_t namelen = strlen (name);
int len;
int yperr = yp_match (domain, "passwd.byname", name, namelen, &result, &len);
- if (__builtin_expect (yperr != YPERR_SUCCESS, 0))
+ if (__glibc_unlikely (yperr != YPERR_SUCCESS))
{
enum nss_status retval = yperr2nss (yperr);
}
/* Check for adjunct style secret passwords. They can be recognized
- by a password starting with "##". */
+ by a password starting with "##". We do not use it if the
+ passwd.adjunct.byname table is supposed to be used as a shadow.byname
+ replacement. */
char *result2;
int len2;
char *p = strchr (result, ':');
- if (p != NULL /* This better should be true in all cases. */
+ if ((_nsl_default_nss () & NSS_FLAG_ADJUNCT_AS_SHADOW) == 0
+ && p != NULL /* This better should be true in all cases. */
&& p[1] == '#' && p[2] == '#'
&& yp_match (domain, "passwd.adjunct.byname", name, namelen,
&result2, &len2) == YPERR_SUCCESS)
{
- /* We found a passwd.adjunct entry. Merge encrypted password
+ /* We found a passwd.adjunct.byname entry. Merge encrypted password
therein into original result. */
char *encrypted = strchr (result2, ':');
char *endp;
else
{
non_adjunct:
- if (__builtin_expect ((size_t) (len + 1) > buflen, 0))
+ if (__glibc_unlikely ((size_t) (len + 1) > buflen))
{
free (result);
*errnop = ERANGE;
int parse_res = _nss_files_parse_pwent (p, pwd, (void *) buffer, buflen,
errnop);
- if (__builtin_expect (parse_res < 1, 0))
+ if (__glibc_unlikely (parse_res < 1))
{
if (parse_res == -1)
- return NSS_STATUS_TRYAGAIN;
+ return NSS_STATUS_TRYAGAIN;
else
return NSS_STATUS_NOTFOUND;
}
char *buffer, size_t buflen, int *errnop)
{
char *domain;
- if (__builtin_expect (yp_get_default_domain (&domain), 0))
+ if (__glibc_unlikely (yp_get_default_domain (&domain)))
return NSS_STATUS_UNAVAIL;
char buf[32];
int len;
int yperr = yp_match (domain, "passwd.byuid", buf, nlen, &result, &len);
- if (__builtin_expect (yperr != YPERR_SUCCESS, 0))
+ if (__glibc_unlikely (yperr != YPERR_SUCCESS))
{
enum nss_status retval = yperr2nss (yperr);
}
/* Check for adjunct style secret passwords. They can be recognized
- by a password starting with "##". */
+ by a password starting with "##". We do not use it if the
+ passwd.adjunct.byname table is supposed to be used as a shadow.byname
+ replacement. */
char *result2;
int len2;
size_t namelen;
char *p = strchr (result, ':');
- if (p != NULL /* This better should be true in all cases. */
+ if ((_nsl_default_nss () & NSS_FLAG_ADJUNCT_AS_SHADOW) == 0
+ && p != NULL /* This better should be true in all cases. */
&& p[1] == '#' && p[2] == '#'
&& (namelen = p - result,
yp_match (domain, "passwd.adjunct.byname", result, namelen,
&result2, &len2)) == YPERR_SUCCESS)
{
- /* We found a passwd.adjunct entry. Merge encrypted password
+ /* We found a passwd.adjunct.byname entry. Merge encrypted password
therein into original result. */
char *encrypted = strchr (result2, ':');
char *endp;
else
{
non_adjunct:
- if (__builtin_expect ((size_t) (len + 1) > buflen, 0))
+ if (__glibc_unlikely ((size_t) (len + 1) > buflen))
{
free (result);
*errnop = ERANGE;
int parse_res = _nss_files_parse_pwent (p, pwd, (void *) buffer, buflen,
errnop);
- if (__builtin_expect (parse_res < 1, 0))
+ if (__glibc_unlikely (parse_res < 1))
{
if (parse_res == -1)
- return NSS_STATUS_TRYAGAIN;
+ return NSS_STATUS_TRYAGAIN;
else
return NSS_STATUS_NOTFOUND;
}