The branch, master has been updated
       via  0db0e93 s3-passdb pdb_samba4 handles PDB_PWHISTORY already
       via  2ecb500 s3_upgrade: Set the administrator password on upgrade
       via  22cce00 s3-passdb: Fix the get/set routines for pw_history for samu
       via  149845f s3_upgrade: Do not add administrator and root accounts from 
s3 to s4
       via  0ffb4e6 python-samba3: Secrets file loaded from private dir, not 
lib dir
       via  dadaca0 s3-passdb: Display username when reporting error on 
add_sam_account.
       via  876f9cc s3-passdb: Use pdb_get_nt_passwd() to get nt passwd.
       via  2a3f5c0 s3upgrade: Add idmap migration, users/groups import
       via  dfa1c75 provision: Add idmap database handle to the result of 
provision
       via  57b9f1b samba3-python: Add methods to get any entry (user/group) 
and its sid from idmap
       via  c71e781 py_security: Fix comparison between two dom_sid objects
       via  0fef5a3 s3-passdb: Fix call for search_aliases(). It returns bool 
and not NTSTATUS.
       via  1c1f4e2 s3-passdb: Return list of sids from python wrapper 
enum_group_members
       via  590ed81 s3-passdb: Make arguments for python wrapper 
enum_group_mapping() optional
       via  f4c7a44 s3-passdb: Added python wrapper for passdb methods
       via  5b44491 s3-passdb: Python wrapper for passdb
       via  4201d6f s3-passdb: Replace SMB_MALLOC_ARRAY()/SAFE_FREE() with 
talloc equivalents.
      from  a6d06c0 Fix bug #8370 - vfs_chown_fsp broken -- returns in the 
wrong directory

http://gitweb.samba.org/?p=samba.git;a=shortlog;h=master


- Log -----------------------------------------------------------------
commit 0db0e93517f77f73b5c332afb7edf256af33b740
Author: Andrew Bartlett <[email protected]>
Date:   Mon Aug 15 18:07:09 2011 +1000

    s3-passdb pdb_samba4 handles PDB_PWHISTORY already
    
    Signed-off-by: Andrew Bartlett <[email protected]>
    
    Autobuild-User: Andrew Bartlett <[email protected]>
    Autobuild-Date: Fri Aug 19 10:40:16 CEST 2011 on sn-devel-104

commit 2ecb5003eba410d1287c81d9392aa39322b7d215
Author: Amitay Isaacs <[email protected]>
Date:   Fri Aug 19 15:53:28 2011 +1000

    s3_upgrade: Set the administrator password on upgrade
    
    In the upgrade process, set the administrator password from the
    existing root or administrator account.
    
    Pair-Programmed-With: Andrew Bartlett <[email protected]>
    Signed-off-by: Andrew Bartlett <[email protected]>

commit 22cce0015146c24692209dd9cc5ad0d2dc0f8ce3
Author: Amitay Isaacs <[email protected]>
Date:   Fri Aug 19 15:50:49 2011 +1000

    s3-passdb: Fix the get/set routines for pw_history for samu
    
    Return pw_history with current string length (which is a multiple
    of PW_HISTORY_ENTRY_LEN) and same thing for setting the pw_history.
    
    Pair-Programmed-With: Andrew Bartlett <[email protected]>
    Signed-off-by: Andrew Bartlett <[email protected]>

commit 149845fb18e016f8e8e8a415f936b62278b83fc0
Author: Amitay Isaacs <[email protected]>
Date:   Fri Aug 19 12:33:15 2011 +1000

    s3_upgrade: Do not add administrator and root accounts from s3 to s4
    
    Need to copy the password from s3 for administrator/root to s4.
    
    Pair-Programmed-With: Andrew Bartlett <[email protected]>
    Signed-off-by: Andrew Bartlett <[email protected]>

commit 0ffb4e6f6f1db61bf4f2ec73c1cad5e102787f67
Author: Amitay Isaacs <[email protected]>
Date:   Fri Aug 19 12:30:19 2011 +1000

    python-samba3: Secrets file loaded from private dir, not lib dir
    
    Signed-off-by: Andrew Bartlett <[email protected]>

commit dadaca01d2c4ac272b3f684eaee85cf5800f5f69
Author: Amitay Isaacs <[email protected]>
Date:   Fri Aug 19 12:27:42 2011 +1000

    s3-passdb: Display username when reporting error on add_sam_account.
    
    Signed-off-by: Andrew Bartlett <[email protected]>

