r25598: Add missing become_root/unbecome_root around calls of add_aliases.
[samba.git] / source / python / py_conv.c
index 39b20ace8612a952cbb88b363b6dd20d98bd6b07..13d9ef9dc49f962c9b9429bbc1f9c5b80e702da2 100644 (file)
@@ -5,7 +5,7 @@
    
    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
-   the Free Software Foundation; either version 2 of the License, or
+   the Free Software Foundation; either version 3 of the License, or
    (at your option) any later version.
    
    This program is distributed in the hope that it will be useful,
    GNU General Public License for more details.
    
    You should have received a copy of the GNU General Public License
-   along with this program; if not, write to the Free Software
-   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+   along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
 
-#include "includes.h"
-#include "Python.h"
 #include "py_conv.h"
 
 /* Helper for rpcstr_pull() function */
@@ -29,6 +26,11 @@ static void fstr_pull(fstring str, UNISTR *uni)
        rpcstr_pull(str, uni->buffer, sizeof(fstring), -1, STR_TERMINATE);
 }
 
+static void fstr_pull2(fstring str, UNISTR2 *uni)
+{
+       rpcstr_pull(str, uni->buffer, sizeof(fstring), -1, STR_TERMINATE);
+}
+
 /* Convert a structure to a Python dict */
 
 PyObject *from_struct(void *s, struct pyconv *conv)
@@ -42,12 +44,24 @@ PyObject *from_struct(void *s, struct pyconv *conv)
                switch (conv[i].type) {
                case PY_UNISTR: {
                        UNISTR *u = (UNISTR *)((char *)s + conv[i].offset);
-                       fstring s = "";
+                       fstring str = "";
 
                        if (u->buffer)
-                               fstr_pull(s, u);
+                               fstr_pull(str, u);
 
-                       item = PyString_FromString(s);
+                       item = PyString_FromString(str);
+                       PyDict_SetItemString(obj, conv[i].name, item);
+
+                       break;
+               }
+               case PY_UNISTR2: {
+                       UNISTR2 *u = (UNISTR2 *)((char *)s + conv[i].offset);
+                       fstring str = "";
+
+                       if (u->buffer)
+                               fstr_pull2(str, u);
+
+                       item = PyString_FromString(str);
                        PyDict_SetItemString(obj, conv[i].name, item);
 
                        break;
@@ -68,7 +82,32 @@ PyObject *from_struct(void *s, struct pyconv *conv)
 
                        break;
                }
+               case PY_STRING: {
+                       char *str = (char *)s + conv[i].offset;
+
+                       item = PyString_FromString(str);
+                       PyDict_SetItemString(obj, conv[i].name, item);
+
+                       break;
+               }
+               case PY_UID: {
+                       uid_t *uid = (uid_t *)((char *)s + conv[i].offset);
+
+                       item = PyInt_FromLong(*uid);
+                       PyDict_SetItemString(obj, conv[i].name, item);
+
+                       break;
+               }
+               case PY_GID: {
+                       gid_t *gid = (gid_t *)((char *)s + conv[i].offset);
+
+                       item = PyInt_FromLong(*gid);
+                       PyDict_SetItemString(obj, conv[i].name, item);
+
+                       break;
+               }
                default:
+                       
                        break;
                }
        }
@@ -97,13 +136,13 @@ BOOL to_struct(void *s, PyObject *dict, struct pyconv *conv)
                switch (conv[i].type) {
                case PY_UNISTR: {
                        UNISTR *u = (UNISTR *)((char *)s + conv[i].offset);
-                       char *s = "";
+                       char *str = "";
 
                        if (!PyString_Check(obj))
                                goto done;
 
-                       s = PyString_AsString(obj);
-                       init_unistr(u, s);
+                       str = PyString_AsString(obj);
+                       init_unistr(u, str);
                        
                        break;
                }
@@ -157,3 +196,27 @@ done:
 
        return result;
 }
+
+/* Convert a NULL terminated list of NULL terminated unicode strings
+   to a list of (char *) strings */
+
+PyObject *from_unistr_list(uint16 *dependentfiles)
+{
+       PyObject *list;
+       int offset = 0;
+
+       list = PyList_New(0);
+
+       while (*(dependentfiles + offset) != 0) {
+               fstring name;
+               int len;
+
+               len = rpcstr_pull(name, dependentfiles + offset,
+                                 sizeof(fstring), -1, STR_TERMINATE);
+
+               offset += len / 2;
+               PyList_Append(list, PyString_FromString(name));
+       }
+
+       return list;
+}