Skip to content

Commit

Permalink
* nss/getXXent.c (GETFUNC_NAME): Use union type to avoid strict
Browse files Browse the repository at this point in the history
aliasing problem. 
* nss/getXXbyYY_r.c (INTERNAL): Likewise. 
* nss/getnssent_r.c (__nss_getent_r): Likewise. 
(__nss_setent): Likewise. 
(__nss_getent_r): Likewise. 
* inet/getnetgrent_r.c (innetgr): Likewise. 
(__internal_setnetgrent_reuse): Likewise. 
(internal_getnetgrent_r): Likewise. 
* inet/ether_hton.c (ether_hostton): Likewise. 
* inet/ether_ntoh.c (ether_ntohost): Likewise. 
* sunrpc/netname.c (netname2user): Likewise. 
* sunrpc/publickey.c (getpublickey): Likewise. 
(getsecretkey): Likewise.
  • Loading branch information
ajaeger committed Nov 10, 2002
1 parent 55c303a commit fb776f3
Show file tree
Hide file tree
Showing 8 changed files with 161 additions and 92 deletions.
16 changes: 10 additions & 6 deletions inet/ether_hton.c
Original file line number Diff line number Diff line change
Expand Up @@ -39,35 +39,39 @@ ether_hostton (const char *hostname, struct ether_addr *addr)
static service_user *startp;
static lookup_function start_fct;
service_user *nip;
lookup_function fct;
union
{
lookup_function f;
void *ptr;
} fct;
int no_more;
enum nss_status status = NSS_STATUS_UNAVAIL;
struct etherent etherent;

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

while (no_more == 0)
{
char buffer[1024];

status = (*fct) (hostname, &etherent, buffer, sizeof buffer, &errno);
status = (*fct.f) (hostname, &etherent, buffer, sizeof buffer, &errno);

no_more = __nss_next (&nip, "gethostton_r", (void **) &fct, status, 0);
no_more = __nss_next (&nip, "gethostton_r", &fct.ptr, status, 0);
}

if (status == NSS_STATUS_SUCCESS)
Expand Down
16 changes: 10 additions & 6 deletions inet/ether_ntoh.c
Original file line number Diff line number Diff line change
Expand Up @@ -40,35 +40,39 @@ ether_ntohost (char *hostname, const struct ether_addr *addr)
static service_user *startp;
static lookup_function start_fct;
service_user *nip;
lookup_function fct;
union
{
lookup_function f;
void *ptr;
} fct;
int no_more;
enum nss_status status = NSS_STATUS_UNAVAIL;
struct etherent etherent;

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

while (no_more == 0)
{
char buffer[1024];

status = (*fct) (addr, &etherent, buffer, sizeof buffer, &errno);
status = (*fct.f) (addr, &etherent, buffer, sizeof buffer, &errno);

no_more = __nss_next (&nip, "getntohost_r", (void **) &fct, status, 0);
no_more = __nss_next (&nip, "getntohost_r", &fct.ptr, status, 0);
}