commit 876f9cc29009b73ac7645a03d271b9e72b1a6ea2
Author: Amitay Isaacs <[email protected]>
Date:   Fri Aug 19 12:26:53 2011 +1000

    s3-passdb: Use pdb_get_nt_passwd() to get nt passwd.
    
    Pair-Programmed-With: Andrew Bartlett <[email protected]>
    Signed-off-by: Andrew Bartlett <[email protected]>

commit 2a3f5c04bdfac49d509fe5761cf7371965d21089
Author: Amitay Isaacs <[email protected]>
Date:   Thu Aug 18 15:21:32 2011 +1000

    s3upgrade: Add idmap migration, users/groups import
    
    Added users/groups import from s3 using python wrapper for passdb.
    Fix idmap entries for users/groups when migrating from s3 idmap.
    
    Pair-Programmed-With: Andrew Bartlett <[email protected]>
    Signed-off-by: Andrew Bartlett <[email protected]>

commit dfa1c751c68596f858b0e3094c26b7acdec1aa2c
Author: Amitay Isaacs <[email protected]>
Date:   Thu Aug 18 15:17:40 2011 +1000

    provision: Add idmap database handle to the result of provision
    
    It is required in s3_upgrade script to migrate idmap database from s3 to s4.
    
    Pair-Programmed-With: Andrew Bartlett <[email protected]>
    Signed-off-by: Andrew Bartlett <[email protected]>

commit 57b9f1b5025f2b521e6d8bcb25762b223b83ace4
Author: Amitay Isaacs <[email protected]>
Date:   Thu Aug 18 15:15:20 2011 +1000

    samba3-python: Add methods to get any entry (user/group) and its sid from 
idmap
    
    This is required in upgrade_s3 script to migrate idmap database from s3 to 
s4
    
    Pair-Programmed-With: Andrew Bartlett <[email protected]>
    Signed-off-by: Andrew Bartlett <[email protected]>

commit c71e781e7d66022cd6181e910f5fb8b7d750cbc1
Author: Amitay Isaacs <[email protected]>
Date:   Thu Aug 18 15:11:20 2011 +1000

    py_security: Fix comparison between two dom_sid objects
    
    dom_sid_compare() function can return values other than -1, 0, 1.
    Python requires compare function to return value from [-1, 0, 1].
    
    Pair-Programmed-With: Andrew Bartlett <[email protected]>
    Signed-off-by: Andrew Bartlett <[email protected]>

commit 0fef5a3a268219adea8f9a4614abe1f90f1d845e
Author: Amitay Isaacs <[email protected]>
Date:   Thu Aug 18 15:08:22 2011 +1000

    s3-passdb: Fix call for search_aliases(). It returns bool and not NTSTATUS.
    
    Signed-off-by: Andrew Bartlett <[email protected]>

commit 1c1f4e27a89946f4fd551358bc25fe04ad621ea4
Author: Amitay Isaacs <[email protected]>
Date:   Thu Aug 18 15:07:06 2011 +1000

    s3-passdb: Return list of sids from python wrapper enum_group_members
    
    Instead of returning rids as the C api does, return sids, so it is
    similar to enum_aliasmem and can be used easily in s3_upgrade.
    
    Pair-Programmed-With: Andrew Bartlett <[email protected]>
    Signed-off-by: Andrew Bartlett <[email protected]>

commit 590ed81c4868c030ee84870fd8cdaca4fad20520
Author: Amitay Isaacs <[email protected]>
Date:   Thu Aug 18 15:05:18 2011 +1000

    s3-passdb: Make arguments for python wrapper enum_group_mapping() optional
    
    Set the defaults, if no arguments are provided.
    
    Pair-Programmed-With: Andrew Bartlett <[email protected]>
    Signed-off-by: Andrew Bartlett <[email protected]>

commit f4c7a448d4b6d875281c3c4db61e9e5aabb91173
Author: Amitay Isaacs <[email protected]>
Date:   Thu Aug 18 15:02:22 2011 +1000

    s3-passdb: Added python wrapper for passdb methods
    
    Added following methods
     - uid_to_sid, gid_to_sid, sid_to_id, new_rid
     - get_trusteddom_pw, set_trusteddom_pw, del_trusteddom_pw, enum_trusteddoms
     - get_trusted_domain, get_trusted_domain_by_sid, set_trusted_domain,
       del_trusted_domain, enum_trusted_domains
     - get_secret, set_secret, delete_secret
    
    Updated documentation for all methods
    
    Signed-off-by: Andrew Bartlett <[email protected]>

