Patch by Fred Gansevles (the module's original author).

This patch fixes 3 small problems.
1) If a map is used which is generated with 'makedbm -a',
   the trailing '\0' is now handled correctely.
2) The nis.maps() function skipped the first map in the output list.
3) The library '-lnsl' is added in Setup.in (needed on Linux glibc2 and
   Solaris systems. Maybe on other systems too?)

[I note that this still doesn't work when you are using NIS+ --GvR]
This commit is contained in:
Guido van Rossum 2000-02-29 15:52:40 +00:00
parent 43713e5a28
commit 61b705a570
2 changed files with 58 additions and 28 deletions

View File

@ -164,7 +164,7 @@ socket socketmodule.c # socket(2); not on ancient System V
# Some more UNIX dependent modules -- off by default, since these # Some more UNIX dependent modules -- off by default, since these
# are not supported by all UNIX systems: # are not supported by all UNIX systems:
#nis nismodule.c # Sun yellow pages -- not everywhere #nis nismodule.c -lnsl # Sun yellow pages -- not everywhere
#termios termios.c # Steen Lumholt's termios module #termios termios.c # Steen Lumholt's termios module
#resource resource.c # Jeremy Hylton's rlimit interface #resource resource.c # Jeremy Hylton's rlimit interface

View File

@ -1,7 +1,7 @@
/*********************************************************** /***********************************************************
Written by: Written by:
Fred Gansevles <Fred.Gansevles@cs.utwente.nl> Fred Gansevles <Fred.Gansevles@cs.utwente.nl>
Vakgroep Spa, B&O group,
Faculteit der Informatica, Faculteit der Informatica,
Universiteit Twente, Universiteit Twente,
Enschede, Enschede,
@ -36,32 +36,48 @@ nis_error (err)
static struct nis_map { static struct nis_map {
char *alias; char *alias;
char *map; char *map;
int fix;
} aliases [] = { } aliases [] = {
{"passwd", "passwd.byname"}, {"passwd", "passwd.byname", 0},
{"group", "group.byname"}, {"group", "group.byname", 0},
{"networks", "networks.byaddr"}, {"networks", "networks.byaddr", 0},
{"hosts", "hosts.byname"}, {"hosts", "hosts.byname", 0},
{"protocols", "protocols.bynumber"}, {"protocols", "protocols.bynumber", 0},
{"services", "services.byname"}, {"services", "services.byname", 0},
{"aliases", "mail.aliases"}, {"aliases", "mail.aliases", 1}, /* created with 'makedbm -a' */
{"ethers", "ethers.byname"}, {"ethers", "ethers.byname", 0},
{0L, 0L} {0L, 0L, 0}
}; };
static char * static char *
nis_mapname (map) nis_mapname (map, pfix)
char *map; char *map;
int *pfix;
{ {
int i; int i;
for (i=0; aliases[i].alias != 0L; i++) *pfix = 0;
if (!strcmp (aliases[i].alias, map)) for (i=0; aliases[i].alias != 0L; i++) {
map = aliases[i].map; if (!strcmp (aliases[i].alias, map)) {
*pfix = aliases[i].fix;
return aliases[i].map;
}
if (!strcmp (aliases[i].map, map)) {
*pfix = aliases[i].fix;
return aliases[i].map;
}
}
return map; return map;
} }
typedef int (*foreachfunc) Py_PROTO((int, char *, int, char *, int, char *)); typedef int (*foreachfunc) Py_PROTO((int, char *, int, char *, int, char *));
struct ypcallback_data {
PyObject *dict;
int fix;
};
static int static int
nis_foreach (instatus, inkey, inkeylen, inval, invallen, indata) nis_foreach (instatus, inkey, inkeylen, inval, invallen, indata)
int instatus; int instatus;
@ -69,12 +85,19 @@ nis_foreach (instatus, inkey, inkeylen, inval, invallen, indata)
int inkeylen; int inkeylen;
char *inval; char *inval;
int invallen; int invallen;
PyObject *indata; struct ypcallback_data *indata;
{ {
if (instatus == YP_TRUE) { if (instatus == YP_TRUE) {
PyObject *key = PyString_FromStringAndSize(inkey, inkeylen); PyObject *key;
PyObject *val = PyString_FromStringAndSize(inval, invallen); PyObject *val;
int err; int err;
if (indata->fix) {
inkeylen--;
invallen--;
}
key = PyString_FromStringAndSize(inkey, inkeylen);
val = PyString_FromStringAndSize(inval, invallen);
if (key == NULL || val == NULL) { if (key == NULL || val == NULL) {
/* XXX error -- don't know how to handle */ /* XXX error -- don't know how to handle */
PyErr_Clear(); PyErr_Clear();
@ -82,7 +105,7 @@ nis_foreach (instatus, inkey, inkeylen, inval, invallen, indata)
Py_XDECREF(val); Py_XDECREF(val);
return 1; return 1;
} }
err = PyDict_SetItem(indata, key, val); err = PyDict_SetItem(indata->dict, key, val);
Py_DECREF(key); Py_DECREF(key);
Py_DECREF(val); Py_DECREF(val);
if (err != 0) { if (err != 0) {
@ -105,15 +128,20 @@ nis_match (self, args)
char *key, *map; char *key, *map;
int err; int err;
PyObject *res; PyObject *res;
int fix;
if (!PyArg_Parse(args, "(t#s)", &key, &keylen, &map)) if (!PyArg_Parse(args, "(t#s)", &key, &keylen, &map))
return NULL; return NULL;
if ((err = yp_get_default_domain(&domain)) != 0) if ((err = yp_get_default_domain(&domain)) != 0)
return nis_error(err); return nis_error(err);
map = nis_mapname (map, &fix);
if (fix)
keylen++;
Py_BEGIN_ALLOW_THREADS Py_BEGIN_ALLOW_THREADS
map = nis_mapname (map);
err = yp_match (domain, map, key, keylen, &match, &len); err = yp_match (domain, map, key, keylen, &match, &len);
Py_END_ALLOW_THREADS Py_END_ALLOW_THREADS
if (fix)
len--;
if (err != 0) if (err != 0)
return nis_error(err); return nis_error(err);
res = PyString_FromStringAndSize (match, len); res = PyString_FromStringAndSize (match, len);
@ -129,27 +157,29 @@ nis_cat (self, args)
char *domain; char *domain;
char *map; char *map;
struct ypall_callback cb; struct ypall_callback cb;
PyObject *cat; struct ypcallback_data data;
PyObject *dict;
int err; int err;
if (!PyArg_Parse(args, "s", &map)) if (!PyArg_Parse(args, "s", &map))
return NULL; return NULL;
if ((err = yp_get_default_domain(&domain)) != 0) if ((err = yp_get_default_domain(&domain)) != 0)
return nis_error(err); return nis_error(err);
cat = PyDict_New (); dict = PyDict_New ();
if (cat == NULL) if (dict == NULL)
return NULL; return NULL;
cb.foreach = (foreachfunc)nis_foreach; cb.foreach = (foreachfunc)nis_foreach;
cb.data = (char *)cat; data.dict = dict;
map = nis_mapname (map, &data.fix);
cb.data = (char *)&data;
Py_BEGIN_ALLOW_THREADS Py_BEGIN_ALLOW_THREADS
map = nis_mapname (map);
err = yp_all (domain, map, &cb); err = yp_all (domain, map, &cb);
Py_END_ALLOW_THREADS Py_END_ALLOW_THREADS
if (err != 0) { if (err != 0) {
Py_DECREF(cat); Py_DECREF(dict);
return nis_error(err); return nis_error(err);
} }
return cat; return dict;
} }
/* These should be u_long on Sun h/w but not on 64-bit h/w. /* These should be u_long on Sun h/w but not on 64-bit h/w.
@ -345,7 +375,7 @@ nis_maps (self, args)
return NULL; return NULL;
if ((list = PyList_New(0)) == NULL) if ((list = PyList_New(0)) == NULL)
return NULL; return NULL;
for (maps = maps->next; maps; maps = maps->next) { for (maps = maps; maps; maps = maps->next) {
PyObject *str = PyString_FromString(maps->map); PyObject *str = PyString_FromString(maps->map);
if (!str || PyList_Append(list, str) < 0) if (!str || PyList_Append(list, str) < 0)
{ {