Back to index

glibc  2.9
Defines | Functions | Variables
netname.c File Reference
#include <stdio.h>
#include <unistd.h>
#include <string.h>
#include <rpc/rpc.h>
#include "nsswitch.h"

Go to the source code of this file.

Defines

#define OPSYS_LEN   4
#define MAXIPRINT   (11) /* max length of printed integer */

Functions

int user2netname (char netname[MAXNETNAMELEN+1], const uid_t uid, const char *domain)
 libc_hidden_def (user2netname)
 libc_hidden_def (host2netname)
 libc_hidden_def (getnetname)
 libc_hidden_def (netname2user)

Variables

static const char OPSYS [] = "unix"

Define Documentation

#define MAXIPRINT   (11) /* max length of printed integer */

Definition at line 28 of file netname.c.

#define OPSYS_LEN   4

Definition at line 27 of file netname.c.


Function Documentation

Definition at line 58 of file netname.c.

{
  char *p;
  char hostname[MAXHOSTNAMELEN + 1];
  char domainname[MAXHOSTNAMELEN + 1];
  char *dot_in_host;
  size_t i;

  netname[0] = '\0';        /* make null first (no need for memset) */

  if (host == NULL)
    __gethostname (hostname, MAXHOSTNAMELEN);
  else
    {
      strncpy (hostname, host, MAXHOSTNAMELEN);
      hostname[MAXHOSTNAMELEN] = '\0';
    }

  dot_in_host = strchr (hostname, '.');
  if (domain == NULL)
    {
      p = dot_in_host;
      if (p)
       {
         ++p;
         strncpy (domainname, p, MAXHOSTNAMELEN);
         domainname[MAXHOSTNAMELEN] = '\0';
       }
      else
       {
         domainname[0] = 0;
         getdomainname (domainname, MAXHOSTNAMELEN);
       }
    }
  else
    {
      strncpy (domainname, domain, MAXHOSTNAMELEN);
      domainname[MAXHOSTNAMELEN] = '\0';
    }

  i = strlen (domainname);
  if (i == 0)
    /* No domainname */
    return 0;
  if (domainname[i - 1] == '.')
    domainname[i - 1] = 0;

  if (dot_in_host)          /* strip off rest of name */
    *dot_in_host = '\0';

  if ((strlen (domainname) + strlen (hostname) + OPSYS_LEN + 3)
      > MAXNETNAMELEN)
    return 0;

  sprintf (netname, "%s.%s@%s", OPSYS, hostname, domainname);
  return 1;
}

Here is the call graph for this function:

Definition at line 119 of file netname.c.

{
  uid_t uid;
  int dummy;

  uid = __geteuid ();
  if (uid == 0)
    dummy = host2netname (name, NULL, NULL);
  else
    dummy = user2netname (name, uid, NULL);
  return (dummy);
}

Here is the call graph for this function:

Definition at line 134 of file netname.c.

{
  static service_user *startp;
  static netname2user_function start_fct;
  service_user *nip;
  union
  {
    netname2user_function f;
    void *ptr;
  } fct;
  enum nss_status status = NSS_STATUS_UNAVAIL;
  int no_more;

  if (startp == NULL)
    {
      no_more = __nss_publickey_lookup (&nip, "netname2user", &fct.ptr);
      if (no_more)
       startp = (service_user *) - 1;
      else
       {
         startp = nip;
         start_fct = fct.f;
       }
    }
  else
    {
      fct.f = start_fct;
      no_more = (nip = startp) == (service_user *) - 1;
    }

  while (!no_more)
    {
      status = (*fct.f) (netname, uidp, gidp, gidlenp, gidlist);

      no_more = __nss_next2 (&nip, "netname2user", NULL, &fct.ptr, status, 0);
    }

  return status == NSS_STATUS_SUCCESS;
}

Here is the call graph for this function:

Definition at line 184 of file netname.c.

{
  char *p1, *p2;
  char buffer[MAXNETNAMELEN + 1];

  p1 = strchr (buffer, '.');
  if (p1 == NULL)
    return 0;
  p1++;

  p2 = strchr (p1, '@');
  if (p2 == NULL)
    return 0;
  *p2 = '\0';

  if (hostlen > MAXNETNAMELEN)
    return 0;

  strncpy (hostname, p1, hostlen);
  hostname[hostlen] = '\0';

  return 1;
}
int user2netname ( char  netname[MAXNETNAMELEN+1],
const uid_t  uid,
const char *  domain 
)

Definition at line 32 of file netname.c.

{
  char dfltdom[MAXNETNAMELEN + 1];
  size_t i;

  if (domain == NULL)
    {
      if (getdomainname (dfltdom, sizeof (dfltdom)) < 0)
       return 0;
    }
  else
    {
      strncpy (dfltdom, domain, MAXNETNAMELEN);
      dfltdom[MAXNETNAMELEN] = '\0';
    }

  if ((strlen (dfltdom) + OPSYS_LEN + 3 + MAXIPRINT) > (size_t) MAXNETNAMELEN)
    return 0;

  sprintf (netname, "%s.%d@%s", OPSYS, uid, dfltdom);
  i = strlen (netname);
  if (netname[i - 1] == '.')
    netname[i - 1] = '\0';
  return 1;
}

Here is the call graph for this function:

Here is the caller graph for this function:


Variable Documentation

const char OPSYS[] = "unix" [static]

Definition at line 29 of file netname.c.