2323extern int yp_get_default_domain (char * * );
2424#endif
2525
26+ PyDoc_STRVAR (get_default_domain__doc__ ,
27+ "get_default_domain() -> str\n\
28+ Corresponds to the C library yp_get_default_domain() call, returning\n\
29+ the default NIS domain.\n" );
30+
31+ PyDoc_STRVAR (match__doc__ ,
32+ "match(key, map, domain = defaultdomain)\n\
33+ Corresponds to the C library yp_match() call, returning the value of\n\
34+ key in the given map. Optionally domain can be specified but it\n\
35+ defaults to the system default domain.\n" );
36+
37+ PyDoc_STRVAR (cat__doc__ ,
38+ "cat(map, domain = defaultdomain)\n\
39+ Returns the entire map as a dictionary. Optionally domain can be\n\
40+ specified but it defaults to the system default domain.\n" );
41+
42+ PyDoc_STRVAR (maps__doc__ ,
43+ "maps(domain = defaultdomain)\n\
44+ Returns an array of all available NIS maps within a domain. If domain\n\
45+ is not specified it defaults to the system default domain.\n" );
46+
2647static PyObject * NisError ;
2748
2849static PyObject *
@@ -116,19 +137,36 @@ nis_foreach (int instatus, char *inkey, int inkeylen, char *inval,
116137}
117138
118139static PyObject *
119- nis_match (PyObject * self , PyObject * args )
140+ nis_get_default_domain (PyObject * self )
120141{
121- char * match ;
122142 char * domain ;
143+ int err ;
144+ PyObject * res ;
145+
146+ if ((err = yp_get_default_domain (& domain )) != 0 )
147+ return nis_error (err );
148+
149+ res = PyString_FromStringAndSize (domain , strlen (domain ));
150+ return res ;
151+ }
152+
153+ static PyObject *
154+ nis_match (PyObject * self , PyObject * args , PyObject * kwdict )
155+ {
156+ char * match ;
157+ char * domain = NULL ;
123158 int keylen , len ;
124159 char * key , * map ;
125160 int err ;
126161 PyObject * res ;
127162 int fix ;
163+ static const char * kwlist [] = {"key" , "map" , "domain" , NULL };
128164
129- if (!PyArg_ParseTuple (args , "t#s:match" , & key , & keylen , & map ))
165+ if (!PyArg_ParseTupleAndKeywords (args , kwdict ,
166+ "t#s|s:match" , kwlist ,
167+ & key , & keylen , & map , & domain ))
130168 return NULL ;
131- if (( err = yp_get_default_domain (& domain )) != 0 )
169+ if (! domain && (( err = yp_get_default_domain (& domain )) != 0 ) )
132170 return nis_error (err );
133171 map = nis_mapname (map , & fix );
134172 if (fix )
@@ -146,18 +184,20 @@ nis_match (PyObject *self, PyObject *args)
146184}
147185
148186static PyObject *
149- nis_cat (PyObject * self , PyObject * args )
187+ nis_cat (PyObject * self , PyObject * args , PyObject * kwdict )
150188{
151- char * domain ;
189+ char * domain = NULL ;
152190 char * map ;
153191 struct ypall_callback cb ;
154192 struct ypcallback_data data ;
155193 PyObject * dict ;
156194 int err ;
195+ static const char * kwlist [] = {"map" , "domain" , NULL };
157196
158- if (!PyArg_ParseTuple (args , "s:cat" , & map ))
197+ if (!PyArg_ParseTupleAndKeywords (args , kwdict , "s|s:cat" ,
198+ kwlist , & map , & domain ))
159199 return NULL ;
160- if (( err = yp_get_default_domain (& domain )) != 0 )
200+ if (! domain && (( err = yp_get_default_domain (& domain )) != 0 ) )
161201 return nis_error (err );
162202 dict = PyDict_New ();
163203 if (dict == NULL )
@@ -301,19 +341,12 @@ nisproc_maplist_2(domainname *argp, CLIENT *clnt)
301341
302342static
303343nismaplist *
304- nis_maplist (void )
344+ nis_maplist (char * dom )
305345{
306346 nisresp_maplist * list ;
307- char * dom ;
308347 CLIENT * cl ;
309348 char * server = NULL ;
310349 int mapi = 0 ;
311- int err ;
312-
313- if ((err = yp_get_default_domain (& dom )) != 0 ) {
314- nis_error (err );
315- return NULL ;
316- }
317350
318351 while (!server && aliases [mapi ].map != 0L ) {
319352 yp_master (dom , aliases [mapi ].map , & server );
@@ -344,12 +377,23 @@ nis_maplist (void)
344377}
345378
346379static PyObject *
347- nis_maps (PyObject * self )
380+ nis_maps (PyObject * self , PyObject * args , PyObject * kwdict )
348381{
382+ char * domain = NULL ;
349383 nismaplist * maps ;
350384 PyObject * list ;
385+ int err ;
386+ static const char * kwlist [] = {"domain" , NULL };
351387
352- if ((maps = nis_maplist ()) == NULL )
388+ if (!PyArg_ParseTupleAndKeywords (args , kwdict ,
389+ "|s:maps" , kwlist , & domain ))
390+ return NULL ;
391+ if (!domain && ((err = yp_get_default_domain (& domain )) != 0 )) {
392+ nis_error (err );
393+ return NULL ;
394+ }
395+
396+ if ((maps = nis_maplist (domain )) == NULL )
353397 return NULL ;
354398 if ((list = PyList_New (0 )) == NULL )
355399 return NULL ;
@@ -368,17 +412,29 @@ nis_maps (PyObject *self)
368412}
369413
370414static PyMethodDef nis_methods [] = {
371- {"match" , nis_match , METH_VARARGS },
372- {"cat" , nis_cat , METH_VARARGS },
373- {"maps" , (PyCFunction )nis_maps , METH_NOARGS },
374- {NULL , NULL } /* Sentinel */
415+ {"match" , (PyCFunction )nis_match ,
416+ METH_VARARGS | METH_KEYWORDS ,
417+ match__doc__ },
418+ {"cat" , (PyCFunction )nis_cat ,
419+ METH_VARARGS | METH_KEYWORDS ,
420+ cat__doc__ },
421+ {"maps" , (PyCFunction )nis_maps ,
422+ METH_VARARGS | METH_KEYWORDS ,
423+ maps__doc__ },
424+ {"get_default_domain" , (PyCFunction )nis_get_default_domain ,
425+ METH_NOARGS ,
426+ get_default_domain__doc__ },
427+ {NULL , NULL } /* Sentinel */
375428};
376429
430+ PyDoc_STRVAR (nis__doc__ ,
431+ "This module contains functions for accessing NIS maps.\n" );
432+
377433void
378434initnis (void )
379435{
380436 PyObject * m , * d ;
381- m = Py_InitModule ("nis" , nis_methods );
437+ m = Py_InitModule3 ("nis" , nis_methods , nis__doc__ );
382438 if (m == NULL )
383439 return ;
384440 d = PyModule_GetDict (m );
0 commit comments