blob: 0811430cf03fe605077eabfd95f8c0833728b791 [file] [log] [blame]
Guido van Rossum9de7a011992-08-12 14:57:12 +00001/***********************************************************
2 Written by:
3 Fred Gansevles <Fred.Gansevles@cs.utwente.nl>
Guido van Rossum61b705a2000-02-29 15:52:40 +00004 B&O group,
Guido van Rossum9de7a011992-08-12 14:57:12 +00005 Faculteit der Informatica,
6 Universiteit Twente,
7 Enschede,
8 the Netherlands.
9******************************************************************/
10
11/* NIS module implementation */
12
Barry Warsawadbf4e61996-12-11 00:15:58 +000013#include "Python.h"
Guido van Rossum9de7a011992-08-12 14:57:12 +000014
Guido van Rossum9de7a011992-08-12 14:57:12 +000015#include <sys/time.h>
16#include <sys/types.h>
17#include <rpc/rpc.h>
18#include <rpcsvc/yp_prot.h>
Guido van Rossum8a170cb1996-08-08 19:11:41 +000019#include <rpcsvc/ypclnt.h>
Guido van Rossum9de7a011992-08-12 14:57:12 +000020
Guido van Rossum259552d1996-12-09 18:46:28 +000021#ifdef __sgi
22/* This is missing from rpcsvc/ypclnt.h */
Thomas Woutersbd4bc4e2000-07-22 23:57:55 +000023extern int yp_get_default_domain(char **);
Guido van Rossum259552d1996-12-09 18:46:28 +000024#endif
25
Martin v. Löwis57a34e82006-02-04 19:12:37 +000026PyDoc_STRVAR(get_default_domain__doc__,
27"get_default_domain() -> str\n\
28Corresponds to the C library yp_get_default_domain() call, returning\n\
29the default NIS domain.\n");
30
31PyDoc_STRVAR(match__doc__,
32"match(key, map, domain = defaultdomain)\n\
33Corresponds to the C library yp_match() call, returning the value of\n\
34key in the given map. Optionally domain can be specified but it\n\
35defaults to the system default domain.\n");
36
37PyDoc_STRVAR(cat__doc__,
38"cat(map, domain = defaultdomain)\n\
39Returns the entire map as a dictionary. Optionally domain can be\n\
40specified but it defaults to the system default domain.\n");
41
42PyDoc_STRVAR(maps__doc__,
43"maps(domain = defaultdomain)\n\
44Returns an array of all available NIS maps within a domain. If domain\n\
45is not specified it defaults to the system default domain.\n");
46
Barry Warsawadbf4e61996-12-11 00:15:58 +000047static PyObject *NisError;
Guido van Rossum3562d521992-08-12 15:26:16 +000048
Barry Warsawadbf4e61996-12-11 00:15:58 +000049static PyObject *
Peter Schneider-Kamp39e0e5a2000-07-10 13:12:27 +000050nis_error (int err)
Guido van Rossum3562d521992-08-12 15:26:16 +000051{
Barry Warsawadbf4e61996-12-11 00:15:58 +000052 PyErr_SetString(NisError, yperr_string(err));
Guido van Rossum3562d521992-08-12 15:26:16 +000053 return NULL;
54}
55
Guido van Rossum9de7a011992-08-12 14:57:12 +000056static struct nis_map {
57 char *alias;
58 char *map;
Guido van Rossum61b705a2000-02-29 15:52:40 +000059 int fix;
Guido van Rossum9de7a011992-08-12 14:57:12 +000060} aliases [] = {
Guido van Rossum61b705a2000-02-29 15:52:40 +000061 {"passwd", "passwd.byname", 0},
62 {"group", "group.byname", 0},
63 {"networks", "networks.byaddr", 0},
64 {"hosts", "hosts.byname", 0},
65 {"protocols", "protocols.bynumber", 0},
66 {"services", "services.byname", 0},
67 {"aliases", "mail.aliases", 1}, /* created with 'makedbm -a' */
68 {"ethers", "ethers.byname", 0},
69 {0L, 0L, 0}
Guido van Rossum9de7a011992-08-12 14:57:12 +000070};
71
72static char *
Peter Schneider-Kamp39e0e5a2000-07-10 13:12:27 +000073nis_mapname (char *map, int *pfix)
Guido van Rossum9de7a011992-08-12 14:57:12 +000074{
Guido van Rossum3562d521992-08-12 15:26:16 +000075 int i;
Guido van Rossum9de7a011992-08-12 14:57:12 +000076
Guido van Rossum61b705a2000-02-29 15:52:40 +000077 *pfix = 0;
78 for (i=0; aliases[i].alias != 0L; i++) {
79 if (!strcmp (aliases[i].alias, map)) {
80 *pfix = aliases[i].fix;
81 return aliases[i].map;
82 }
83 if (!strcmp (aliases[i].map, map)) {
84 *pfix = aliases[i].fix;
85 return aliases[i].map;
86 }
87 }
88
Guido van Rossum9de7a011992-08-12 14:57:12 +000089 return map;
90}
91
Brett Cannonf6067ec2004-07-10 00:57:37 +000092#ifdef __APPLE__
93typedef int (*foreachfunc)(unsigned long, char *, int, char *, int, void *);
94#else
Tim Petersdbd9ba62000-07-09 03:09:57 +000095typedef int (*foreachfunc)(int, char *, int, char *, int, char *);
Brett Cannonf6067ec2004-07-10 00:57:37 +000096#endif
Guido van Rossumb6775db1994-08-01 11:34:53 +000097
Guido van Rossum61b705a2000-02-29 15:52:40 +000098struct ypcallback_data {
99 PyObject *dict;
100 int fix;
101};
102
Guido van Rossum9de7a011992-08-12 14:57:12 +0000103static int
Peter Schneider-Kamp39e0e5a2000-07-10 13:12:27 +0000104nis_foreach (int instatus, char *inkey, int inkeylen, char *inval,
105 int invallen, struct ypcallback_data *indata)
Guido van Rossum9de7a011992-08-12 14:57:12 +0000106{
107 if (instatus == YP_TRUE) {
Guido van Rossum61b705a2000-02-29 15:52:40 +0000108 PyObject *key;
109 PyObject *val;
Guido van Rossume77a7571993-11-03 15:01:26 +0000110 int err;
Guido van Rossum61b705a2000-02-29 15:52:40 +0000111
112 if (indata->fix) {
Neal Norwitz66239062002-11-04 23:21:09 +0000113 if (inkeylen > 0 && inkey[inkeylen-1] == '\0')
114 inkeylen--;
115 if (invallen > 0 && inval[invallen-1] == '\0')
116 invallen--;
Guido van Rossum61b705a2000-02-29 15:52:40 +0000117 }
118 key = PyString_FromStringAndSize(inkey, inkeylen);
119 val = PyString_FromStringAndSize(inval, invallen);
Guido van Rossume77a7571993-11-03 15:01:26 +0000120 if (key == NULL || val == NULL) {
121 /* XXX error -- don't know how to handle */
Barry Warsawadbf4e61996-12-11 00:15:58 +0000122 PyErr_Clear();
123 Py_XDECREF(key);
124 Py_XDECREF(val);
Guido van Rossume77a7571993-11-03 15:01:26 +0000125 return 1;
126 }
Guido van Rossum61b705a2000-02-29 15:52:40 +0000127 err = PyDict_SetItem(indata->dict, key, val);
Barry Warsawadbf4e61996-12-11 00:15:58 +0000128 Py_DECREF(key);
129 Py_DECREF(val);
Guido van Rossume77a7571993-11-03 15:01:26 +0000130 if (err != 0) {
Barry Warsawadbf4e61996-12-11 00:15:58 +0000131 PyErr_Clear();
Guido van Rossume77a7571993-11-03 15:01:26 +0000132 return 1;
133 }
Guido van Rossum9de7a011992-08-12 14:57:12 +0000134 return 0;
135 }
136 return 1;
137}
138
Barry Warsawadbf4e61996-12-11 00:15:58 +0000139static PyObject *
Martin v. Löwis57a34e82006-02-04 19:12:37 +0000140nis_get_default_domain (PyObject *self)
141{
142 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
153static PyObject *
154nis_match (PyObject *self, PyObject *args, PyObject *kwdict)
Guido van Rossum9de7a011992-08-12 14:57:12 +0000155{
Guido van Rossum3562d521992-08-12 15:26:16 +0000156 char *match;
Martin v. Löwis57a34e82006-02-04 19:12:37 +0000157 char *domain = NULL;
Guido van Rossume77a7571993-11-03 15:01:26 +0000158 int keylen, len;
Guido van Rossum3562d521992-08-12 15:26:16 +0000159 char *key, *map;
160 int err;
Barry Warsawadbf4e61996-12-11 00:15:58 +0000161 PyObject *res;
Guido van Rossum61b705a2000-02-29 15:52:40 +0000162 int fix;
Martin v. Löwis15e62742006-02-27 16:46:16 +0000163 static char *kwlist[] = {"key", "map", "domain", NULL};
Guido van Rossum9de7a011992-08-12 14:57:12 +0000164
Martin v. Löwis57a34e82006-02-04 19:12:37 +0000165 if (!PyArg_ParseTupleAndKeywords(args, kwdict,
166 "t#s|s:match", kwlist,
167 &key, &keylen, &map, &domain))
Guido van Rossum9de7a011992-08-12 14:57:12 +0000168 return NULL;
Martin v. Löwis57a34e82006-02-04 19:12:37 +0000169 if (!domain && ((err = yp_get_default_domain(&domain)) != 0))
Guido van Rossum3562d521992-08-12 15:26:16 +0000170 return nis_error(err);
Guido van Rossum61b705a2000-02-29 15:52:40 +0000171 map = nis_mapname (map, &fix);
172 if (fix)
173 keylen++;
Barry Warsawadbf4e61996-12-11 00:15:58 +0000174 Py_BEGIN_ALLOW_THREADS
Guido van Rossume77a7571993-11-03 15:01:26 +0000175 err = yp_match (domain, map, key, keylen, &match, &len);
Barry Warsawadbf4e61996-12-11 00:15:58 +0000176 Py_END_ALLOW_THREADS
Guido van Rossum61b705a2000-02-29 15:52:40 +0000177 if (fix)
178 len--;
Guido van Rossum3562d521992-08-12 15:26:16 +0000179 if (err != 0)
180 return nis_error(err);
Barry Warsawadbf4e61996-12-11 00:15:58 +0000181 res = PyString_FromStringAndSize (match, len);
Guido van Rossum3562d521992-08-12 15:26:16 +0000182 free (match);
183 return res;
Guido van Rossum9de7a011992-08-12 14:57:12 +0000184}
185
Barry Warsawadbf4e61996-12-11 00:15:58 +0000186static PyObject *
Martin v. Löwis57a34e82006-02-04 19:12:37 +0000187nis_cat (PyObject *self, PyObject *args, PyObject *kwdict)
Guido van Rossum9de7a011992-08-12 14:57:12 +0000188{
Martin v. Löwis57a34e82006-02-04 19:12:37 +0000189 char *domain = NULL;
Guido van Rossum3562d521992-08-12 15:26:16 +0000190 char *map;
191 struct ypall_callback cb;
Guido van Rossum61b705a2000-02-29 15:52:40 +0000192 struct ypcallback_data data;
193 PyObject *dict;
Guido van Rossum3562d521992-08-12 15:26:16 +0000194 int err;
Martin v. Löwis15e62742006-02-27 16:46:16 +0000195 static char *kwlist[] = {"map", "domain", NULL};
Guido van Rossum9de7a011992-08-12 14:57:12 +0000196
Martin v. Löwis57a34e82006-02-04 19:12:37 +0000197 if (!PyArg_ParseTupleAndKeywords(args, kwdict, "s|s:cat",
198 kwlist, &map, &domain))
Guido van Rossum9de7a011992-08-12 14:57:12 +0000199 return NULL;
Martin v. Löwis57a34e82006-02-04 19:12:37 +0000200 if (!domain && ((err = yp_get_default_domain(&domain)) != 0))
Guido van Rossum3562d521992-08-12 15:26:16 +0000201 return nis_error(err);
Guido van Rossum61b705a2000-02-29 15:52:40 +0000202 dict = PyDict_New ();
203 if (dict == NULL)
Guido van Rossum9de7a011992-08-12 14:57:12 +0000204 return NULL;
Guido van Rossumb6775db1994-08-01 11:34:53 +0000205 cb.foreach = (foreachfunc)nis_foreach;
Guido van Rossum61b705a2000-02-29 15:52:40 +0000206 data.dict = dict;
207 map = nis_mapname (map, &data.fix);
208 cb.data = (char *)&data;
Barry Warsawadbf4e61996-12-11 00:15:58 +0000209 Py_BEGIN_ALLOW_THREADS
Guido van Rossum3562d521992-08-12 15:26:16 +0000210 err = yp_all (domain, map, &cb);
Barry Warsawadbf4e61996-12-11 00:15:58 +0000211 Py_END_ALLOW_THREADS
Guido van Rossum3562d521992-08-12 15:26:16 +0000212 if (err != 0) {
Guido van Rossum61b705a2000-02-29 15:52:40 +0000213 Py_DECREF(dict);
Guido van Rossum3562d521992-08-12 15:26:16 +0000214 return nis_error(err);
215 }
Guido van Rossum61b705a2000-02-29 15:52:40 +0000216 return dict;
Guido van Rossum9de7a011992-08-12 14:57:12 +0000217}
218
Guido van Rossumb6775db1994-08-01 11:34:53 +0000219/* These should be u_long on Sun h/w but not on 64-bit h/w.
220 This is not portable to machines with 16-bit ints and no prototypes */
221#ifndef YPPROC_MAPLIST
222#define YPPROC_MAPLIST 11
223#endif
224#ifndef YPPROG
225#define YPPROG 100004
226#endif
227#ifndef YPVERS
228#define YPVERS 2
229#endif
Guido van Rossum9de7a011992-08-12 14:57:12 +0000230
231typedef char *domainname;
232typedef char *mapname;
233
234enum nisstat {
Barry Warsawadbf4e61996-12-11 00:15:58 +0000235 NIS_TRUE = 1,
236 NIS_NOMORE = 2,
237 NIS_FALSE = 0,
238 NIS_NOMAP = -1,
239 NIS_NODOM = -2,
240 NIS_NOKEY = -3,
241 NIS_BADOP = -4,
242 NIS_BADDB = -5,
243 NIS_YPERR = -6,
244 NIS_BADARGS = -7,
245 NIS_VERS = -8
Guido van Rossum9de7a011992-08-12 14:57:12 +0000246};
247typedef enum nisstat nisstat;
248
249struct nismaplist {
Barry Warsawadbf4e61996-12-11 00:15:58 +0000250 mapname map;
251 struct nismaplist *next;
Guido van Rossum9de7a011992-08-12 14:57:12 +0000252};
253typedef struct nismaplist nismaplist;
254
255struct nisresp_maplist {
256 nisstat stat;
257 nismaplist *maps;
258};
259typedef struct nisresp_maplist nisresp_maplist;
260
261static struct timeval TIMEOUT = { 25, 0 };
262
263static
264bool_t
Peter Schneider-Kamp39e0e5a2000-07-10 13:12:27 +0000265nis_xdr_domainname(XDR *xdrs, domainname *objp)
Guido van Rossum9de7a011992-08-12 14:57:12 +0000266{
Barry Warsawadbf4e61996-12-11 00:15:58 +0000267 if (!xdr_string(xdrs, objp, YPMAXDOMAIN)) {
268 return (FALSE);
269 }
270 return (TRUE);
Guido van Rossum9de7a011992-08-12 14:57:12 +0000271}
272
273static
274bool_t
Peter Schneider-Kamp39e0e5a2000-07-10 13:12:27 +0000275nis_xdr_mapname(XDR *xdrs, mapname *objp)
Guido van Rossum9de7a011992-08-12 14:57:12 +0000276{
Barry Warsawadbf4e61996-12-11 00:15:58 +0000277 if (!xdr_string(xdrs, objp, YPMAXMAP)) {
278 return (FALSE);
279 }
280 return (TRUE);
Guido van Rossum9de7a011992-08-12 14:57:12 +0000281}
282
283static
284bool_t
Peter Schneider-Kamp39e0e5a2000-07-10 13:12:27 +0000285nis_xdr_ypmaplist(XDR *xdrs, nismaplist *objp)
Guido van Rossum9de7a011992-08-12 14:57:12 +0000286{
Barry Warsawadbf4e61996-12-11 00:15:58 +0000287 if (!nis_xdr_mapname(xdrs, &objp->map)) {
288 return (FALSE);
289 }
290 if (!xdr_pointer(xdrs, (char **)&objp->next,
Guido van Rossumc5015831998-10-07 16:36:14 +0000291 sizeof(nismaplist), (xdrproc_t)nis_xdr_ypmaplist))
Barry Warsawadbf4e61996-12-11 00:15:58 +0000292 {
293 return (FALSE);
294 }
295 return (TRUE);
Guido van Rossum9de7a011992-08-12 14:57:12 +0000296}
297
298static
299bool_t
Peter Schneider-Kamp39e0e5a2000-07-10 13:12:27 +0000300nis_xdr_ypstat(XDR *xdrs, nisstat *objp)
Guido van Rossum9de7a011992-08-12 14:57:12 +0000301{
Barry Warsawadbf4e61996-12-11 00:15:58 +0000302 if (!xdr_enum(xdrs, (enum_t *)objp)) {
303 return (FALSE);
304 }
305 return (TRUE);
Guido van Rossum9de7a011992-08-12 14:57:12 +0000306}
307
308
309static
310bool_t
Peter Schneider-Kamp39e0e5a2000-07-10 13:12:27 +0000311nis_xdr_ypresp_maplist(XDR *xdrs, nisresp_maplist *objp)
Guido van Rossum9de7a011992-08-12 14:57:12 +0000312{
Barry Warsawadbf4e61996-12-11 00:15:58 +0000313 if (!nis_xdr_ypstat(xdrs, &objp->stat)) {
314 return (FALSE);
315 }
316 if (!xdr_pointer(xdrs, (char **)&objp->maps,
Guido van Rossumc5015831998-10-07 16:36:14 +0000317 sizeof(nismaplist), (xdrproc_t)nis_xdr_ypmaplist))
Barry Warsawadbf4e61996-12-11 00:15:58 +0000318 {
319 return (FALSE);
320 }
321 return (TRUE);
Guido van Rossum9de7a011992-08-12 14:57:12 +0000322}
323
324
325static
326nisresp_maplist *
Peter Schneider-Kamp39e0e5a2000-07-10 13:12:27 +0000327nisproc_maplist_2(domainname *argp, CLIENT *clnt)
Guido van Rossum9de7a011992-08-12 14:57:12 +0000328{
Barry Warsawadbf4e61996-12-11 00:15:58 +0000329 static nisresp_maplist res;
Guido van Rossum9de7a011992-08-12 14:57:12 +0000330
Barry Warsawadbf4e61996-12-11 00:15:58 +0000331 memset(&res, 0, sizeof(res));
Guido van Rossumc5015831998-10-07 16:36:14 +0000332 if (clnt_call(clnt, YPPROC_MAPLIST,
333 (xdrproc_t)nis_xdr_domainname, (caddr_t)argp,
334 (xdrproc_t)nis_xdr_ypresp_maplist, (caddr_t)&res,
335 TIMEOUT) != RPC_SUCCESS)
336 {
Barry Warsawadbf4e61996-12-11 00:15:58 +0000337 return (NULL);
338 }
339 return (&res);
Guido van Rossum9de7a011992-08-12 14:57:12 +0000340}
341
342static
343nismaplist *
Martin v. Löwis57a34e82006-02-04 19:12:37 +0000344nis_maplist (char *dom)
Guido van Rossum9de7a011992-08-12 14:57:12 +0000345{
Guido van Rossum3562d521992-08-12 15:26:16 +0000346 nisresp_maplist *list;
Thomas Wouterse75e6d02001-01-21 23:34:12 +0000347 CLIENT *cl;
Barry Warsaw4bc9d391997-01-09 22:22:05 +0000348 char *server = NULL;
Barry Warsawadbf4e61996-12-11 00:15:58 +0000349 int mapi = 0;
Barry Warsaw3696c521996-12-11 00:29:14 +0000350
Barry Warsaw4bc9d391997-01-09 22:22:05 +0000351 while (!server && aliases[mapi].map != 0L) {
Barry Warsawadbf4e61996-12-11 00:15:58 +0000352 yp_master (dom, aliases[mapi].map, &server);
353 mapi++;
354 }
Barry Warsaw4bc9d391997-01-09 22:22:05 +0000355 if (!server) {
Barry Warsawadbf4e61996-12-11 00:15:58 +0000356 PyErr_SetString(NisError, "No NIS master found for any map");
357 return NULL;
358 }
Guido van Rossum9de7a011992-08-12 14:57:12 +0000359 cl = clnt_create(server, YPPROG, YPVERS, "tcp");
360 if (cl == NULL) {
Barry Warsawadbf4e61996-12-11 00:15:58 +0000361 PyErr_SetString(NisError, clnt_spcreateerror(server));
Barry Warsaw4bc9d391997-01-09 22:22:05 +0000362 goto finally;
Guido van Rossum9de7a011992-08-12 14:57:12 +0000363 }
364 list = nisproc_maplist_2 (&dom, cl);
Barry Warsaw4bc9d391997-01-09 22:22:05 +0000365 clnt_destroy(cl);
Guido van Rossum9de7a011992-08-12 14:57:12 +0000366 if (list == NULL)
Barry Warsaw4bc9d391997-01-09 22:22:05 +0000367 goto finally;
Guido van Rossum9de7a011992-08-12 14:57:12 +0000368 if (list->stat != NIS_TRUE)
Barry Warsaw4bc9d391997-01-09 22:22:05 +0000369 goto finally;
370
Guido van Rossumb18618d2000-05-03 23:44:39 +0000371 free(server);
Guido van Rossum9de7a011992-08-12 14:57:12 +0000372 return list->maps;
Barry Warsaw4bc9d391997-01-09 22:22:05 +0000373
374 finally:
Guido van Rossumb18618d2000-05-03 23:44:39 +0000375 free(server);
Barry Warsaw4bc9d391997-01-09 22:22:05 +0000376 return NULL;
Guido van Rossum9de7a011992-08-12 14:57:12 +0000377}
378
Barry Warsawadbf4e61996-12-11 00:15:58 +0000379static PyObject *
Martin v. Löwis57a34e82006-02-04 19:12:37 +0000380nis_maps (PyObject *self, PyObject *args, PyObject *kwdict)
Guido van Rossum9de7a011992-08-12 14:57:12 +0000381{
Martin v. Löwis57a34e82006-02-04 19:12:37 +0000382 char *domain = NULL;
Guido van Rossum3562d521992-08-12 15:26:16 +0000383 nismaplist *maps;
Barry Warsawadbf4e61996-12-11 00:15:58 +0000384 PyObject *list;
Martin v. Löwis57a34e82006-02-04 19:12:37 +0000385 int err;
Martin v. Löwis15e62742006-02-27 16:46:16 +0000386 static char *kwlist[] = {"domain", NULL};
Guido van Rossum9de7a011992-08-12 14:57:12 +0000387
Martin v. Löwis57a34e82006-02-04 19:12:37 +0000388 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)
Guido van Rossum9de7a011992-08-12 14:57:12 +0000397 return NULL;
Barry Warsawadbf4e61996-12-11 00:15:58 +0000398 if ((list = PyList_New(0)) == NULL)
Guido van Rossum9de7a011992-08-12 14:57:12 +0000399 return NULL;
Guido van Rossum61b705a2000-02-29 15:52:40 +0000400 for (maps = maps; maps; maps = maps->next) {
Barry Warsaw4bc9d391997-01-09 22:22:05 +0000401 PyObject *str = PyString_FromString(maps->map);
402 if (!str || PyList_Append(list, str) < 0)
Barry Warsawadbf4e61996-12-11 00:15:58 +0000403 {
404 Py_DECREF(list);
Guido van Rossum3562d521992-08-12 15:26:16 +0000405 list = NULL;
406 break;
407 }
Barry Warsaw4bc9d391997-01-09 22:22:05 +0000408 Py_DECREF(str);
Guido van Rossum3562d521992-08-12 15:26:16 +0000409 }
410 /* XXX Shouldn't we free the list of maps now? */
Guido van Rossum9de7a011992-08-12 14:57:12 +0000411 return list;
412}
413
Barry Warsawadbf4e61996-12-11 00:15:58 +0000414static PyMethodDef nis_methods[] = {
Martin v. Löwis57a34e82006-02-04 19:12:37 +0000415 {"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 */
Guido van Rossum9de7a011992-08-12 14:57:12 +0000428};
429
Martin v. Löwis57a34e82006-02-04 19:12:37 +0000430PyDoc_STRVAR(nis__doc__,
431"This module contains functions for accessing NIS maps.\n");
432
Guido van Rossum9de7a011992-08-12 14:57:12 +0000433void
Thomas Woutersf3f33dc2000-07-21 06:00:07 +0000434initnis (void)
Guido van Rossum9de7a011992-08-12 14:57:12 +0000435{
Barry Warsawadbf4e61996-12-11 00:15:58 +0000436 PyObject *m, *d;
Martin v. Löwis57a34e82006-02-04 19:12:37 +0000437 m = Py_InitModule3("nis", nis_methods, nis__doc__);
Neal Norwitz1ac754f2006-01-19 06:09:39 +0000438 if (m == NULL)
439 return;
Barry Warsawadbf4e61996-12-11 00:15:58 +0000440 d = PyModule_GetDict(m);
Guido van Rossum0cb96de1997-10-01 04:29:29 +0000441 NisError = PyErr_NewException("nis.error", NULL, NULL);
442 if (NisError != NULL)
443 PyDict_SetItemString(d, "error", NisError);
Guido van Rossum9de7a011992-08-12 14:57:12 +0000444}