mirror of
https://github.com/samba-team/samba.git
synced 2025-12-07 20:23:50 +03:00
r9685: Add tests for samba3sam mapping module
Fix a couple of bugs Move samba3sam backend to lib/ldb/ Remove some more unused parameters
This commit is contained in:
committed by
Gerald (Jerry) Carter
parent
4a51a31571
commit
7f864d446d
@@ -226,6 +226,17 @@ int ldb_load_modules(struct ldb_context *ldb, const char *options[])
|
||||
DLIST_ADD(ldb->modules, current);
|
||||
continue;
|
||||
}
|
||||
|
||||
if (strcmp(modules[i], "samba3sam") == 0) {
|
||||
current = ldb_samba3sam_module_init(ldb, options);
|
||||
if (!current) {
|
||||
ldb_debug(ldb, LDB_DEBUG_FATAL, "function 'init_module' in %s fails\n", modules[i]);
|
||||
return -1;
|
||||
}
|
||||
DLIST_ADD(ldb->modules, current);
|
||||
continue;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
ldb_debug(ldb, LDB_DEBUG_WARNING, "WARNING: Module [%s] not found\n", modules[i]);
|
||||
|
||||
@@ -115,7 +115,8 @@ REQUIRED_SUBSYSTEMS = \
|
||||
# Start SUBSYSTEM LDBSAMBA
|
||||
[SUBSYSTEM::LDBSAMBA]
|
||||
OBJ_FILES = \
|
||||
lib/ldb/samba/ldif_handlers.o
|
||||
lib/ldb/samba/ldif_handlers.o \
|
||||
lib/ldb/samba/samba3sam.o
|
||||
# End SUBSYSTEM LDBSAMBA
|
||||
################################################
|
||||
|
||||
|
||||
@@ -126,6 +126,9 @@ static struct ldb_dn *map_remote_dn(struct ldb_module *module, const struct ldb_
|
||||
struct ldb_dn *newdn;
|
||||
int i;
|
||||
|
||||
if (dn == NULL)
|
||||
return NULL;
|
||||
|
||||
newdn = talloc_memdup(module, dn, sizeof(*dn));
|
||||
if (!newdn)
|
||||
return NULL;
|
||||
@@ -183,6 +186,9 @@ static struct ldb_dn *map_local_dn(struct ldb_module *module, const struct ldb_d
|
||||
int i;
|
||||
struct ldb_parse_tree eqtree, *new_eqtree;
|
||||
|
||||
if (dn == NULL)
|
||||
return NULL;
|
||||
|
||||
newdn = talloc_memdup(module, dn, sizeof(*dn));
|
||||
if (!newdn)
|
||||
return NULL;
|
||||
@@ -252,8 +258,6 @@ static struct ldb_dn *map_local_dn(struct ldb_module *module, const struct ldb_d
|
||||
return newdn;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/* Loop over ldb_map_attribute array and add remote_names */
|
||||
static const char **ldb_map_attrs(struct ldb_module *module, const char *const attrs[])
|
||||
{
|
||||
@@ -261,6 +265,9 @@ static const char **ldb_map_attrs(struct ldb_module *module, const char *const a
|
||||
const char **ret;
|
||||
int ar_size = 0, last_element = 0;
|
||||
|
||||
if (attrs == NULL)
|
||||
return NULL;
|
||||
|
||||
/* Start with good guess of number of elements */
|
||||
for (i = 0; attrs[i]; i++);
|
||||
|
||||
|
||||
198
source/lib/ldb/samba/samba3sam.c
Normal file
198
source/lib/ldb/samba/samba3sam.c
Normal file
@@ -0,0 +1,198 @@
|
||||
/*
|
||||
ldb database library - Samba3 SAM compatibility backend
|
||||
|
||||
Copyright (C) Jelmer Vernooij 2005
|
||||
|
||||
** NOTE! The following LGPL license applies to the ldb
|
||||
** library. This does NOT imply that all of Samba is released
|
||||
** under the LGPL
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2 of the License, or (at your option) any later version.
|
||||
|
||||
This library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with this library; if not, write to the Free Software
|
||||
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
|
||||
#include "includes.h"
|
||||
#include "ldb/ldb_map/ldb_map.h"
|
||||
#include "ldb/include/ldb.h"
|
||||
#include "ldb/include/ldb_private.h"
|
||||
|
||||
/* FIXME:
|
||||
* sambaSID -> member
|
||||
* sambaSIDList -> member (special!)
|
||||
* sambaDomainName -> name
|
||||
* sambaTrustPassword
|
||||
* sambaUnixIdPool
|
||||
* sambaIdmapEntry
|
||||
* sambaAccountPolicy
|
||||
* sambaSidEntry
|
||||
* sambaAcctFlags -> systemFlags ?
|
||||
* sambaPasswordHistory -> ntPwdHistory*/
|
||||
|
||||
/* Not necessary:
|
||||
* sambaConfig
|
||||
* sambaShare
|
||||
* sambaConfigOption
|
||||
* sambaNextGroupRid
|
||||
* sambaNextUserRid
|
||||
* sambaAlgorithmicRidBase
|
||||
*/
|
||||
|
||||
/* Not in Samba4:
|
||||
* sambaKickoffTime
|
||||
* sambaPwdCanChange
|
||||
* sambaPwdMustChange
|
||||
* sambaHomePath
|
||||
* sambaHomeDrive
|
||||
* sambaLogonScript
|
||||
* sambaProfilePath
|
||||
* sambaUserWorkstations
|
||||
* sambaMungedDial
|
||||
* sambaLogonHours */
|
||||
|
||||
|
||||
|
||||
const struct ldb_map_objectclass samba3_objectclasses[] = {
|
||||
{ "group", "sambaGroupMapping" },
|
||||
{ "user", "sambaSAMAccount" },
|
||||
{ "domain", "sambaDomain" },
|
||||
};
|
||||
|
||||
const struct ldb_map_attribute samba3_attributes[] =
|
||||
{
|
||||
/* sambaNextRid -> nextRid */
|
||||
{
|
||||
.local_name = "nextRid",
|
||||
.type = MAP_RENAME,
|
||||
.u.rename.remote_name = "sambaNextRid",
|
||||
},
|
||||
|
||||
/* sambaBadPasswordTime -> badPasswordtime*/
|
||||
{
|
||||
.local_name = "badPasswordTime",
|
||||
.type = MAP_RENAME,
|
||||
.u.rename.remote_name = "sambaBadPasswordTime",
|
||||
},
|
||||
|
||||
/* sambaLMPassword -> lmPwdHash*/
|
||||
{
|
||||
.local_name = "lmPwdHash",
|
||||
.type = MAP_RENAME,
|
||||
.u.rename.remote_name = "sambaLMPassword",
|
||||
},
|
||||
|
||||
/* sambaGroupType -> groupType */
|
||||
{
|
||||
.local_name = "groupType",
|
||||
.type = MAP_RENAME,
|
||||
.u.rename.remote_name = "sambaGroupType",
|
||||
},
|
||||
|
||||
/* sambaNTPassword -> ntPwdHash*/
|
||||
{
|
||||
.local_name = "badPwdCount",
|
||||
.type = MAP_RENAME,
|
||||
.u.rename.remote_name = "sambaNTPassword",
|
||||
},
|
||||
|
||||
/* sambaPrimaryGroupSID -> primaryGroupID */
|
||||
{
|
||||
.local_name = "primaryGroupID",
|
||||
.type = MAP_CONVERT,
|
||||
.u.convert.remote_name = "sambaPrimaryGroupSID",
|
||||
.u.convert.convert_local = NULL, /* FIXME: Add domain SID */
|
||||
.u.convert.convert_remote = NULL, /* FIXME: Extract RID */
|
||||
},
|
||||
|
||||
/* sambaBadPasswordCount -> badPwdCount */
|
||||
{
|
||||
.local_name = "badPwdCount",
|
||||
.type = MAP_RENAME,
|
||||
.u.rename.remote_name = "sambaBadPasswordCount",
|
||||
},
|
||||
|
||||
/* sambaLogonTime -> lastLogon*/
|
||||
{
|
||||
.local_name = "lastLogon",
|
||||
.type = MAP_RENAME,
|
||||
.u.rename.remote_name = "sambaLogonTime",
|
||||
},
|
||||
|
||||
/* sambaLogoffTime -> lastLogoff*/
|
||||
{
|
||||
.local_name = "lastLogoff",
|
||||
.type = MAP_RENAME,
|
||||
.u.rename.remote_name = "sambaLogoffTime",
|
||||
},
|
||||
|
||||
/* gidNumber -> unixName */
|
||||
{
|
||||
.local_name = "unixName",
|
||||
.type = MAP_CONVERT,
|
||||
.u.convert.remote_name = "gidNumber",
|
||||
.u.convert.convert_local = NULL, /* FIXME: Lookup gid */
|
||||
.u.convert.convert_remote = NULL, /* FIXME: Lookup groupname */
|
||||
},
|
||||
|
||||
/* uid -> unixName */
|
||||
{
|
||||
.local_name = "unixName",
|
||||
.type = MAP_CONVERT,
|
||||
.u.convert.remote_name = "uid",
|
||||
.u.convert.convert_local = NULL, /* FIXME: Lookup uid */
|
||||
.u.convert.convert_remote = NULL, /* FIXME: Lookup username */
|
||||
},
|
||||
|
||||
/* displayName -> name */
|
||||
{
|
||||
.local_name = "name",
|
||||
.type = MAP_RENAME,
|
||||
.u.rename.remote_name = "displayName",
|
||||
},
|
||||
|
||||
/* cn */
|
||||
{
|
||||
.local_name = "cn",
|
||||
.type = MAP_KEEP,
|
||||
},
|
||||
|
||||
/* description */
|
||||
{
|
||||
.local_name = "description",
|
||||
.type = MAP_KEEP,
|
||||
},
|
||||
|
||||
/* sambaSID -> objectSid*/
|
||||
{
|
||||
.local_name = "objectSid",
|
||||
.type = MAP_RENAME,
|
||||
.u.rename.remote_name = "sambaSID",
|
||||
},
|
||||
|
||||
/* sambaPwdLastSet -> pwdLastSet*/
|
||||
{
|
||||
.local_name = "pwdLastSet",
|
||||
.type = MAP_RENAME,
|
||||
.u.rename.remote_name = "sambaPwdLastSet",
|
||||
},
|
||||
};
|
||||
|
||||
/* the init function */
|
||||
#ifdef HAVE_DLOPEN_DISABLED
|
||||
struct ldb_module *init_module(struct ldb_context *ldb, const char *options[])
|
||||
#else
|
||||
struct ldb_module *ldb_samba3sam_module_init(struct ldb_context *ldb, const char *options[])
|
||||
#endif
|
||||
{
|
||||
return ldb_map_init(ldb, &samba3_attributes, &samba3_objectclasses, options);
|
||||
}
|
||||
203
source/lib/ldb/tests/samba3.ldif
Normal file
203
source/lib/ldb/tests/samba3.ldif
Normal file
@@ -0,0 +1,203 @@
|
||||
dn: dc=idealx,dc=org
|
||||
objectClass: dcObject
|
||||
objectclass: organization
|
||||
o: idealx
|
||||
dc: idealx
|
||||
|
||||
dn: ou=Users,dc=idealx,dc=org
|
||||
objectClass: organizationalUnit
|
||||
ou: Users
|
||||
|
||||
dn: ou=Groups,dc=idealx,dc=org
|
||||
objectClass: organizationalUnit
|
||||
ou: Groups
|
||||
|
||||
dn: ou=Computers,dc=idealx,dc=org
|
||||
objectClass: organizationalUnit
|
||||
ou: Computers
|
||||
dn: uid=Administrator,ou=Users,dc=idealx,dc=org
|
||||
cn: Administrator
|
||||
sn: Administrator
|
||||
objectClass: inetOrgPerson
|
||||
objectClass: sambaSAMAccount
|
||||
objectClass: posixAccount
|
||||
objectClass: shadowAccount
|
||||
gidNumber: 512
|
||||
uid: Administrator
|
||||
uidNumber: 0
|
||||
homeDirectory: /home/%U
|
||||
sambaPwdLastSet: 0
|
||||
sambaLogonTime: 0
|
||||
sambaLogoffTime: 2147483647
|
||||
sambaKickoffTime: 2147483647
|
||||
sambaPwdCanChange: 0
|
||||
sambaPwdMustChange: 2147483647
|
||||
sambaHomePath: \\PDC-SMB3\home\%U
|
||||
sambaHomeDrive: H:
|
||||
sambaProfilePath: \\PDC-SMB3\profiles\%U\Administrator
|
||||
sambaPrimaryGroupSID: S-1-5-21-4231626423-2410014848-2360679739-512
|
||||
sambaLMPassword: XXX
|
||||
sambaNTPassword: XXX
|
||||
sambaAcctFlags: [U ]
|
||||
sambaSID: S-1-5-21-4231626423-2410014848-2360679739-2996
|
||||
loginShell: /bin/false
|
||||
gecos: Netbios Domain Administrator
|
||||
|
||||
dn: uid=nobody,ou=Users,dc=idealx,dc=org
|
||||
cn: nobody
|
||||
sn: nobody
|
||||
objectClass: inetOrgPerson
|
||||
objectClass: sambaSAMAccount
|
||||
objectClass: posixAccount
|
||||
objectClass: shadowAccount
|
||||
gidNumber: 514
|
||||
uid: nobody
|
||||
uidNumber: 999
|
||||
homeDirectory: /dev/null
|
||||
sambaPwdLastSet: 0
|
||||
sambaLogonTime: 0
|
||||
sambaLogoffTime: 2147483647
|
||||
sambaKickoffTime: 2147483647
|
||||
sambaPwdCanChange: 0
|
||||
sambaPwdMustChange: 2147483647
|
||||
sambaHomePath: \\PDC-SMB3\home\%U
|
||||
sambaHomeDrive: H:
|
||||
sambaProfilePath: \\PDC-SMB3\profiles\%U\nobody
|
||||
sambaPrimaryGroupSID: S-1-5-21-4231626423-2410014848-2360679739-514
|
||||
sambaLMPassword: NO PASSWORDXXXXXXXXXXXXXXXXXXXXX
|
||||
sambaNTPassword: NO PASSWORDXXXXXXXXXXXXXXXXXXXXX
|
||||
sambaAcctFlags: [NU ]
|
||||
sambaSID: S-1-5-21-4231626423-2410014848-2360679739-2998
|
||||
loginShell: /bin/false
|
||||
|
||||
dn: cn=Domain Admins,ou=Groups,dc=idealx,dc=org
|
||||
objectClass: posixGroup
|
||||
objectClass: sambaGroupMapping
|
||||
gidNumber: 512
|
||||
cn: Domain Admins
|
||||
memberUid: Administrator
|
||||
description: Netbios Domain Administrators
|
||||
sambaSID: S-1-5-21-4231626423-2410014848-2360679739-512
|
||||
sambaGroupType: 2
|
||||
displayName: Domain Admins
|
||||
|
||||
dn: cn=Domain Users,ou=Groups,dc=idealx,dc=org
|
||||
objectClass: posixGroup
|
||||
objectClass: sambaGroupMapping
|
||||
gidNumber: 513
|
||||
cn: Domain Users
|
||||
description: Netbios Domain Users
|
||||
sambaSID: S-1-5-21-4231626423-2410014848-2360679739-513
|
||||
sambaGroupType: 2
|
||||
displayName: Domain Users
|
||||
|
||||
dn: cn=Domain Guests,ou=Groups,dc=idealx,dc=org
|
||||
objectClass: posixGroup
|
||||
objectClass: sambaGroupMapping
|
||||
gidNumber: 514
|
||||
cn: Domain Guests
|
||||
description: Netbios Domain Guests Users
|
||||
sambaSID: S-1-5-21-4231626423-2410014848-2360679739-514
|
||||
sambaGroupType: 2
|
||||
displayName: Domain Guests
|
||||
|
||||
dn: cn=Print Operators,ou=Groups,dc=idealx,dc=org
|
||||
objectClass: posixGroup
|
||||
objectClass: sambaGroupMapping
|
||||
gidNumber: 550
|
||||
cn: Print Operators
|
||||
description: Netbios Domain Print Operators
|
||||
sambaSID: S-1-5-21-4231626423-2410014848-2360679739-550
|
||||
sambaGroupType: 2
|
||||
displayName: Print Operators
|
||||
|
||||
dn: cn=Backup Operators,ou=Groups,dc=idealx,dc=org
|
||||
objectClass: posixGroup
|
||||
objectClass: sambaGroupMapping
|
||||
gidNumber: 551
|
||||
cn: Backup Operators
|
||||
description: Netbios Domain Members can bypass file security to back up files
|
||||
sambaSID: S-1-5-21-4231626423-2410014848-2360679739-551
|
||||
sambaGroupType: 2
|
||||
displayName: Backup Operators
|
||||
|
||||
dn: cn=Replicator,ou=Groups,dc=idealx,dc=org
|
||||
objectClass: posixGroup
|
||||
objectClass: sambaGroupMapping
|
||||
gidNumber: 552
|
||||
cn: Replicator
|
||||
description: Netbios Domain Supports file replication in a sambaDomainName
|
||||
sambaSID: S-1-5-21-4231626423-2410014848-2360679739-552
|
||||
sambaGroupType: 2
|
||||
displayName: Replicator
|
||||
|
||||
dn: cn=Domain Computers,ou=Groups,dc=idealx,dc=org
|
||||
objectClass: posixGroup
|
||||
objectClass: sambaGroupMapping
|
||||
gidNumber: 553
|
||||
cn: Domain Computers
|
||||
description: Netbios Domain Computers accounts
|
||||
sambaSID: S-1-5-21-4231626423-2410014848-2360679739-553
|
||||
sambaGroupType: 2
|
||||
displayName: Domain Computers
|
||||
|
||||
dn: cn=Administrators,ou=Groups,dc=idealx,dc=org
|
||||
objectClass: posixGroup
|
||||
objectClass: sambaGroupMapping
|
||||
gidNumber: 544
|
||||
cn: Administrators
|
||||
description: Netbios Domain Members can fully administer the computer/sambaDomainName
|
||||
sambaSID: S-1-5-21-4231626423-2410014848-2360679739-544
|
||||
sambaGroupType: 2
|
||||
displayName: Administrators
|
||||
|
||||
dn: cn=Users,ou=Groups,dc=idealx,dc=org
|
||||
objectClass: posixGroup
|
||||
objectClass: sambaGroupMapping
|
||||
gidNumber: 545
|
||||
cn: Users
|
||||
description: Netbios Domain Ordinary users
|
||||
sambaSID: S-1-5-21-4231626423-2410014848-2360679739-545
|
||||
sambaGroupType: 2
|
||||
displayName: users
|
||||
|
||||
dn: cn=Guests,ou=Groups,dc=idealx,dc=org
|
||||
objectClass: posixGroup
|
||||
objectClass: sambaGroupMapping
|
||||
gidNumber: 546
|
||||
cn: Guests
|
||||
memberUid: nobody
|
||||
description: Netbios Domain Users granted guest access to the computer/sambaDomainName
|
||||
sambaSID: S-1-5-21-4231626423-2410014848-2360679739-546
|
||||
sambaGroupType: 2
|
||||
displayName: Guests
|
||||
|
||||
dn: cn=Power Users,ou=Groups,dc=idealx,dc=org
|
||||
objectClass: posixGroup
|
||||
objectClass: sambaGroupMapping
|
||||
gidNumber: 547
|
||||
cn: Power Users
|
||||
description: Netbios Domain Members can share directories and printers
|
||||
sambaSID: S-1-5-21-4231626423-2410014848-2360679739-547
|
||||
sambaGroupType: 2
|
||||
displayName: Power Users
|
||||
|
||||
dn: cn=Account Operators,ou=Groups,dc=idealx,dc=org
|
||||
objectClass: posixGroup
|
||||
objectClass: sambaGroupMapping
|
||||
gidNumber: 548
|
||||
cn: Account Operators
|
||||
description: Netbios Domain Users to manipulate users accounts
|
||||
sambaSID: S-1-5-21-4231626423-2410014848-2360679739-548
|
||||
sambaGroupType: 2
|
||||
displayName: Account Operators
|
||||
|
||||
dn: cn=Server Operators,ou=Groups,dc=idealx,dc=org
|
||||
objectClass: posixGroup
|
||||
objectClass: sambaGroupMapping
|
||||
gidNumber: 549
|
||||
cn: Server Operators
|
||||
description: Netbios Domain Server Operators
|
||||
sambaSID: S-1-5-21-4231626423-2410014848-2360679739-549
|
||||
sambaGroupType: 2
|
||||
displayName: Server Operators
|
||||
8
source/lib/ldb/tests/test-samba3sam.sh
Executable file
8
source/lib/ldb/tests/test-samba3sam.sh
Executable file
@@ -0,0 +1,8 @@
|
||||
#!/bin/sh
|
||||
|
||||
rm -f samba3.ldb
|
||||
|
||||
$VALGRIND ldbadd -H tdb://samba3.ldb < samba3.ldif
|
||||
|
||||
OPT="-o modules:samba3sam -H tdb://samba3.ldb "
|
||||
$VALGRIND ldbsearch $OPT "(cn=Administrator)"
|
||||
@@ -124,13 +124,14 @@ struct ldb_cmdline *ldb_cmdline_process(struct ldb_context *ldb, int argc, const
|
||||
|
||||
case 'o':
|
||||
options.options = talloc_realloc(ret, options.options,
|
||||
const char *, num_options+2);
|
||||
const char *, num_options+3);
|
||||
if (options.options == NULL) {
|
||||
ldb_oom(ldb);
|
||||
goto failed;
|
||||
}
|
||||
options.options[num_options++] = poptGetOptArg(pc);
|
||||
options.options[num_options] = poptGetOptArg(pc);
|
||||
options.options[num_options+1] = NULL;
|
||||
num_options++;
|
||||
break;
|
||||
|
||||
default:
|
||||
|
||||
Reference in New Issue
Block a user