ReactOS  0.4.13-dev-247-g0f29b3f
netname.c File Reference
#include <wintirpc.h>
#include <rpc/rpc.h>
#include "rpc_com.h"
#include <ctype.h>
#include <limits.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
Include dependency graph for netname.c:

Go to the source code of this file.

Macros

#define MAXHOSTNAMELEN   256
 
#define NGROUPS   16
 
#define TYPE_BIT(type)   (sizeof (type) * CHAR_BIT)
 
#define TYPE_SIGNED(type)   (((type) -1) < 0)
 
#define INT_STRLEN_MAXIMUM(type)   ((TYPE_BIT(type) - TYPE_SIGNED(type)) * 302 / 1000 + 1 + TYPE_SIGNED(type))
 

Functions

int getnetname (name)
 
int user2netname (netname, const uid_t uid, const char *domain)
 
int host2netname (netname, const char *host, const char *domain)
 

Variables

static charOPSYS = "unix"
 

Macro Definition Documentation

◆ INT_STRLEN_MAXIMUM

#define INT_STRLEN_MAXIMUM (   type)    ((TYPE_BIT(type) - TYPE_SIGNED(type)) * 302 / 1000 + 1 + TYPE_SIGNED(type))

Definition at line 69 of file netname.c.

◆ MAXHOSTNAMELEN

#define MAXHOSTNAMELEN   256

Definition at line 53 of file netname.c.

◆ NGROUPS

#define NGROUPS   16

Definition at line 56 of file netname.c.

◆ TYPE_BIT

#define TYPE_BIT (   type)    (sizeof (type) * CHAR_BIT)

Definition at line 59 of file netname.c.

◆ TYPE_SIGNED

#define TYPE_SIGNED (   type)    (((type) -1) < 0)

Definition at line 61 of file netname.c.

Function Documentation

◆ getnetname()

int getnetname ( name  )

Definition at line 78 of file netname.c.

80 {
81 #ifdef _WIN32
82  /* I don't understand what these underlying routines are accomplishing??? */
83  return 1;
84 #else
85  uid_t uid;
86 
87  uid = geteuid();
88  if (uid == 0) {
89  return (host2netname(name, (char *) NULL, (char *) NULL));
90  } else {
91  return (user2netname(name, uid, (char *) NULL));
92  }
93 #endif
94 }
long uid_t
Definition: various.h:8
smooth NULL
Definition: ftsmooth.c:416
int user2netname(netname, const uid_t uid, const char *domain)
Definition: netname.c:101
EXPORT uid_t geteuid()
Definition: uid.c:37
Definition: name.c:36
int host2netname(netname, const char *host, const char *domain)
Definition: netname.c:126

Referenced by authdes_pk_seccreate().

◆ host2netname()

int host2netname ( netname  ,
const char host,
const char domain 
)

Definition at line 126 of file netname.c.

130 {
131  char *dfltdom;
132  char hostname[MAXHOSTNAMELEN+1];
133 
134  if (domain == NULL) {
135  if (__rpc_get_default_domain(&dfltdom) != 0) {
136  return (0);
137  }
138  domain = dfltdom;
139  }
140  if (host == NULL) {
141  (void) gethostname(hostname, sizeof(hostname));
142  host = hostname;
143  }
144  if (strlen(domain) + 1 + strlen(host) + 1 + strlen(OPSYS) > MAXNETNAMELEN) {
145  return (0);
146  }
147  (void) sprintf(netname, "%s.%s@%s", OPSYS, host, domain);
148  return (1);
149 }
struct png_info_def **typedef void(__cdecl typeof(png_destroy_read_struct))(struct png_struct_def **
Definition: typeof.h:49
ACPI_SIZE strlen(const char *String)
Definition: utclib.c:269
#define MAXHOSTNAMELEN
Definition: netname.c:53
int __rpc_get_default_domain(char **)
Definition: rpcdname.c:72
char * host
Definition: whois.c:55
char * hostname
Definition: ftp.c:88
#define sprintf(buf, format,...)
Definition: sprintf.c:55
INT WSAAPI gethostname(OUT char FAR *name, IN INT namelen)
Definition: getxbyxx.c:397
smooth NULL
Definition: ftsmooth.c:416
static char * OPSYS
Definition: netname.c:72
#define MAXNETNAMELEN
Definition: auth.h:78

Referenced by getnetname().

◆ user2netname()

int user2netname ( netname  ,
const uid_t  uid,
const char domain 
)

Definition at line 101 of file netname.c.

105 {
106  char *dfltdom;
107 
108  if (domain == NULL) {
109  if (__rpc_get_default_domain(&dfltdom) != 0) {
110  return (0);
111  }
112  domain = dfltdom;
113  }
114  if (strlen(domain) + 1 + INT_STRLEN_MAXIMUM(u_long) + 1 + strlen(OPSYS) > MAXNETNAMELEN) {
115  return (0);
116  }
117  (void) sprintf(netname, "%s.%ld@%s", OPSYS, (u_long)uid, domain);
118  return (1);
119 }
struct png_info_def **typedef void(__cdecl typeof(png_destroy_read_struct))(struct png_struct_def **
Definition: typeof.h:49
unsigned long u_long
Definition: linux.h:269
ACPI_SIZE strlen(const char *String)
Definition: utclib.c:269
int __rpc_get_default_domain(char **)
Definition: rpcdname.c:72
#define sprintf(buf, format,...)
Definition: sprintf.c:55
smooth NULL
Definition: ftsmooth.c:416
static char * OPSYS
Definition: netname.c:72
#define INT_STRLEN_MAXIMUM(type)
Definition: netname.c:69
#define MAXNETNAMELEN
Definition: auth.h:78

Referenced by getnetname().

Variable Documentation

◆ OPSYS

char* OPSYS = "unix"
static

Definition at line 72 of file netname.c.

Referenced by host2netname(), and user2netname().