commit 5b444916bfb2266182d62500d679d2ec08a7c53b
Author: Amitay Isaacs <[email protected]>
Date:   Mon Aug 15 17:21:38 2011 +1000

    s3-passdb: Python wrapper for passdb
    
    - Added Groupmap python wrapper
    - Added passdb methods
    
       getgrsid, getgrgid, getgrnam
       create_dom_group, delete_dom_group
       add_group_mapping_entry, update_group_mapping_entry, 
delete_group_mapping_entry
       enum_group_mapping, enum_group_members
       add_groupmem, del_groupmem
       create_alias, delete_alias
       get_aliasinfo, set_aliasinfo
       add_aliasmem, del_aliasmem, enum_aliasmem
       get_account_policy, set_account_policy
       search_groups, search_aliases
    
    Pair-Programmed-With: Andrew Bartlett <[email protected]>
    Signed-off-by: Andrew Bartlett <[email protected]>

commit 4201d6fd68b382208395b806b77b70e5e1be8d4a
Author: Amitay Isaacs <[email protected]>
Date:   Mon Aug 15 17:12:46 2011 +1000

    s3-passdb: Replace SMB_MALLOC_ARRAY()/SAFE_FREE() with talloc equivalents.
    
    Pair-Programmed-With: Andrew Bartlett <[email protected]>
    Signed-off-by: Andrew Bartlett <[email protected]>

-----------------------------------------------------------------------

Summary of changes:
 source3/passdb/account_pol.c                       |   13 +-
 source3/passdb/pdb_samba4.c                        |    3 +-
 source3/passdb/proto.h                             |    2 +-
 source3/passdb/py_passdb.c                         | 2116 +++++++++++++++++++-
 source3/utils/net_sam.c                            |   13 +-
 source3/utils/pdbedit.c                            |    4 +-
 source4/librpc/ndr/py_security.c                   |   10 +-
 .../scripting/python/samba/provision/__init__.py   |    2 +
 source4/scripting/python/samba/samba3/__init__.py  |   22 +-
 source4/scripting/python/samba/upgrade.py          |  257 ++-
 10 files changed, 2369 insertions(+), 73 deletions(-)


Changeset truncated at 500 lines:

diff --git a/source3/passdb/account_pol.c b/source3/passdb/account_pol.c
index 3556869..a491c27 100644
--- a/source3/passdb/account_pol.c
+++ b/source3/passdb/account_pol.c
@@ -89,22 +89,21 @@ static const struct ap_table account_policy_names[] = {
        {0, NULL, 0, "", NULL}
 };
 
