summaryrefslogtreecommitdiffstats
path: root/source/python/py_conv.c
diff options
context:
space:
mode:
authorTim Potter <tpot@samba.org>2002-05-20 08:04:02 +0000
committerTim Potter <tpot@samba.org>2002-05-20 08:04:02 +0000
commit96ccb2beb1d45f8122ff03fc2f7727bf065adbf6 (patch)
tree1bf7c1b83cd1eb9e9a453a596237680e48442192 /source/python/py_conv.c
parent0caf7610dcf698d2c649e42f0630de4337cfcea2 (diff)
downloadsamba-96ccb2beb1d45f8122ff03fc2f7727bf065adbf6.tar.gz
samba-96ccb2beb1d45f8122ff03fc2f7727bf065adbf6.tar.xz
samba-96ccb2beb1d45f8122ff03fc2f7727bf065adbf6.zip
When converting from a dictionary to a Samba structure, check for any
additional keys that may have been added and return False if so.
Diffstat (limited to 'source/python/py_conv.c')
-rw-r--r--source/python/py_conv.c32
1 files changed, 30 insertions, 2 deletions
diff --git a/source/python/py_conv.c b/source/python/py_conv.c
index c6f39515af1..9093b54b00f 100644
--- a/source/python/py_conv.c
+++ b/source/python/py_conv.c
@@ -80,15 +80,19 @@ PyObject *from_struct(void *s, struct pyconv *conv)
BOOL to_struct(void *s, PyObject *dict, struct pyconv *conv)
{
+ PyObject *visited, *key, *value;
+ BOOL result = False;
int i;
+ visited = PyDict_New();
+
for (i = 0; conv[i].name; i++) {
PyObject *obj;
obj = PyDict_GetItemString(dict, conv[i].name);
if (!obj)
- return False;
+ goto done;
switch (conv[i].type) {
case PY_UNISTR: {
@@ -125,7 +129,31 @@ BOOL to_struct(void *s, PyObject *dict, struct pyconv *conv)
default:
break;
}
+
+ /* Mark as visited */
+
+ PyDict_SetItemString(visited, conv[i].name,
+ PyInt_FromLong(1));
}
- return True;
+ /* Iterate over each item in the input dictionary and see if it was
+ visited. If it wasn't then the user has added some extra crap
+ to the dictionary. */
+
+ i = 0;
+
+ while (PyDict_Next(dict, &i, &key, &value)) {
+ if (!PyDict_GetItem(visited, key))
+ goto done;
+ }
+
+ result = True;
+
+done:
+ /* We must decrement the reference count here or the visited
+ dictionary will not be freed. */
+
+ Py_DECREF(visited);
+
+ return result;
}