[Python-checkins] CVS: python/dist/src/Modules Setup.in,1.89,1.90 nismodule.c,2.14,2.15

Guido van Rossum guido@cnri.reston.va.us
Tue, 29 Feb 2000 10:52:43 -0500 (EST)


Update of /projects/cvsroot/python/dist/src/Modules
In directory eric:/projects/python/develop/guido/src/Modules

Modified Files:
	Setup.in nismodule.c 
Log Message:
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]


Index: Setup.in
===================================================================
RCS file: /projects/cvsroot/python/dist/src/Modules/Setup.in,v
retrieving revision 1.89
retrieving revision 1.90
diff -C2 -r1.89 -r1.90
*** Setup.in	1999/12/07 21:47:09	1.89
--- Setup.in	2000/02/29 15:52:40	1.90
***************
*** 165,169 ****
  # are not supported by all UNIX systems:
  
! #nis nismodule.c 	# Sun yellow pages -- not everywhere
  #termios termios.c	# Steen Lumholt's termios module
  #resource resource.c	# Jeremy Hylton's rlimit interface
--- 165,169 ----
  # are not supported by all UNIX systems:
  
! #nis nismodule.c -lnsl	# Sun yellow pages -- not everywhere
  #termios termios.c	# Steen Lumholt's termios module
  #resource resource.c	# Jeremy Hylton's rlimit interface

Index: nismodule.c
===================================================================
RCS file: /projects/cvsroot/python/dist/src/Modules/nismodule.c,v
retrieving revision 2.14
retrieving revision 2.15
diff -C2 -r2.14 -r2.15
*** nismodule.c	1998/10/08 02:25:18	2.14
--- nismodule.c	2000/02/29 15:52:40	2.15
***************
*** 2,6 ****
      Written by:
  	Fred Gansevles <Fred.Gansevles@cs.utwente.nl>
! 	Vakgroep Spa,
  	Faculteit der Informatica,
  	Universiteit Twente,
--- 2,6 ----
      Written by:
  	Fred Gansevles <Fred.Gansevles@cs.utwente.nl>
! 	B&O group,
  	Faculteit der Informatica,
  	Universiteit Twente,
***************
*** 37,61 ****
  	char *alias;
  	char *map;
  } aliases [] = {
! 	{"passwd",	"passwd.byname"},
! 	{"group",	"group.byname"},
! 	{"networks",	"networks.byaddr"},
! 	{"hosts",	"hosts.byname"},
! 	{"protocols",	"protocols.bynumber"},
! 	{"services",	"services.byname"},
! 	{"aliases",	"mail.aliases"},
! 	{"ethers",	"ethers.byname"},
! 	{0L,		0L}
  };
  
  static char *
! nis_mapname (map)
  	char *map;
  {
  	int i;
  
! 	for (i=0; aliases[i].alias != 0L; i++)
! 		if (!strcmp (aliases[i].alias, map))
! 			map = aliases[i].map;
  	return map;
  }
--- 37,72 ----
  	char *alias;
  	char *map;
+ 	int  fix;
  } aliases [] = {
! 	{"passwd",	"passwd.byname",	0},
! 	{"group",	"group.byname",		0},
! 	{"networks",	"networks.byaddr",	0},
! 	{"hosts",	"hosts.byname",		0},
! 	{"protocols",	"protocols.bynumber",	0},
! 	{"services",	"services.byname",	0},
! 	{"aliases",	"mail.aliases",		1}, /* created with 'makedbm -a' */
! 	{"ethers",	"ethers.byname",	0},
! 	{0L,		0L,			0}
  };
  
  static char *
! nis_mapname (map, pfix)
  	char *map;