if (status == NSS_STATUS_SUCCESS)
Expand Down
68 changes: 46 additions & 22 deletions inet/getnetgrent_r.c
Original file line number Diff line number Diff line change
Expand Up @@ -96,19 +96,23 @@ internal_function
__internal_setnetgrent_reuse (const char *group, struct __netgrent *datap,
int *errnop)
{
enum nss_status (*fct) (const char *, struct __netgrent *);
union
{
enum nss_status (*f) (const char *, struct __netgrent *);
void *ptr;
} fct;
enum nss_status status = NSS_STATUS_UNAVAIL;
struct name_list *new_elem;
int no_more;

/* Cycle through all the services and run their setnetgrent functions. */
no_more = setup ((void **) &fct, "setnetgrent", 1);
no_more = setup (&fct.ptr, "setnetgrent", 1);
while (! no_more)
{
/* Ignore status, we force check in `__nss_next'. */
status = (*fct) (group, datap);
status = (*fct.f) (group, datap);

no_more = __nss_next (&nip, "setnetgrent", (void **) &fct, status, 0);
no_more = __nss_next (&nip, "setnetgrent", &fct.ptr, status, 0);
}

/* Add the current group to the list of known groups. */
Expand Down Expand Up @@ -158,21 +162,25 @@ static void
internal_endnetgrent (struct __netgrent *datap)
{
service_user *old_nip;
enum nss_status (*fct) (struct __netgrent *);
union
{
enum nss_status (*f) (struct __netgrent *);
void *ptr;
} fct;
int no_more;

/* Remember which was the last used service. */
old_nip = nip;

/* Cycle through all the services and run their endnetgrent functions. */
no_more = setup ((void **) &fct, "endnetgrent", 1);
no_more = setup (&fct.ptr, "endnetgrent", 1);
while (! no_more)
{
/* Ignore status, we force check in `__nss_next'. */
(void) (*fct) (datap);
(void) (*fct.f) (datap);

no_more = (nip == old_nip
|| __nss_next (&nip, "endnetgrent", (void **) &fct, 0, 1));
|| __nss_next (&nip, "endnetgrent", &fct.ptr, 0, 1));
}

/* Now free list of all netgroup names from last run. */
Expand All @@ -197,7 +205,11 @@ internal_getnetgrent_r (char **hostp, char **userp, char **domainp,
struct __netgrent *datap,
char *buffer, size_t buflen, int *errnop)
{
enum nss_status (*fct) (struct __netgrent *, char *, size_t, int *);
union
{
enum nss_status (*f) (struct __netgrent *, char *, size_t, int *);
void *ptr;
} fct;
int no_more;

/* Initialize status to return if no more functions are found. */
Expand All @@ -206,10 +218,10 @@ internal_getnetgrent_r (char **hostp, char **userp, char **domainp,
/* Run through available functions, starting with the same function last
run. We will repeat each function as long as it succeeds, and then go
on to the next service action. */
no_more = setup ((void **) &fct, "getnetgrent_r", 0);
no_more = setup (&fct.ptr, "getnetgrent_r", 0);
while (! no_more)
{
status = (*fct) (datap, buffer, buflen, &errno);
status = (*fct.f) (datap, buffer, buflen, &errno);

if (status == NSS_STATUS_RETURN)
{
Expand Down Expand Up @@ -262,7 +274,7 @@ internal_getnetgrent_r (char **hostp, char **userp, char **domainp,
}
}

no_more = __nss_next (&nip, "getnetgrent_r", (void **) &fct, status, 0);
no_more = __nss_next (&nip, "getnetgrent_r", &fct.ptr, status, 0);
}

if (status == NSS_STATUS_SUCCESS)
Expand Down Expand Up @@ -299,9 +311,21 @@ int
innetgr (const char *netgroup, const char *host, const char *user,
const char *domain)
{
int (*setfct) (const char *, struct __netgrent *);
void (*endfct) (struct __netgrent *);
int (*getfct) (struct __netgrent *, char *, size_t, int *);
union
{
int (*f) (const char *, struct __netgrent *);
void *ptr;
} setfct;
union
{
void (*f) (struct __netgrent *);
void *ptr;
} endfct;
union
{
int (*f) (struct __netgrent *, char *, size_t, int *);
void *ptr;
} getfct;
struct name_list *known = NULL;
struct name_list *needed = NULL;
int result = 0;
Expand All @@ -315,7 +339,7 @@ innetgr (const char *netgroup, const char *host, const char *user,
the work during one walk through the service list. */
while (1)
{
no_more = setup ((void **) &setfct, "setnetgrent", 1);
no_more = setup (&setfct.ptr, "setnetgrent", 1);
while (! no_more)
{
enum nss_status status;
Expand All @@ -325,13 +349,13 @@ innetgr (const char *netgroup, const char *host, const char *user,
__bzero (&entry, sizeof (entry));

/* Open netgroup. */
status = (*setfct) (current_group, &entry);
status = (*setfct.f) (current_group, &entry);
if (status == NSS_STATUS_SUCCESS
&& __nss_lookup (&nip, "getnetgrent_r", (void **) &getfct) == 0)
&& __nss_lookup (&nip, "getnetgrent_r", &getfct.ptr) == 0)
{
char buffer[1024];

while ((*getfct) (&entry, buffer, sizeof buffer, &errno)
while ((*getfct.f) (&entry, buffer, sizeof buffer, &errno)
== NSS_STATUS_SUCCESS)
{
if (entry.type == group_val)
Expand Down Expand Up @@ -389,12 +413,12 @@ innetgr (const char *netgroup, const char *host, const char *user,
}

/* Free all resources of the service. */
if (__nss_lookup (&nip, "endnetgrent", (void **) &endfct) == 0)
(*endfct) (&entry);
if (__nss_lookup (&nip, "endnetgrent", &endfct.ptr) == 0)
(*endfct.f) (&entry);

/* Look for the next service. */
no_more = __nss_next (&nip, "setnetgrent",
(void **) &setfct, status, 0);
&setfct.ptr, status, 0);
}

if (result == 0 && needed != NULL)
Expand Down
45 changes: 25 additions & 20 deletions nss/getXXbyYY_r.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,30 +32,30 @@
#endif
/*******************************************************************\
|* Here we assume several symbols to be defined: *|
|* *|
|* *|
|* LOOKUP_TYPE - the return type of the function *|
|* *|
|* *|
|* FUNCTION_NAME - name of the non-reentrant function *|
|* *|
|* *|
|* DATABASE_NAME - name of the database the function accesses *|
|* (e.g., host, services, ...) *|
|* *|
|* *|
|* ADD_PARAMS - additional parameter, can vary in number *|
|* *|
|* *|
|* ADD_VARIABLES - names of additional parameter *|
|* *|
|* *|
|* Optionally the following vars can be defined: *|
|* *|
|* *|
|* NEED_H_ERRNO - an extra parameter will be passed to point to *|
|* the global `h_errno' variable. *|
|* *|
|* *|
|* NEED__RES - the global _res variable might be used so we *|
|* will have to initialize it if necessary *|
|* *|
|* will have to initialize it if necessary *|
|* *|
|* PREPROCESS - code run before anything else *|
|* *|
|* *|
|* POSTPROCESS - code run after the lookup *|
|* *|
|* *|
\*******************************************************************/

/* To make the real sources a bit prettier. */
Expand Down Expand Up @@ -130,7 +130,12 @@ INTERNAL (REENTRANT_NAME) (ADD_PARAMS, LOOKUP_TYPE *resbuf, char *buffer,
static service_user *startp;
static lookup_function start_fct;
service_user *nip;
lookup_function fct;
union
{
lookup_function l;
void *ptr;
} fct;

int no_more;
enum nss_status status = NSS_STATUS_UNAVAIL;
#ifdef USE_NSCD
Expand Down Expand Up @@ -175,13 +180,13 @@ INTERNAL (REENTRANT_NAME) (ADD_PARAMS, LOOKUP_TYPE *resbuf, char *buffer,

if (startp == NULL)
{
no_more = DB_LOOKUP_FCT (&nip, REENTRANT_NAME_STRING, (void **) &fct);
no_more = DB_LOOKUP_FCT (&nip, REENTRANT_NAME_STRING, &fct.ptr);
if (no_more)
startp = (service_user *) -1l;
else
{
startp = nip;
start_fct = fct;
start_fct = fct.l;

#ifdef NEED__RES
/* The resolver code will really be used so we have to
Expand All @@ -201,7 +206,7 @@ INTERNAL (REENTRANT_NAME) (ADD_PARAMS, LOOKUP_TYPE *resbuf, char *buffer,
}
else
{
fct = start_fct;
fct.l = start_fct;
no_more = (nip = startp) == (service_user *) -1l;
}

Expand All @@ -211,8 +216,8 @@ INTERNAL (REENTRANT_NAME) (ADD_PARAMS, LOOKUP_TYPE *resbuf, char *buffer,
any_service = true;
#endif

status = DL_CALL_FCT (fct, (ADD_VARIABLES, resbuf, buffer, buflen,
&errno H_ERRNO_VAR));
status = DL_CALL_FCT (fct.l, (ADD_VARIABLES, resbuf, buffer, buflen,
&errno H_ERRNO_VAR));

/* The status is NSS_STATUS_TRYAGAIN and errno is ERANGE the
provided buffer is too small. In this case we should give
Expand All @@ -227,7 +232,7 @@ INTERNAL (REENTRANT_NAME) (ADD_PARAMS, LOOKUP_TYPE *resbuf, char *buffer,
break;

no_more = __nss_next (&nip, REENTRANT_NAME_STRING,
(void **) &fct, status, 0);
&fct.ptr, status, 0);
}

#ifdef HANDLE_DIGITS_DOTS
Expand Down Expand Up @@ -262,7 +267,7 @@ OLD (REENTRANT_NAME) (ADD_PARAMS, LOOKUP_TYPE *resbuf, char *buffer,
size_t buflen, LOOKUP_TYPE **result H_ERRNO_PARM)
{
int ret = INTERNAL (REENTRANT_NAME) (ADD_VARIABLES, resbuf, buffer,
buflen, result H_ERRNO_VAR);
buflen, result H_ERRNO_VAR);

if (ret != 0)
ret = -1;
Expand Down
8 changes: 6 additions & 2 deletions nss/getXXent.c
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,11 @@ LOOKUP_TYPE *
GETFUNC_NAME (void)
{
static size_t buffer_size;
static LOOKUP_TYPE resbuf;
static union
{
LOOKUP_TYPE l;
void *ptr;
} resbuf;
LOOKUP_TYPE *result;
int save;

Expand All @@ -79,7 +83,7 @@ GETFUNC_NAME (void)

result = (LOOKUP_TYPE *)
__nss_getent ((getent_r_function) INTERNAL (REENTRANT_GETNAME),
(void **) &resbuf, &buffer, BUFLEN, &buffer_size,
&resbuf.ptr, &buffer, BUFLEN, &buffer_size,
H_ERRNO_VAR);

save = errno;
Expand Down
Loading

0 comments on commit fb776f3

Please sign in to comment.