-void account_policy_names_list(const char ***names, int *num_names)
+void account_policy_names_list(TALLOC_CTX *mem_ctx, const char ***names, int 
*num_names)
 {
        const char **nl;
-       int i, count;
+       int i, count = ARRAY_SIZE(account_policy_names);
 
-       for (count=0; account_policy_names[count].string; count++) {
-       }
-       nl = SMB_MALLOC_ARRAY(const char *, count);
+       nl = talloc_array(mem_ctx, const char *, count);
        if (!nl) {
                *num_names = 0;
                return;
        }
-       for (i=0; account_policy_names[i].string; i++) {
+       for (i=0; i<count; i++) {
                nl[i] = account_policy_names[i].string;
        }
-       *num_names = count;
+       /* Do not return the last null entry */
+       *num_names = count-1;
        *names = nl;
        return;
 }
diff --git a/source3/passdb/pdb_samba4.c b/source3/passdb/pdb_samba4.c
index ae38133..a45c687 100644
--- a/source3/passdb/pdb_samba4.c
+++ b/source3/passdb/pdb_samba4.c
@@ -383,7 +383,7 @@ static int pdb_samba4_replace_by_sam(struct 
pdb_samba4_state *state,
                }
                if (need_update(sam, PDB_NTPASSWD)) {
                        struct ldb_val val;
-                       val.data = pdb_get_lanman_passwd(sam);
+                       val.data = pdb_get_nt_passwd(sam);
                        if (!val.data) {
                                samdb_msg_add_delete(state->ldb, msg, msg,
                                                     "unicodePwd");
@@ -565,7 +565,6 @@ static int pdb_samba4_replace_by_sam(struct 
pdb_samba4_state *state,
        PDB_BAD_PASSWORD_COUNT,
        PDB_LOGON_COUNT,
        PDB_UNKNOWN6,
-       PDB_PWHISTORY,
        PDB_BACKEND_PRIVATE_DATA,
 
  */
diff --git a/source3/passdb/proto.h b/source3/passdb/proto.h
index 24a7cba..63208ea 100644
--- a/source3/passdb/proto.h
+++ b/source3/passdb/proto.h
@@ -39,7 +39,7 @@
 
 /* The following definitions come from passdb/account_pol.c  */
 
-void account_policy_names_list(const char ***names, int *num_names);
+void account_policy_names_list(TALLOC_CTX *mem_ctx, const char ***names, int 
*num_names);
 const char *decode_account_policy_name(enum pdb_policy_type type);
 const char *get_account_policy_attr(enum pdb_policy_type type);
 const char *account_policy_get_desc(enum pdb_policy_type type);
diff --git a/source3/passdb/py_passdb.c b/source3/passdb/py_passdb.c
index 30c3f8c..9192ab3 100644
--- a/source3/passdb/py_passdb.c
+++ b/source3/passdb/py_passdb.c
@@ -43,9 +43,11 @@
 
 
 static PyTypeObject *dom_sid_Type = NULL;
+static PyTypeObject *security_Type = NULL;
 static PyTypeObject *guid_Type = NULL;
 
 staticforward PyTypeObject PySamu;
+staticforward PyTypeObject PyGroupmap;
 staticforward PyTypeObject PyPDB;
 
 static PyObject *py_pdb_error;
@@ -656,7 +658,7 @@ static PyObject *py_samu_get_pw_history(PyObject *obj, void 
*closure)
                Py_RETURN_NONE;
        }
 
-       py_nt_pw_his = PyString_FromStringAndSize(nt_pw_his, hist_len);
+       py_nt_pw_his = PyString_FromStringAndSize(nt_pw_his, 
hist_len*PW_HISTORY_ENTRY_LEN);
        return py_nt_pw_his;
 }
 
@@ -668,7 +670,7 @@ static int py_samu_set_pw_history(PyObject *obj, PyObject 
*value, void *closure)
        uint32_t hist_len;
 
        PyString_AsStringAndSize(value, &nt_pw_his, &len);
-       hist_len = len;
+       hist_len = len / PW_HISTORY_ENTRY_LEN;
        if (!pdb_set_pw_history(sam_acct, (uint8_t *)nt_pw_his, hist_len, 
PDB_CHANGED)) {
                return -1;
        }
@@ -949,13 +951,189 @@ static PyObject *py_samu_new(PyTypeObject *type, 
PyObject *args, PyObject *kwarg
 }
 
 static PyTypeObject PySamu = {
-       .tp_name = "passdb.samu",
+       .tp_name = "passdb.Samu",
        .tp_basicsize = sizeof(pytalloc_Object),
        .tp_getset = py_samu_getsetters,
        .tp_methods = NULL,
        .tp_new = py_samu_new,
        .tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE,
-       .tp_doc = "samu() -> samu object\n",
+       .tp_doc = "Samu() -> samu object\n",
+};
+
+
+static PyObject *py_groupmap_get_gid(PyObject *obj, void *closure)
+{
+       GROUP_MAP *group_map = (GROUP_MAP *)pytalloc_get_ptr(obj);
+       PyObject *py_gid;
+
+       py_gid = PyInt_FromLong(group_map->gid);
+       return py_gid;
+}
+
+static int py_groupmap_set_gid(PyObject *obj, PyObject *value, void *closure)
+{
+       GROUP_MAP *group_map = (GROUP_MAP *)pytalloc_get_ptr(obj);
+
+       PY_CHECK_TYPE(&PyInt_Type, value, return -1;);
+       group_map->gid = PyInt_AsLong(value);
+       return 0;
+}
+
+static PyObject *py_groupmap_get_sid(PyObject *obj, void *closure)
+{
+       GROUP_MAP *group_map = (GROUP_MAP *)pytalloc_get_ptr(obj);
+       PyObject *py_sid;
+       struct dom_sid *group_sid;
+       TALLOC_CTX *mem_ctx;
+
+       mem_ctx = talloc_new(NULL);
+       if (mem_ctx == NULL) {
+               PyErr_NoMemory();
+               return NULL;
+       }
+
+       group_sid = dom_sid_dup(mem_ctx, &group_map->sid);
+       if (group_sid == NULL) {
+               PyErr_NoMemory();
+               talloc_free(mem_ctx);
+               return NULL;
+       }
+
+       py_sid = pytalloc_steal(dom_sid_Type, group_sid);
+
+       talloc_free(mem_ctx);
+
+       return py_sid;
+}
+
+static int py_groupmap_set_sid(PyObject *obj, PyObject *value, void *closure)
+{
+       GROUP_MAP *group_map = (GROUP_MAP *)pytalloc_get_ptr(obj);
+
+       PY_CHECK_TYPE(dom_sid_Type, value, return -1;);
+       group_map->sid = *pytalloc_get_type(value, struct dom_sid);
+       return 0;
+}
+
+static PyObject *py_groupmap_get_sid_name_use(PyObject *obj, void *closure)
+{
+       GROUP_MAP *group_map = (GROUP_MAP *)pytalloc_get_ptr(obj);
+       PyObject *py_sid_name_use;
+
+       py_sid_name_use = PyInt_FromLong(group_map->sid_name_use);
+       return py_sid_name_use;
+}
+
+static int py_groupmap_set_sid_name_use(PyObject *obj, PyObject *value, void 
*closure)
+{
+       GROUP_MAP *group_map = (GROUP_MAP *)pytalloc_get_ptr(obj);
+
+       PY_CHECK_TYPE(&PyInt_Type, value, return -1;);
+       group_map->sid_name_use = PyInt_AsLong(value);
+       return 0;
+}
+
+static PyObject *py_groupmap_get_nt_name(PyObject *obj, void *closure)
+{
+       GROUP_MAP *group_map = (GROUP_MAP *)pytalloc_get_ptr(obj);
+       PyObject *py_nt_name;
+       if (group_map->nt_name == NULL) {
+               py_nt_name = Py_None;
+               Py_INCREF(py_nt_name);
+       } else {
+               py_nt_name = PyString_FromString(group_map->nt_name);
+       }
+       return py_nt_name;
+}
+
+static int py_groupmap_set_nt_name(PyObject *obj, PyObject *value, void 
*closure)
+{
+       GROUP_MAP *group_map = (GROUP_MAP *)pytalloc_get_ptr(obj);
+
+       PY_CHECK_TYPE(&PyString_Type, value, return -1;);
+       if (value == Py_None) {
+               fstrcpy(group_map->nt_name, NULL);
+       } else {
+               fstrcpy(group_map->nt_name, PyString_AsString(value));
+       }
+       return 0;
+}
+
+static PyObject *py_groupmap_get_comment(PyObject *obj, void *closure)
+{
+       GROUP_MAP *group_map = (GROUP_MAP *)pytalloc_get_ptr(obj);
+       PyObject *py_comment;
+       if (group_map->comment == NULL) {
+               py_comment = Py_None;
+               Py_INCREF(py_comment);
+       } else {
+               py_comment = PyString_FromString(group_map->comment);
+       }
+       return py_comment;
+}
+
+static int py_groupmap_set_comment(PyObject *obj, PyObject *value, void 
*closure)
+{
+       GROUP_MAP *group_map = (GROUP_MAP *)pytalloc_get_ptr(obj);
+
+       PY_CHECK_TYPE(&PyString_Type, value, return -1;);
+       if (value == Py_None) {
+               fstrcpy(group_map->comment, NULL);
+       } else {
+               fstrcpy(group_map->comment, PyString_AsString(value));
+       }
+       return 0;
+}
+
+static PyGetSetDef py_groupmap_getsetters[] = {
+       { discard_const_p(char, "gid"), py_groupmap_get_gid, 
py_groupmap_set_gid },
+       { discard_const_p(char, "sid"), py_groupmap_get_sid, 
py_groupmap_set_sid },
+       { discard_const_p(char, "sid_name_use"), py_groupmap_get_sid_name_use, 
py_groupmap_set_sid_name_use },
+       { discard_const_p(char, "nt_name"), py_groupmap_get_nt_name, 
py_groupmap_set_nt_name },
+       { discard_const_p(char, "comment"), py_groupmap_get_comment, 
py_groupmap_set_comment },
+       { NULL }
+};
+
+static PyObject *py_groupmap_new(PyTypeObject *type, PyObject *args, PyObject 
*kwargs)
+{
+       GROUP_MAP *group_map;
+       TALLOC_CTX *mem_ctx;
+       PyObject *py_group_map;
+
+       mem_ctx = talloc_new(NULL);
+       if (mem_ctx == NULL) {
+               PyErr_NoMemory();
+               return NULL;
+       }
+
+       group_map = talloc_zero(mem_ctx, GROUP_MAP);
+       if (group_map == NULL) {
+               PyErr_NoMemory();
+               talloc_free(mem_ctx);
+               return NULL;
+       }
+
+       py_group_map = pytalloc_steal(type, group_map);
+       if (py_group_map == NULL) {
+               PyErr_NoMemory();
+               talloc_free(mem_ctx);
+               return NULL;
+       }
+
+       talloc_free(mem_ctx);
+
+       return py_group_map;
+}
+
+
+static PyTypeObject PyGroupmap = {
+       .tp_name = "passdb.Groupmap",
+       .tp_basicsize = sizeof(pytalloc_Object),
+       .tp_getset = py_groupmap_getsetters,
+       .tp_methods = NULL,
+       .tp_new = py_groupmap_new,
+       .tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE,
+       .tp_doc = "Groupmap() -> group map object\n",
 };
 
 
@@ -1188,7 +1366,8 @@ static PyObject *py_pdb_add_sam_account(pytalloc_Object 
*self, PyObject *args)
 
        status = methods->add_sam_account(methods, sam_acct);
        if (!NT_STATUS_IS_OK(status)) {
-               PyErr_Format(py_pdb_error, "Unable to add sam account, (%d,%s)",
+               PyErr_Format(py_pdb_error, "Unable to add sam account '%s', 
(%d,%s)",
+                               sam_acct->username,
                                NT_STATUS_V(status),
                                get_friendly_nt_error_msg(status));
                talloc_free(tframe);
@@ -1303,6 +1482,866 @@ static PyObject 
*py_pdb_rename_sam_account(pytalloc_Object *self, PyObject *args
        Py_RETURN_NONE;
 }
 
+
+static PyObject *py_pdb_getgrsid(pytalloc_Object *self, PyObject *args)
+{
+       NTSTATUS status;
+       struct pdb_methods *methods;
+       TALLOC_CTX *tframe;
+       GROUP_MAP *group_map;
+       struct dom_sid *domain_sid;
+       PyObject *py_domain_sid, *py_group_map;
+
+       if (!PyArg_ParseTuple(args, "O!:getgrsid", dom_sid_Type, 
&py_domain_sid)) {
+               return NULL;
+       }
+
+       methods = pytalloc_get_ptr(self);
+
+       if ((tframe = talloc_stackframe()) == NULL) {
+               PyErr_NoMemory();
+               return NULL;
+       }
+
+       domain_sid = pytalloc_get_ptr(py_domain_sid);
+
+       py_group_map = py_groupmap_new(&PyGroupmap, NULL, NULL);
+       if (py_group_map == NULL) {
+               PyErr_NoMemory();
+               talloc_free(tframe);
+               return NULL;
+       }
+
+       group_map = pytalloc_get_ptr(py_group_map);
+
+       status = methods->getgrsid(methods, group_map, *domain_sid);
+       if (!NT_STATUS_IS_OK(status)) {
+               PyErr_Format(py_pdb_error, "Unable to get group information by 
sid, (%d,%s)",
+                               NT_STATUS_V(status),
+                               get_friendly_nt_error_msg(status));
+               talloc_free(tframe);
+               return NULL;
+       }
+
+       talloc_free(tframe);
+       return py_group_map;
+}
+
+
+static PyObject *py_pdb_getgrgid(pytalloc_Object *self, PyObject *args)
+{
+       NTSTATUS status;
+       struct pdb_methods *methods;
+       TALLOC_CTX *tframe;
+       GROUP_MAP *group_map;
+       PyObject *py_group_map;
+       unsigned int gid_value;
+
+       if (!PyArg_ParseTuple(args, "I:getgrgid", &gid_value)) {
+               return NULL;
+       }
+
+       methods = pytalloc_get_ptr(self);
+
+       if ((tframe = talloc_stackframe()) == NULL) {
+               PyErr_NoMemory();
+               return NULL;
+       }
+
+       py_group_map = py_groupmap_new(&PyGroupmap, NULL, NULL);
+       if (py_group_map == NULL) {
+               PyErr_NoMemory();
+               talloc_free(tframe);
+               return NULL;
+       }
+
+       group_map = pytalloc_get_ptr(py_group_map);
+
+       status = methods->getgrgid(methods, group_map, gid_value);
+       if (!NT_STATUS_IS_OK(status)) {
+               PyErr_Format(py_pdb_error, "Unable to get group information by 
gid, (%d,%s)",
+                               NT_STATUS_V(status),
+                               get_friendly_nt_error_msg(status));
+               talloc_free(tframe);
+               return NULL;
+       }
+
+       talloc_free(tframe);
+       return py_group_map;
+}
+
+
+static PyObject *py_pdb_getgrnam(pytalloc_Object *self, PyObject *args)
+{
+       NTSTATUS status;
+       struct pdb_methods *methods;
+       TALLOC_CTX *tframe;
+       GROUP_MAP *group_map;
+       PyObject *py_group_map;
+       const char *groupname;
+
+       if (!PyArg_ParseTuple(args, "s:getgrnam", &groupname)) {
+               return NULL;
+       }
+
+       methods = pytalloc_get_ptr(self);
+
+       if ((tframe = talloc_stackframe()) == NULL) {
+               PyErr_NoMemory();
+               return NULL;
+       }
+
+       py_group_map = py_groupmap_new(&PyGroupmap, NULL, NULL);
+       if (py_group_map == NULL) {
+               PyErr_NoMemory();
+               talloc_free(tframe);
+               return NULL;
+       }
+
+       group_map = pytalloc_get_ptr(py_group_map);
+
+       status = methods->getgrnam(methods, group_map, groupname);
+       if (!NT_STATUS_IS_OK(status)) {
+               PyErr_Format(py_pdb_error, "Unable to get group information by 
name, (%d,%s)",
+                               NT_STATUS_V(status),
+                               get_friendly_nt_error_msg(status));
+               talloc_free(tframe);
+               return NULL;
+       }
+
+       talloc_free(tframe);
+       return py_group_map;
+}
+
+
+static PyObject *py_pdb_create_dom_group(pytalloc_Object *self, PyObject *args)
+{
+       NTSTATUS status;
+       struct pdb_methods *methods;
+       TALLOC_CTX *tframe;
+       const char *groupname;
+       uint32_t group_rid;
+
+       if (!PyArg_ParseTuple(args, "s:create_dom_group", &groupname)) {
+               return NULL;
+       }
+
+       methods = pytalloc_get_ptr(self);
+
+       if ((tframe = talloc_stackframe()) == NULL) {
+               PyErr_NoMemory();
+               return NULL;
+       }
+
+       status = methods->create_dom_group(methods, tframe, groupname, 
&group_rid);
+       if (!NT_STATUS_IS_OK(status)) {
+               PyErr_Format(py_pdb_error, "Unable to create domain group (%s), 
(%d,%s)",
+                               groupname,
+                               NT_STATUS_V(status),
+                               get_friendly_nt_error_msg(status));
+               talloc_free(tframe);
+               return NULL;
+       }
+
+       talloc_free(tframe);
+       return PyInt_FromLong(group_rid);
+}
+
+
+static PyObject *py_pdb_delete_dom_group(pytalloc_Object *self, PyObject *args)
+{
+       NTSTATUS status;
+       struct pdb_methods *methods;
+       TALLOC_CTX *tframe;
+       unsigned int group_rid;
+
+       if (!PyArg_ParseTuple(args, "I:delete_dom_group", &group_rid)) {
+               return NULL;
+       }
+
+       methods = pytalloc_get_ptr(self);
+
+       if ((tframe = talloc_stackframe()) == NULL) {
+               PyErr_NoMemory();
+               return NULL;
+       }
+
+       status = methods->delete_dom_group(methods, tframe, group_rid);
+       if (!NT_STATUS_IS_OK(status)) {
+               PyErr_Format(py_pdb_error, "Unable to delete domain group 
(rid=%d), (%d,%s)",
+                               group_rid,
+                               NT_STATUS_V(status),
+                               get_friendly_nt_error_msg(status));
+               talloc_free(tframe);
+               return NULL;
+       }


-- 
Samba Shared Repository

Reply via email to