+ 	int *pfix;
  {
  	int i;
  
! 	*pfix = 0;
! 	for (i=0; aliases[i].alias != 0L; i++) {
! 		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;
  }
***************
*** 63,66 ****
--- 74,82 ----
  typedef int (*foreachfunc) Py_PROTO((int, char *, int, char *, int, char *));
  
+ struct ypcallback_data {
+ 	PyObject	*dict;
+ 	int			fix;
+ };
+ 
  static int
  nis_foreach (instatus, inkey, inkeylen, inval, invallen, indata)
***************
*** 70,79 ****
  	char *inval;
  	int invallen;
! 	PyObject *indata;
  {
  	if (instatus == YP_TRUE) {
! 		PyObject *key = PyString_FromStringAndSize(inkey, inkeylen);
! 		PyObject *val = PyString_FromStringAndSize(inval, invallen);
  		int err;
  		if (key == NULL || val == NULL) {
  			/* XXX error -- don't know how to handle */
--- 86,102 ----
  	char *inval;
  	int invallen;
! 	struct ypcallback_data *indata;
  {
  	if (instatus == YP_TRUE) {
! 		PyObject *key;
! 		PyObject *val;
  		int err;
+ 
+ 		if (indata->fix) {
+ 		    inkeylen--;
+ 		    invallen--;
+ 		}
+ 		key = PyString_FromStringAndSize(inkey, inkeylen);
+ 		val = PyString_FromStringAndSize(inval, invallen);
  		if (key == NULL || val == NULL) {
  			/* XXX error -- don't know how to handle */
***************
*** 83,87 ****
  			return 1;
  		}
! 		err = PyDict_SetItem(indata, key, val);
  		Py_DECREF(key);
  		Py_DECREF(val);
--- 106,110 ----
  			return 1;
  		}
! 		err = PyDict_SetItem(indata->dict, key, val);
  		Py_DECREF(key);
  		Py_DECREF(val);
***************
*** 106,109 ****
--- 129,133 ----
  	int err;
  	PyObject *res;
+ 	int fix;
  
  	if (!PyArg_Parse(args, "(t#s)", &key, &keylen, &map))
***************
*** 111,118 ****
  	if ((err = yp_get_default_domain(&domain)) != 0)
  		return nis_error(err);
  	Py_BEGIN_ALLOW_THREADS
- 	map = nis_mapname (map);
  	err = yp_match (domain, map, key, keylen, &match, &len);
  	Py_END_ALLOW_THREADS
  	if (err != 0)
  		return nis_error(err);
--- 135,146 ----
  	if ((err = yp_get_default_domain(&domain)) != 0)
  		return nis_error(err);
+ 	map = nis_mapname (map, &fix);
+ 	if (fix)
+ 	    keylen++;
  	Py_BEGIN_ALLOW_THREADS
  	err = yp_match (domain, map, key, keylen, &match, &len);
  	Py_END_ALLOW_THREADS
+ 	if (fix)
+ 	    len--;
  	if (err != 0)
  		return nis_error(err);
***************
*** 130,134 ****
  	char *map;
  	struct ypall_callback cb;
! 	PyObject *cat;
  	int err;
  
--- 158,163 ----
  	char *map;
  	struct ypall_callback cb;
! 	struct ypcallback_data data;
! 	PyObject *dict;
  	int err;
  
***************
*** 137,154 ****
  	if ((err = yp_get_default_domain(&domain)) != 0)
  		return nis_error(err);
! 	cat = PyDict_New ();
! 	if (cat == NULL)
  		return NULL;
  	cb.foreach = (foreachfunc)nis_foreach;
! 	cb.data = (char *)cat;
  	Py_BEGIN_ALLOW_THREADS
- 	map = nis_mapname (map);
  	err = yp_all (domain, map, &cb);
  	Py_END_ALLOW_THREADS
  	if (err != 0) {
! 		Py_DECREF(cat);
  		return nis_error(err);
  	}
! 	return cat;
  }
  
--- 166,184 ----
  	if ((err = yp_get_default_domain(&domain)) != 0)
  		return nis_error(err);
! 	dict = PyDict_New ();
! 	if (dict == NULL)
  		return NULL;
  	cb.foreach = (foreachfunc)nis_foreach;
! 	data.dict = dict;
! 	map = nis_mapname (map, &data.fix);
! 	cb.data = (char *)&data;
  	Py_BEGIN_ALLOW_THREADS
  	err = yp_all (domain, map, &cb);
  	Py_END_ALLOW_THREADS
  	if (err != 0) {
! 		Py_DECREF(dict);
  		return nis_error(err);
  	}
! 	return dict;
  }
  
***************
*** 346,350 ****
  	if ((list = PyList_New(0)) == NULL)
  		return NULL;
! 	for (maps = maps->next; maps; maps = maps->next) {
  		PyObject *str = PyString_FromString(maps->map);
  		if (!str || PyList_Append(list, str) < 0)
--- 376,380 ----
  	if ((list = PyList_New(0)) == NULL)
  		return NULL;
! 	for (maps = maps; maps; maps = maps->next) {
  		PyObject *str = PyString_FromString(maps->map);
  		if (!str || PyList_Append(list, str) < 0)