git.samba.org
/
samba.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
s3-talloc Change TALLOC_ARRAY() to talloc_array()
[samba.git]
/
source3
/
groupdb
/
mapping_tdb.c
diff --git
a/source3/groupdb/mapping_tdb.c
b/source3/groupdb/mapping_tdb.c
index fa91fc2310eae937cfaa300b8e3d0daa11350d1e..cf8857cda541990cff878745933d5ea41b361999 100644
(file)
--- a/
source3/groupdb/mapping_tdb.c
+++ b/
source3/groupdb/mapping_tdb.c
@@
-21,16
+21,21
@@
*/
#include "includes.h"
*/
#include "includes.h"
+#include "system/filesys.h"
+#include "passdb.h"
#include "groupdb/mapping.h"
#include "groupdb/mapping.h"
+#include "dbwrap.h"
+#include "util_tdb.h"
+#include "../libcli/security/security.h"
static struct db_context *db; /* used for driver files */
static struct db_context *db; /* used for driver files */
-static bool enum_group_mapping(const
DOM_SID
*domsid,
+static bool enum_group_mapping(const
struct dom_sid
*domsid,
enum lsa_SidType sid_name_use,
GROUP_MAP **pp_rmap,
size_t *p_num_entries,
bool unix_only);
enum lsa_SidType sid_name_use,
GROUP_MAP **pp_rmap,
size_t *p_num_entries,
bool unix_only);
-static bool group_map_remove(const
DOM_SID
*sid);
+static bool group_map_remove(const
struct dom_sid
*sid);
static bool mapping_switch(const char *ldb_path);
static bool mapping_switch(const char *ldb_path);
@@
-109,7
+114,7
@@
static bool init_group_mapping(void)
return true;
}
return true;
}
-static char *group_mapping_key(TALLOC_CTX *mem_ctx, const
DOM_SID
*sid)
+static char *group_mapping_key(TALLOC_CTX *mem_ctx, const
struct dom_sid
*sid)
{
char *sidstr, *result;
{
char *sidstr, *result;
@@
-140,7
+145,7
@@
static bool add_mapping_entry(GROUP_MAP *map, int flag)
len = tdb_pack(NULL, 0, "ddff",
map->gid, map->sid_name_use, map->nt_name, map->comment);
len = tdb_pack(NULL, 0, "ddff",
map->gid, map->sid_name_use, map->nt_name, map->comment);
- buf =
TALLOC_ARRAY
(key, char, len);
+ buf =
talloc_array
(key, char, len);
if (!buf) {
TALLOC_FREE(key);
return false;
if (!buf) {
TALLOC_FREE(key);
return false;
@@
-162,7
+167,7
@@
static bool add_mapping_entry(GROUP_MAP *map, int flag)
Return the sid and the type of the unix group.
****************************************************************************/
Return the sid and the type of the unix group.
****************************************************************************/
-static bool get_group_map_from_sid(
DOM_SID
sid, GROUP_MAP *map)
+static bool get_group_map_from_sid(
struct dom_sid
sid, GROUP_MAP *map)
{
TDB_DATA dbuf;
char *key;
{
TDB_DATA dbuf;
char *key;
@@
-286,7
+291,7
@@
static bool get_group_map_from_ntname(const char *name, GROUP_MAP *map)
Remove a group mapping entry.
****************************************************************************/
Remove a group mapping entry.
****************************************************************************/
-static bool group_map_remove(const
DOM_SID
*sid)
+static bool group_map_remove(const
struct dom_sid
*sid)
{
char *key;
NTSTATUS status;
{
char *key;
NTSTATUS status;
@@
-307,7
+312,7
@@
static bool group_map_remove(const DOM_SID *sid)
****************************************************************************/
struct enum_map_state {
****************************************************************************/
struct enum_map_state {
- const
DOM_SID
*domsid;
+ const
struct dom_sid
*domsid;
enum lsa_SidType sid_name_use;
bool unix_only;
enum lsa_SidType sid_name_use;
bool unix_only;
@@
-339,7
+344,7
@@
static int collect_map(struct db_record *rec, void *private_data)
}
if ((state->domsid != NULL) &&
}
if ((state->domsid != NULL) &&
- (sid_compare_domain(state->domsid, &map.sid) != 0)) {
+ (
dom_
sid_compare_domain(state->domsid, &map.sid) != 0)) {
DEBUG(11,("enum_group_mapping: group %s is not in domain\n",
sid_string_dbg(&map.sid)));
return 0;
DEBUG(11,("enum_group_mapping: group %s is not in domain\n",
sid_string_dbg(&map.sid)));
return 0;
@@
-358,7
+363,7
@@
static int collect_map(struct db_record *rec, void *private_data)
return 0;
}
return 0;
}
-static bool enum_group_mapping(const
DOM_SID
*domsid,
+static bool enum_group_mapping(const
struct dom_sid
*domsid,
enum lsa_SidType sid_name_use,
GROUP_MAP **pp_rmap,
size_t *p_num_entries, bool unix_only)
enum lsa_SidType sid_name_use,
GROUP_MAP **pp_rmap,
size_t *p_num_entries, bool unix_only)
@@
-384,8
+389,8
@@
static bool enum_group_mapping(const DOM_SID *domsid,
/* This operation happens on session setup, so it should better be fast. We
* store a list of aliases a SID is member of hanging off MEMBEROF/SID. */
/* This operation happens on session setup, so it should better be fast. We
* store a list of aliases a SID is member of hanging off MEMBEROF/SID. */
-static NTSTATUS one_alias_membership(const
DOM_SID
*member,
-
DOM_SID
**sids, size_t *num)
+static NTSTATUS one_alias_membership(const
struct dom_sid
*member,
+
struct dom_sid
**sids, size_t *num)
{
fstring tmp;
fstring key;
{
fstring tmp;
fstring key;
@@
-407,15
+412,18
@@
static NTSTATUS one_alias_membership(const DOM_SID *member,
p = (const char *)dbuf.dptr;
while (next_token_talloc(frame, &p, &string_sid, " ")) {
p = (const char *)dbuf.dptr;
while (next_token_talloc(frame, &p, &string_sid, " ")) {
- DOM_SID alias;
+ struct dom_sid alias;
+ uint32_t num_sids;
if (!string_to_sid(&alias, string_sid))
continue;
if (!string_to_sid(&alias, string_sid))
continue;
- status= add_sid_to_array_unique(NULL, &alias, sids, num);
+ num_sids = *num;
+ status= add_sid_to_array_unique(NULL, &alias, sids, &num_sids);
if (!NT_STATUS_IS_OK(status)) {
goto done;
}
if (!NT_STATUS_IS_OK(status)) {
goto done;
}
+ *num = num_sids;
}
done:
}
done:
@@
-423,8
+431,8
@@
done:
return status;
}
return status;
}
-static NTSTATUS alias_memberships(const
DOM_SID
*members, size_t num_members,
-
DOM_SID
**sids, size_t *num)
+static NTSTATUS alias_memberships(const
struct dom_sid
*members, size_t num_members,
+
struct dom_sid
**sids, size_t *num)
{
size_t i;
{
size_t i;
@@
-439,10
+447,11
@@
static NTSTATUS alias_memberships(const DOM_SID *members, size_t num_members,
return NT_STATUS_OK;
}
return NT_STATUS_OK;
}
-static bool is_aliasmem(const
DOM_SID *alias, const DOM_SID
*member)
+static bool is_aliasmem(const
struct dom_sid *alias, const struct dom_sid
*member)
{
{
- DOM_SID *sids;
- size_t i, num;
+ struct dom_sid *sids;
+ size_t i;
+ size_t num;
/* This feels the wrong way round, but the on-disk data structure
* dictates it this way. */
/* This feels the wrong way round, but the on-disk data structure
* dictates it this way. */
@@
-450,7
+459,7
@@
static bool is_aliasmem(const DOM_SID *alias, const DOM_SID *member)
return False;
for (i=0; i<num; i++) {
return False;
for (i=0; i<num; i++) {
- if (sid_compare(alias, &sids[i]) == 0) {
+ if (
dom_
sid_compare(alias, &sids[i]) == 0) {
TALLOC_FREE(sids);
return True;
}
TALLOC_FREE(sids);
return True;
}
@@
-460,7
+469,7
@@
static bool is_aliasmem(const DOM_SID *alias, const DOM_SID *member)
}
}
-static NTSTATUS add_aliasmem(const
DOM_SID *alias, const DOM_SID
*member)
+static NTSTATUS add_aliasmem(const
struct dom_sid *alias, const struct dom_sid
*member)
{
GROUP_MAP map;
char *key;
{
GROUP_MAP map;
char *key;
@@
-543,8
+552,8
@@
static NTSTATUS add_aliasmem(const DOM_SID *alias, const DOM_SID *member)
struct aliasmem_state {
TALLOC_CTX *mem_ctx;
struct aliasmem_state {
TALLOC_CTX *mem_ctx;
- const
DOM_SID
*alias;
-
DOM_SID
**sids;
+ const
struct dom_sid
*alias;
+
struct dom_sid
**sids;
size_t *num;
};
size_t *num;
};
@@
-564,13
+573,14
@@
static int collect_aliasmem(struct db_record *rec, void *priv)
frame = talloc_stackframe();
while (next_token_talloc(frame, &p, &alias_string, " ")) {
frame = talloc_stackframe();
while (next_token_talloc(frame, &p, &alias_string, " ")) {
-
DOM_SID
alias, member;
+
struct dom_sid
alias, member;
const char *member_string;
const char *member_string;
+ uint32_t num_sids;
if (!string_to_sid(&alias, alias_string))
continue;
if (!string_to_sid(&alias, alias_string))
continue;
- if (sid_compare(state->alias, &alias) != 0)
+ if (
dom_
sid_compare(state->alias, &alias) != 0)
continue;
/* Ok, we found the alias we're looking for in the membership
continue;
/* Ok, we found the alias we're looking for in the membership
@@
-588,21
+598,23
@@
static int collect_aliasmem(struct db_record *rec, void *priv)
if (!string_to_sid(&member, member_string))
continue;
if (!string_to_sid(&member, member_string))
continue;
+ num_sids = *state->num;
if (!NT_STATUS_IS_OK(add_sid_to_array(state->mem_ctx, &member,
state->sids,
if (!NT_STATUS_IS_OK(add_sid_to_array(state->mem_ctx, &member,
state->sids,
-
state->num
)))
+
&num_sids
)))
{
/* talloc fail. */
break;
}
{
/* talloc fail. */
break;
}
+ *state->num = num_sids;
}
TALLOC_FREE(frame);
return 0;
}
}
TALLOC_FREE(frame);
return 0;
}
-static NTSTATUS enum_aliasmem(const
DOM_SID
*alias, TALLOC_CTX *mem_ctx,
-
DOM_SID
**sids, size_t *num)
+static NTSTATUS enum_aliasmem(const
struct dom_sid
*alias, TALLOC_CTX *mem_ctx,
+
struct dom_sid
**sids, size_t *num)
{
GROUP_MAP map;
struct aliasmem_state state;
{
GROUP_MAP map;
struct aliasmem_state state;
@@
-626,10
+638,10
@@
static NTSTATUS enum_aliasmem(const DOM_SID *alias, TALLOC_CTX *mem_ctx,
return NT_STATUS_OK;
}
return NT_STATUS_OK;
}
-static NTSTATUS del_aliasmem(const
DOM_SID *alias, const DOM_SID
*member)
+static NTSTATUS del_aliasmem(const
struct dom_sid *alias, const struct dom_sid
*member)
{
NTSTATUS status;
{
NTSTATUS status;
-
DOM_SID
*sids;
+
struct dom_sid
*sids;
size_t i, num;
bool found = False;
char *member_string;
size_t i, num;
bool found = False;
char *member_string;
@@
-648,7
+660,7
@@
static NTSTATUS del_aliasmem(const DOM_SID *alias, const DOM_SID *member)
}
for (i=0; i<num; i++) {
}
for (i=0; i<num; i++) {
- if (sid_compare(&sids[i], alias) == 0) {
+ if (
dom_
sid_compare(&sids[i], alias) == 0) {
found = True;
break;
}
found = True;
break;
}
@@
-760,7
+772,7
@@
static int convert_ldb_record(TDB_CONTEXT *ltdb, TDB_DATA key,
char *val;
char *q;
uint32_t num_mem = 0;
char *val;
char *q;
uint32_t num_mem = 0;
-
DOM_SID
*members = NULL;
+
struct dom_sid
*members = NULL;
p = (uint8_t *)data.dptr;
if (data.dsize < 8) {
p = (uint8_t *)data.dptr;
if (data.dsize < 8) {
@@
-837,9
+849,9
@@
static int convert_ldb_record(TDB_CONTEXT *ltdb, TDB_DATA key,
p += len + 1;
num_vals = pull_uint32(p, 0);
p += len + 1;
num_vals = pull_uint32(p, 0);
- if (
StrCaseCmp
(name, "member") == 0) {
+ if (
strcasecmp_m
(name, "member") == 0) {
num_mem = num_vals;
num_mem = num_vals;
- members = talloc_array(tmp_ctx,
DOM_SID
, num_mem);
+ members = talloc_array(tmp_ctx,
struct dom_sid
, num_mem);
if (members == NULL) {
errno = ENOMEM;
goto failed;
if (members == NULL) {
errno = ENOMEM;
goto failed;
@@
-870,30
+882,30
@@
static int convert_ldb_record(TDB_CONTEXT *ltdb, TDB_DATA key,
/* we ignore unknown or uninteresting attributes
* (objectclass, etc.) */
/* we ignore unknown or uninteresting attributes
* (objectclass, etc.) */
- if (
StrCaseCmp
(name, "gidNumber") == 0) {
+ if (
strcasecmp_m
(name, "gidNumber") == 0) {
map.gid = strtoul(val, &q, 10);
if (*q) {
errno = EIO;
goto failed;
}
map.gid = strtoul(val, &q, 10);
if (*q) {
errno = EIO;
goto failed;
}
- } else if (
StrCaseCmp
(name, "sid") == 0) {
+ } else if (
strcasecmp_m
(name, "sid") == 0) {
if (!string_to_sid(&map.sid, val)) {
errno = EIO;
goto failed;
}
if (!string_to_sid(&map.sid, val)) {
errno = EIO;
goto failed;
}
- } else if (
StrCaseCmp
(name, "sidNameUse") == 0) {
+ } else if (
strcasecmp_m
(name, "sidNameUse") == 0) {
map.sid_name_use = strtoul(val, &q, 10);
if (*q) {
errno = EIO;
goto failed;
}
map.sid_name_use = strtoul(val, &q, 10);
if (*q) {
errno = EIO;
goto failed;
}
- } else if (
StrCaseCmp
(name, "ntname") == 0) {
+ } else if (
strcasecmp_m
(name, "ntname") == 0) {
strlcpy(map.nt_name, val,
strlcpy(map.nt_name, val,
- sizeof(map.nt_name)
-1
);
- } else if (
StrCaseCmp
(name, "comment") == 0) {
+ sizeof(map.nt_name));
+ } else if (
strcasecmp_m
(name, "comment") == 0) {
strlcpy(map.comment, val,
strlcpy(map.comment, val,
- sizeof(map.comment)
-1
);
- } else if (
StrCaseCmp
(name, "member") == 0) {
+ sizeof(map.comment));
+ } else if (
strcasecmp_m
(name, "member") == 0) {
if (!string_to_sid(&members[j], val)) {
errno = EIO;
goto failed;
if (!string_to_sid(&members[j], val)) {
errno = EIO;
goto failed;
@@
-935,7
+947,7
@@
failed:
static bool mapping_switch(const char *ldb_path)
{
static bool mapping_switch(const char *ldb_path)
{
-
static TALLOC_CTX
*ltdb;
+
TDB_CONTEXT
*ltdb;
TALLOC_CTX *frame;
char *new_path;
int ret;
TALLOC_CTX *frame;
char *new_path;
int ret;
@@
-968,7
+980,7
@@
static bool mapping_switch(const char *ldb_path)
return True;
failed:
return True;
failed:
- DEBUG(0,
("Failed to swit
h to tdb group mapping database\n"));
+ DEBUG(0,
("Failed to switc
h to tdb group mapping database\n"));
if (ltdb) tdb_close(ltdb);
TALLOC_FREE(frame);
return False;
if (ltdb) tdb_close(ltdb);
TALLOC_FREE(frame);
return False;