Added error handling and free resources.
This commit is contained in:
parent
9de7a01e0e
commit
3562d52e93
|
@ -20,6 +20,16 @@
|
|||
#include <rpc/rpc.h>
|
||||
#include <rpcsvc/yp_prot.h>
|
||||
|
||||
static object *NisError;
|
||||
|
||||
static object *
|
||||
nis_error (err)
|
||||
int err;
|
||||
{
|
||||
err_setstr(NisError, yperr_string(err));
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static struct nis_map {
|
||||
char *alias;
|
||||
char *map;
|
||||
|
@ -74,16 +84,22 @@ char *match;
|
|||
char *domain;
|
||||
int len;
|
||||
char *key, *map;
|
||||
int err;
|
||||
object *res;
|
||||
|
||||
if (!getstrstrarg(args, &key, &map))
|
||||
return NULL;
|
||||
map = nis_mapname (map);
|
||||
if ((err = yp_get_default_domain(&domain)) != 0)
|
||||
return nis_error(err);
|
||||
BGN_SAVE
|
||||
yp_get_default_domain(&domain);
|
||||
if (yp_match (domain, map, key, strlen (key), &match, &len) == 0)
|
||||
match[len] = 0;
|
||||
map = nis_mapname (map);
|
||||
err = yp_match (domain, map, key, strlen (key), &match, &len);
|
||||
END_SAVE
|
||||
return newstringobject (match);
|
||||
if (err != 0)
|
||||
return nis_error(err);
|
||||
res = newsizedstringobject (match, len);
|
||||
free (match);
|
||||
return res;
|
||||
}
|
||||
|
||||
static object *
|
||||
|
@ -95,19 +111,25 @@ char *domain;
|
|||
char *map;
|
||||
struct ypall_callback cb;
|
||||
object *cat;
|
||||
int err;
|
||||
|
||||
if (!getstrarg(args, &map))
|
||||
return NULL;
|
||||
if ((err = yp_get_default_domain(&domain)) != 0)
|
||||
return nis_error(err);
|
||||
cat = newdictobject ();
|
||||
if (cat == NULL)
|
||||
return NULL;
|
||||
map = nis_mapname (map);
|
||||
cb.foreach = nis_foreach;
|
||||
cb.data = (char *)cat;
|
||||
yp_get_default_domain(&domain);
|
||||
BGN_SAVE
|
||||
yp_all (domain, map, &cb);
|
||||
map = nis_mapname (map);
|
||||
err = yp_all (domain, map, &cb);
|
||||
END_SAVE
|
||||
if (err != 0) {
|
||||
DECREF(cat);
|
||||
return nis_error(err);
|
||||
}
|
||||
return cat;
|
||||
}
|
||||
|
||||
|
@ -223,11 +245,7 @@ nisproc_maplist_2(argp, clnt)
|
|||
{
|
||||
static nisresp_maplist res;
|
||||
|
||||
#ifdef hpux
|
||||
memset(&res, 0, sizeof(res));
|
||||
#else hpux
|
||||
memset(&res, sizeof(res));
|
||||
#endif hpux
|
||||
if (clnt_call(clnt, YPPROC_MAPLIST, nis_xdr_domainname, argp, nis_xdr_ypresp_maplist
|
||||
, &res, TIMEOUT) != RPC_SUCCESS) {
|
||||
return (NULL);
|
||||
|
@ -271,10 +289,14 @@ object *list;
|
|||
return NULL;
|
||||
if ((list = newlistobject(0)) == NULL)
|
||||
return NULL;
|
||||
BGN_SAVE
|
||||
for (maps = maps->next; maps; maps = maps->next)
|
||||
addlistitem (list, newstringobject (maps->map));
|
||||
END_SAVE
|
||||
for (maps = maps->next; maps; maps = maps->next) {
|
||||
if (addlistitem (list, newstringobject (maps->map)) < 0) {
|
||||
DECREF(list);
|
||||
list = NULL;
|
||||
break;
|
||||
}
|
||||
}
|
||||
/* XXX Shouldn't we free the list of maps now? */
|
||||
return list;
|
||||
}
|
||||
|
||||
|
@ -288,5 +310,10 @@ static struct methodlist nis_methods[] = {
|
|||
void
|
||||
initnis ()
|
||||
{
|
||||
(void) initmodule("nis", nis_methods);
|
||||
object *m, *d;
|
||||
m = initmodule("nis", nis_methods);
|
||||
d = getmoduledict(m);
|
||||
NisError = newstringobject("nis.error");
|
||||
if (NisError == NULL || dictinsert(d, "error", NisError) != 0)
|
||||
fatal("Cannot define nis.error");
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue