Lokasi ngalangkungan proxy:   [ UP ]  
[Ngawartoskeun bug]   [Panyetelan cookie]                
Skip to content

Commit 61b705a

Browse files
committed
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]
1 parent 43713e5 commit 61b705a

2 files changed

Lines changed: 58 additions & 28 deletions

File tree

Modules/Setup.in

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ socket socketmodule.c # socket(2); not on ancient System V
164164
# Some more UNIX dependent modules -- off by default, since these
165165
# are not supported by all UNIX systems:
166166

167-
#nis nismodule.c # Sun yellow pages -- not everywhere
167+
#nis nismodule.c -lnsl # Sun yellow pages -- not everywhere
168168
#termios termios.c # Steen Lumholt's termios module
169169
#resource resource.c # Jeremy Hylton's rlimit interface
170170

Modules/nismodule.c

Lines changed: 57 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/***********************************************************
22
Written by:
33
Fred Gansevles <Fred.Gansevles@cs.utwente.nl>
4-
Vakgroep Spa,
4+
B&O group,
55
Faculteit der Informatica,
66
Universiteit Twente,
77
Enschede,
@@ -36,53 +36,76 @@ nis_error (err)
3636
static struct nis_map {
3737
char *alias;
3838
char *map;
39+
int fix;
3940
} aliases [] = {
40-
{"passwd", "passwd.byname"},
41-
{"group", "group.byname"},
42-
{"networks", "networks.byaddr"},
43-
{"hosts", "hosts.byname"},
44-
{"protocols", "protocols.bynumber"},
45-
{"services", "services.byname"},
46-
{"aliases", "mail.aliases"},
47-
{"ethers", "ethers.byname"},
48-
{0L, 0L}
41+
{"passwd", "passwd.byname", 0},
42+
{"group", "group.byname", 0},
43+
{"networks", "networks.byaddr", 0},
44+
{"hosts", "hosts.byname", 0},
45+
{"protocols", "protocols.bynumber", 0},
46+
{"services", "services.byname", 0},
47+
{"aliases", "mail.aliases", 1}, /* created with 'makedbm -a' */
48+
{"ethers", "ethers.byname", 0},
49+
{0L, 0L, 0}
4950
};
5051

5152
static char *
52-
nis_mapname (map)
53+
nis_mapname (map, pfix)
5354
char *map;
55+
int *pfix;
5456
{
5557
int i;
5658

57-
for (i=0; aliases[i].alias != 0L; i++)
58-
if (!strcmp (aliases[i].alias, map))
59-
map = aliases[i].map;
59+
*pfix = 0;
60+
for (i=0; aliases[i].alias != 0L; i++) {
61+
if (!strcmp (aliases[i].alias, map)) {
62+
*pfix = aliases[i].fix;
63+
return aliases[i].map;
64+
}
65+
if (!strcmp (aliases[i].map, map)) {
66+
*pfix = aliases[i].fix;
67+
return aliases[i].map;
68+
}
69+
}
70+
6071
return map;
6172
}
6273

6374
typedef int (*foreachfunc) Py_PROTO((int, char *, int, char *, int, char *));
6475

76+
struct ypcallback_data {
77+
PyObject *dict;
78+
int fix;
79+
};
80+
6581
static int
6682
nis_foreach (instatus, inkey, inkeylen, inval, invallen, indata)
6783
int instatus;
6884
char *inkey;
6985
int inkeylen;
7086
char *inval;
7187
int invallen;
72-
PyObject *indata;
88+
struct ypcallback_data *indata;
7389
{
7490
if (instatus == YP_TRUE) {
75-
PyObject *key = PyString_FromStringAndSize(inkey, inkeylen);
76-
PyObject *val = PyString_FromStringAndSize(inval, invallen);
91+
PyObject *key;
92+
PyObject *val;
7793
int err;
94+
95+
if (indata->fix) {
96+
inkeylen--;
97+
invallen--;
98+
}
99+
key = PyString_FromStringAndSize(inkey, inkeylen);
100+
val = PyString_FromStringAndSize(inval, invallen);
78101
if (key == NULL || val == NULL) {
79102
/* XXX error -- don't know how to handle */
80103
PyErr_Clear();
81104
Py_XDECREF(key);
82105
Py_XDECREF(val);
83106
return 1;
84107
}
85-
err = PyDict_SetItem(indata, key, val);
108+
err = PyDict_SetItem(indata->dict, key, val);
86109
Py_DECREF(key);
87110
Py_DECREF(val);
88111
if (err != 0) {
@@ -105,15 +128,20 @@ nis_match (self, args)
105128
char *key, *map;
106129
int err;
107130
PyObject *res;
131+
int fix;
108132

109133
if (!PyArg_Parse(args, "(t#s)", &key, &keylen, &map))
110134
return NULL;
111135
if ((err = yp_get_default_domain(&domain)) != 0)
112136
return nis_error(err);
137+
map = nis_mapname (map, &fix);
138+
if (fix)
139+
keylen++;
113140
Py_BEGIN_ALLOW_THREADS
114-
map = nis_mapname (map);
115141
err = yp_match (domain, map, key, keylen, &match, &len);
116142
Py_END_ALLOW_THREADS
143+
if (fix)
144+
len--;
117145
if (err != 0)
118146
return nis_error(err);
119147
res = PyString_FromStringAndSize (match, len);
@@ -129,27 +157,29 @@ nis_cat (self, args)
129157
char *domain;
130158
char *map;
131159
struct ypall_callback cb;
132-
PyObject *cat;
160+
struct ypcallback_data data;
161+
PyObject *dict;
133162
int err;
134163

135164
if (!PyArg_Parse(args, "s", &map))
136165
return NULL;
137166
if ((err = yp_get_default_domain(&domain)) != 0)
138167
return nis_error(err);
139-
cat = PyDict_New ();
140-
if (cat == NULL)
168+
dict = PyDict_New ();
169+
if (dict == NULL)
141170
return NULL;
142171
cb.foreach = (foreachfunc)nis_foreach;
143-
cb.data = (char *)cat;
172+
data.dict = dict;
173+
map = nis_mapname (map, &data.fix);
174+
cb.data = (char *)&data;
144175
Py_BEGIN_ALLOW_THREADS
145-
map = nis_mapname (map);
146176
err = yp_all (domain, map, &cb);
147177
Py_END_ALLOW_THREADS
148178
if (err != 0) {
149-
Py_DECREF(cat);
179+
Py_DECREF(dict);
150180
return nis_error(err);
151181
}
152-
return cat;
182+
return dict;
153183
}
154184

155185
/* These should be u_long on Sun h/w but not on 64-bit h/w.
@@ -345,7 +375,7 @@ nis_maps (self, args)
345375
return NULL;
346376
if ((list = PyList_New(0)) == NULL)
347377
return NULL;
348-
for (maps = maps->next; maps; maps = maps->next) {
378+
for (maps = maps; maps; maps = maps->next) {
349379
PyObject *str = PyString_FromString(maps->map);
350380
if (!str || PyList_Append(list, str) < 0)
351381
{

0 commit comments

Comments
 (0)