Back to index

glibc  2.9
Defines | Functions
nis-spwd.c File Reference
#include <nss.h>
#include <ctype.h>
#include <errno.h>
#include <string.h>
#include <shadow.h>
#include <bits/libc-lock.h>
#include <rpcsvc/yp.h>
#include <rpcsvc/ypclnt.h>
#include "nss-nis.h"
#include <nss/nss_files/files-parse.c>

Go to the source code of this file.

Defines

#define _nss_nis_endspent   _nss_nis_endspent_XXX
#define ENTNAME   spent
#define STRUCTURE   spwd
#define EXTERN_PARSER

Functions

 __libc_lock_define_initialized (static, lock)
 strong_alias (_nss_nis_setspent, _nss_nis_endspent)
enum nss_status _nss_nis_getspent_r (struct spwd *result, char *buffer, size_t buflen, int *errnop)
enum nss_status _nss_nis_getspnam_r (const char *name, struct spwd *sp, char *buffer, size_t buflen, int *errnop)

Define Documentation

#define _nss_nis_endspent   _nss_nis_endspent_XXX

Definition at line 26 of file nis-spwd.c.

#define ENTNAME   spent

Definition at line 36 of file nis-spwd.c.

#define EXTERN_PARSER

Definition at line 38 of file nis-spwd.c.

#define STRUCTURE   spwd

Definition at line 37 of file nis-spwd.c.


Function Documentation

__libc_lock_define_initialized ( static  ,
lock   
)

Definition at line 42 of file nis-spwd.c.

{
  __libc_lock_lock (lock);

  new_start = 1;
  free (oldkey);
  oldkey = NULL;
  oldkeylen = 0;

  __libc_lock_unlock (lock);

  return NSS_STATUS_SUCCESS;
}
enum nss_status _nss_nis_getspent_r ( struct spwd result,
char *  buffer,
size_t  buflen,
int errnop 
)

Definition at line 134 of file nis-spwd.c.

{
  int status;

  __libc_lock_lock (lock);

  status = internal_nis_getspent_r (result, buffer, buflen, errnop);

  __libc_lock_unlock (lock);

  return status;
}
enum nss_status _nss_nis_getspnam_r ( const char *  name,
struct spwd sp,
char *  buffer,
size_t  buflen,
int errnop 
)

Definition at line 149 of file nis-spwd.c.

{
  if (name == NULL)
    {
      *errnop = EINVAL;
      return NSS_STATUS_UNAVAIL;
    }

  char *domain;
  if (__builtin_expect (yp_get_default_domain (&domain), 0))
    return NSS_STATUS_UNAVAIL;

  char *result;
  int len;
  int yperr = yp_match (domain, "shadow.byname", name, strlen (name), &result,
                     &len);

  if (__builtin_expect (yperr != YPERR_SUCCESS, 0))
    {
      enum nss_status retval = yperr2nss (yperr);

      if (retval == NSS_STATUS_TRYAGAIN)
       *errnop = errno;
      return retval;
    }

  if (__builtin_expect ((size_t) (len + 1) > buflen, 0))
    {
      free (result);
      *errnop = ERANGE;
      return NSS_STATUS_TRYAGAIN;
    }

  char *p = strncpy (buffer, result, len);
  buffer[len] = '\0';
  while (isspace (*p))
    ++p;
  free (result);

  int parse_res = _nss_files_parse_spent (p, sp, (void *) buffer, buflen,
                                     errnop);
  if (__builtin_expect (parse_res < 1, 0))
    {
      if (parse_res == -1)
       return NSS_STATUS_TRYAGAIN;
      else
       return NSS_STATUS_NOTFOUND;
    }
  return NSS_STATUS_SUCCESS;
}

Here is the call graph for this function:

strong_alias ( _nss_nis_setspent  ,
_nss_nis_endspent   
)

Definition at line 65 of file nis-spwd.c.

{
  char *domain;
  if (__builtin_expect (yp_get_default_domain (&domain), 0))
    return NSS_STATUS_UNAVAIL;

  /* Get the next entry until we found a correct one. */
  int parse_res;
  do
    {
      char *result;
      char *outkey;
      int len;
      int keylen;
      int yperr;

      if (new_start)
        yperr = yp_first (domain, "shadow.byname", &outkey, &keylen, &result,
                       &len);
      else
        yperr = yp_next (domain, "shadow.byname", oldkey, oldkeylen, &outkey,
                      &keylen, &result, &len);

      if (__builtin_expect (yperr != YPERR_SUCCESS, 0))
        {
         enum nss_status retval = yperr2nss (yperr);

         if (retval == NSS_STATUS_TRYAGAIN)
           *errnop = errno;
          return retval;
        }

      if (__builtin_expect ((size_t) (len + 1) > buflen, 0))
        {
          free (result);
         *errnop = ERANGE;
          return NSS_STATUS_TRYAGAIN;
        }

      char *p = strncpy (buffer, result, len);
      buffer[len] = '\0';
      while (isspace (*p))
        ++p;
      free (result);

      parse_res = _nss_files_parse_spent (p, sp, (void *) buffer, buflen,
                                     errnop);
      if (__builtin_expect  (parse_res == -1, 0))
       {
         free (outkey);
         *errnop = ERANGE;
         return NSS_STATUS_TRYAGAIN;
       }

      free (oldkey);
      oldkey = outkey;
      oldkeylen = keylen;
      new_start = 0;
    }
  while (!parse_res);

  return NSS_STATUS_SUCCESS;
}

Here is the call graph for this function: