diff options
author | Jelmer Vernooij <jelmer@samba.org> | 2005-08-28 14:55:26 +0000 |
---|---|---|
committer | Gerald (Jerry) Carter <jerry@samba.org> | 2007-10-10 13:34:52 -0500 |
commit | 8b15ef881d21b713817bb3aa3599288ecdde0d28 (patch) | |
tree | 275dff742dddefa7040b273de34fd53195c18ee5 /source4/lib/samba3 | |
parent | 707a237e76cfb6e32b5b930327f209aff2c60b64 (diff) | |
download | samba-8b15ef881d21b713817bb3aa3599288ecdde0d28.tar.gz samba-8b15ef881d21b713817bb3aa3599288ecdde0d28.tar.bz2 samba-8b15ef881d21b713817bb3aa3599288ecdde0d28.zip |
r9712: Bunch of small fixes
Write out basic sam.ldif
(This used to be commit 67593bef7f0f8dc2258b2fe9c06779f0025d240e)
Diffstat (limited to 'source4/lib/samba3')
-rw-r--r-- | source4/lib/samba3/group.c | 15 | ||||
-rw-r--r-- | source4/lib/samba3/idmap.c | 2 | ||||
-rw-r--r-- | source4/lib/samba3/samba3.c | 102 | ||||
-rw-r--r-- | source4/lib/samba3/samba3dump.c | 20 | ||||
-rw-r--r-- | source4/lib/samba3/share_info.c | 2 | ||||
-rw-r--r-- | source4/lib/samba3/tdbsam.c | 1 | ||||
-rw-r--r-- | source4/lib/samba3/upgrade.c | 105 |
7 files changed, 200 insertions, 47 deletions
diff --git a/source4/lib/samba3/group.c b/source4/lib/samba3/group.c index 68ac5987d0..220f206e99 100644 --- a/source4/lib/samba3/group.c +++ b/source4/lib/samba3/group.c @@ -82,16 +82,21 @@ NTSTATUS samba3_read_grouptdb(const char *file, TALLOC_CTX *ctx, struct samba3_g if (!dbuf.dptr) continue; - map.sid = dom_sid_parse_talloc(ctx, kbuf.dptr+strlen(GROUP_PREFIX)); + ZERO_STRUCT(map); - ret = tdb_unpack(tdb, dbuf.dptr, dbuf.dsize, "ddff", - &map.gid, &map.sid_name_use, &map.nt_name, &map.comment); + map.sid = dom_sid_parse_talloc(ctx, kbuf.dptr+strlen(GROUP_PREFIX)); + ret = tdb_unpack(tdb, dbuf.dptr, dbuf.dsize, "dd", + &map.gid, &map.sid_name_use); + if ( ret == -1 ) { DEBUG(3,("enum_group_mapping: tdb_unpack failure\n")); continue; } + map.nt_name = talloc_strdup(ctx, dbuf.dptr+ret); + map.comment = talloc_strdup(ctx, dbuf.dptr+ret+strlen(map.nt_name)); + db->groupmappings = talloc_realloc(ctx, db->groupmappings, struct samba3_groupmapping, db->groupmap_count+1); if (!db->groupmappings) @@ -100,9 +105,7 @@ NTSTATUS samba3_read_grouptdb(const char *file, TALLOC_CTX *ctx, struct samba3_g db->groupmappings[db->groupmap_count] = map; db->groupmap_count++; - } - - if (strncmp(kbuf.dptr, MEMBEROF_PREFIX, strlen(MEMBEROF_PREFIX)) == 0) + } else if (strncmp(kbuf.dptr, MEMBEROF_PREFIX, strlen(MEMBEROF_PREFIX)) == 0) { struct samba3_alias alias; pstring alias_string; diff --git a/source4/lib/samba3/idmap.c b/source4/lib/samba3/idmap.c index ad0ef72ef2..b1c7c0dcca 100644 --- a/source4/lib/samba3/idmap.c +++ b/source4/lib/samba3/idmap.c @@ -39,7 +39,7 @@ Initialise idmap database. *****************************************************************************/ -NTSTATUS samba3_read_idmap( const char *fn, TALLOC_CTX *ctx, struct samba3_idmapdb *idmap ) +NTSTATUS samba3_read_idmap(const char *fn, TALLOC_CTX *ctx, struct samba3_idmapdb *idmap) { TDB_CONTEXT *tdb; TDB_DATA key, val; diff --git a/source4/lib/samba3/samba3.c b/source4/lib/samba3/samba3.c index 08debe96b1..4b893c585a 100644 --- a/source4/lib/samba3/samba3.c +++ b/source4/lib/samba3/samba3.c @@ -26,7 +26,19 @@ struct smbconf_data { struct samba3_share_info *current_share; }; -struct samba3_share_info *samba3_find_share(struct samba3 *db, TALLOC_CTX* ctx, const char *name) +struct samba3_domainsecrets *samba3_find_domainsecrets(struct samba3 *db, const char *name) +{ + int i; + + for (i = 0; i < db->secrets.domain_count; i++) { + if (!StrCaseCmp(db->secrets.domains[i].name, name)) + return &db->secrets.domains[i]; + } + + return NULL; +} + +struct samba3_share_info *samba3_find_share(struct samba3 *db, const char *name) { int i; for (i = 0; i < db->share_count; i++) { @@ -34,19 +46,47 @@ struct samba3_share_info *samba3_find_share(struct samba3 *db, TALLOC_CTX* ctx, return &db->shares[i]; } + return NULL; +} + + +struct samba3_share_info *samba3_find_add_share(struct samba3 *db, TALLOC_CTX* ctx, const char *name) +{ + struct samba3_share_info *share = samba3_find_share(db, name); + + if (share) + return share; + db->shares = talloc_realloc(ctx, db->shares, struct samba3_share_info, db->share_count+1); - ZERO_STRUCT(db->shares[i]); - db->shares[i].name = talloc_strdup(ctx, name); + ZERO_STRUCT(db->shares[db->share_count]); + db->shares[db->share_count].name = talloc_strdup(ctx, name); db->share_count++; - return &db->shares[i]; + return &db->shares[db->share_count-1]; +} + +const char *samba3_get_param(struct samba3 *samba3, const char *section, const char *param) +{ + int i; + struct samba3_share_info *share = samba3_find_share(samba3, section); + + if (share == NULL) + return NULL; + + for (i = 0; i < share->parameter_count; i++) { + if (!StrCaseCmp(share->parameters[i].name, param)) + return share->parameters[i].value; + } + + return NULL; } + static BOOL samba3_sfunc (const char *name, void *_db) { struct smbconf_data *privdat = _db; - privdat->current_share = samba3_find_share(privdat->db, privdat->ctx, name); + privdat->current_share = samba3_find_add_share(privdat->db, privdat->ctx, name); return True; } @@ -76,7 +116,7 @@ NTSTATUS samba3_read_smbconf(const char *fn, TALLOC_CTX *ctx, struct samba3 *db) privdat.ctx = ctx; privdat.db = db; - privdat.current_share = samba3_find_share(db, ctx, "global"); + privdat.current_share = samba3_find_add_share(db, ctx, "global"); if (!pm_process( fn, samba3_sfunc, samba3_pfunc, &privdat )) { return NT_STATUS_UNSUCCESSFUL; @@ -88,44 +128,44 @@ NTSTATUS samba3_read_smbconf(const char *fn, TALLOC_CTX *ctx, struct samba3 *db) NTSTATUS samba3_read(const char *smbconf, const char *libdir, TALLOC_CTX *ctx, struct samba3 **samba3) { struct samba3 *ret; - char *dbfile; + char *dbfile = NULL; ret = talloc_zero(ctx, struct samba3); if (smbconf) samba3_read_smbconf(smbconf, ctx, ret); - asprintf(&dbfile, "%s/wins.dat", libdir); - samba3_read_winsdb(dbfile, ret, &ret->winsdb_entries, &ret->winsdb_count); - SAFE_FREE(dbfile); - - asprintf(&dbfile, "%s/passdb.tdb", libdir); - samba3_read_tdbsam(dbfile, ctx, &ret->samaccounts, &ret->samaccount_count); - SAFE_FREE(dbfile); - - asprintf(&dbfile, "%s/group_mapping.tdb", libdir); - samba3_read_grouptdb(dbfile, ctx, &ret->group); - SAFE_FREE(dbfile); - - asprintf(&dbfile, "%s/winbindd_idmap.tdb", libdir); - samba3_read_idmap(dbfile, ctx, &ret->idmap); - SAFE_FREE(dbfile); - - asprintf(&dbfile, "%s/account_policy.tdb", libdir); + dbfile = talloc_asprintf(ctx, "%s/account_policy.tdb", libdir); samba3_read_account_policy(dbfile, ctx, &ret->policy); - SAFE_FREE(dbfile); + talloc_free(dbfile); - asprintf(&dbfile, "%s/registry.tdb", libdir); + dbfile = talloc_asprintf(ctx, "%s/registry.tdb", libdir); samba3_read_regdb(dbfile, ctx, &ret->registry); - SAFE_FREE(dbfile); + talloc_free(dbfile); - asprintf(&dbfile, "%s/secrets.tdb", libdir); + dbfile = talloc_asprintf(ctx, "%s/secrets.tdb", libdir); samba3_read_secrets(dbfile, ctx, &ret->secrets); - SAFE_FREE(dbfile); + talloc_free(dbfile); - asprintf(&dbfile, "%s/share_info.tdb", libdir); + dbfile = talloc_asprintf(ctx, "%s/share_info.tdb", libdir); samba3_read_share_info(dbfile, ctx, ret); - SAFE_FREE(dbfile); + talloc_free(dbfile); + + dbfile = talloc_asprintf(ctx, "%s/winbindd_idmap.tdb", libdir); + samba3_read_idmap(dbfile, ctx, &ret->idmap); + talloc_free(dbfile); + + dbfile = talloc_asprintf(ctx, "%s/wins.dat", libdir); + samba3_read_winsdb(dbfile, ret, &ret->winsdb_entries, &ret->winsdb_count); + talloc_free(dbfile); + + dbfile = talloc_asprintf(ctx, "%s/passdb.tdb", libdir); + samba3_read_tdbsam(dbfile, ctx, &ret->samaccounts, &ret->samaccount_count); + talloc_free(dbfile); + + dbfile = talloc_asprintf(ctx, "%s/group_mapping.tdb", libdir); + samba3_read_grouptdb(dbfile, ctx, &ret->group); + talloc_free(dbfile); *samba3 = ret; diff --git a/source4/lib/samba3/samba3dump.c b/source4/lib/samba3/samba3dump.c index a6166a1c6b..b95fc0d4b2 100644 --- a/source4/lib/samba3/samba3dump.c +++ b/source4/lib/samba3/samba3dump.c @@ -244,25 +244,35 @@ int main(int argc, char **argv) { int opt; const char *format = "summary"; - const char *libdir = "/var/lib/samba"; + char *libdir = NULL; + char *smbconf = NULL; struct samba3 *samba3; poptContext pc; + TALLOC_CTX *mem_ctx; struct poptOption long_options[] = { POPT_AUTOHELP { "format", 0, POPT_ARG_STRING, &format, 'f', "Format to use (one of: summary, text, ldif)" }, - { "libdir", 0, POPT_ARG_STRING, &libdir, 'l', "Set libdir [/var/lib/samba]", "LIBDIR" }, POPT_COMMON_SAMBA POPT_TABLEEND }; pc = poptGetContext(argv[0], argc, (const char **) argv, long_options,0); - poptSetOtherOptionHelp(pc, "<smb.conf>"); + poptSetOtherOptionHelp(pc, "<libdir> <smb.conf>"); while((opt = poptGetNextOpt(pc)) != -1) { } - samba3_read(poptGetArg(pc), libdir, NULL, &samba3); + samba3dump_init_subsystems; + + mem_ctx = talloc_init("samba3dump_context"); + + libdir = talloc_strdup(mem_ctx, poptGetArg(pc)); + smbconf = talloc_strdup(mem_ctx, poptGetArg(pc)); + + printf("Reading from libdir '%s', smb.conf file '%s'\n", libdir, smbconf); + + samba3_read(smbconf, libdir, mem_ctx, &samba3); if (!strcmp(format, "summary")) { printf("WINS db entries: %d\n", samba3->winsdb_count); @@ -276,7 +286,7 @@ int main(int argc, char **argv) print_samba3(samba3); } else if (!strcmp(format, "ldif")) { struct ldb_message **msgs; - struct ldb_context *ldb = ldb_init(NULL); + struct ldb_context *ldb = ldb_init(mem_ctx); int i, ret; const char *hives[] = { "hklm", "hkcr", "hku", "hkpd", "hkpt", NULL }; diff --git a/source4/lib/samba3/share_info.c b/source4/lib/samba3/share_info.c index 098d6c552e..3479a7063c 100644 --- a/source4/lib/samba3/share_info.c +++ b/source4/lib/samba3/share_info.c @@ -66,7 +66,7 @@ NTSTATUS samba3_read_share_info(const char *fn, TALLOC_CTX *ctx, struct samba3 * name = talloc_strndup(ctx, kbuf.dptr+strlen("SECDESC/"), kbuf.dsize-strlen("SECDESC/")); - share = samba3_find_share(db, ctx, name); + share = samba3_find_add_share(db, ctx, name); vbuf = tdb_fetch(tdb, kbuf); blob.data = (uint8_t *)vbuf.dptr; diff --git a/source4/lib/samba3/tdbsam.c b/source4/lib/samba3/tdbsam.c index 23e68717c7..c9b121ca77 100644 --- a/source4/lib/samba3/tdbsam.c +++ b/source4/lib/samba3/tdbsam.c @@ -271,6 +271,7 @@ NTSTATUS samba3_read_tdbsam(const char *filename, TALLOC_CTX *ctx, struct samba3 case 0: ret = init_sam_from_buffer_v0(tdb, &(*accounts)[*count], val); break; case 1: ret = init_sam_from_buffer_v1(tdb, &(*accounts)[*count], val); break; case 2: ret = init_sam_from_buffer_v2(tdb, &(*accounts)[*count], val); break; + default: ret = False; break; } diff --git a/source4/lib/samba3/upgrade.c b/source4/lib/samba3/upgrade.c index eeb77310ec..00000c68df 100644 --- a/source4/lib/samba3/upgrade.c +++ b/source4/lib/samba3/upgrade.c @@ -114,15 +114,114 @@ int samba3_upgrade_sam(struct samba3 *samba3, struct ldb_context *ldb, struct ld int count = 0; struct ldb_message *msg; struct ldb_dn *domaindn = NULL; + const char *domainname; + struct samba3_domainsecrets *domsec; + int i; *msgs = NULL; + domainname = samba3_get_param(samba3, "global", "workgroup"); + + if (domainname == NULL) { + DEBUG(0, ("No domain name specified in smb.conf!\n")); + return -1; + } + + domsec = samba3_find_domainsecrets(samba3, domainname); + /* Domain */ msg = msg_array_add(ldb, msgs, &count); - /* FIXME: Guess domain DN by taking ldap bind dn? */ - /* FIXME */ - return -1; + ldb_msg_add_string(ldb, msg, "objectClass", "top"); + ldb_msg_add_string(ldb, msg, "objectClass", "domain"); + ldb_msg_add_string(ldb, msg, "objectSid", dom_sid_string(msg, &domsec->sid)); + ldb_msg_add_string(ldb, msg, "objectGUID", GUID_string(msg, &domsec->guid)); + ldb_msg_add_string(ldb, msg, "name", domainname); + ldb_msg_add_string(ldb, msg, "oEMInformation", "Provisioned by Samba4 (upgraded from Samba3)"); + + /* account policy as well */ + + ldb_msg_add_fmt(ldb, msg, "minPwdLength", "%d", samba3->policy.min_password_length); + ldb_msg_add_fmt(ldb, msg, "pwdHistoryLength", "%d", samba3->policy.password_history); + ldb_msg_add_fmt(ldb, msg, "minPwdAge", "%d", samba3->policy.minimum_password_age); + ldb_msg_add_fmt(ldb, msg, "maxPwdAge", "%d", samba3->policy.maximum_password_age); + ldb_msg_add_fmt(ldb, msg, "lockoutDuration", "%d", samba3->policy.lockout_duration); + ldb_msg_add_fmt(ldb, msg, "samba3ResetCountMinutes", "%d", samba3->policy.reset_count_minutes); + ldb_msg_add_fmt(ldb, msg, "samba3UserMustLogonToChangePassword", "%d", samba3->policy.user_must_logon_to_change_password); + ldb_msg_add_fmt(ldb, msg, "samba3BadLockoutMinutes", "%d", samba3->policy.bad_lockout_minutes); + ldb_msg_add_fmt(ldb, msg, "samba3DisconnectTime", "%d", samba3->policy.disconnect_time); + ldb_msg_add_fmt(ldb, msg, "samba3RefuseMachinePwdChange", "%d", samba3->policy.refuse_machine_password_change); + + /* Users */ + for (i = 0; i < samba3->samaccount_count; i++) { + struct samba3_samaccount *sam = &samba3->samaccounts[i]; + + msg = msg_array_add(ldb, msgs, &count); + msg->dn = ldb_dn_build_child(msg, "cn", sam->fullname, domaindn); + + ldb_msg_add_string(ldb, msg, "objectClass", "top"); + ldb_msg_add_string(ldb, msg, "objectClass", "person"); + ldb_msg_add_string(ldb, msg, "objectClass", "user"); + ldb_msg_add_fmt(ldb, msg, "lastLogon", "%d", sam->logon_time); + ldb_msg_add_fmt(ldb, msg, "lastLogoff", "%d", sam->logoff_time); + ldb_msg_add_string(ldb, msg, "unixName", sam->username); + ldb_msg_add_string(ldb, msg, "name", sam->nt_username); + ldb_msg_add_string(ldb, msg, "cn", sam->fullname); + ldb_msg_add_string(ldb, msg, "description", sam->acct_desc); + ldb_msg_add_fmt(ldb, msg, "primaryGroupID", "%d", sam->group_rid); + ldb_msg_add_fmt(ldb, msg, "badPwdcount", "%d", sam->bad_password_count); + ldb_msg_add_fmt(ldb, msg, "logonCount", "%d", sam->logon_count); + + ldb_msg_add_string(ldb, msg, "samba3Domain", sam->domain); + if (sam->dir_drive) + ldb_msg_add_string(ldb, msg, "samba3DirDrive", sam->dir_drive); + + if (sam->munged_dial) + ldb_msg_add_string(ldb, msg, "samba3MungedDial", sam->munged_dial); + + if (sam->homedir) + ldb_msg_add_string(ldb, msg, "samba3Homedir", sam->homedir); + + if (sam->logon_script) + ldb_msg_add_string(ldb, msg, "samba3LogonScript", sam->logon_script); + + if (sam->profile_path) + ldb_msg_add_string(ldb, msg, "samba3ProfilePath", sam->profile_path); + + if (sam->workstations) + ldb_msg_add_string(ldb, msg, "samba3Workstations", sam->workstations); + + ldb_msg_add_fmt(ldb, msg, "samba3KickOffTime", "%d", sam->kickoff_time); + ldb_msg_add_fmt(ldb, msg, "samba3BadPwdTime", "%d", sam->bad_password_time); + ldb_msg_add_fmt(ldb, msg, "samba3PassLastSetTime", "%d", sam->pass_last_set_time); + ldb_msg_add_fmt(ldb, msg, "samba3PassCanChangeTime", "%d", sam->pass_can_change_time); + ldb_msg_add_fmt(ldb, msg, "samba3PassMustChangeTime", "%d", sam->pass_must_change_time); + ldb_msg_add_fmt(ldb, msg, "samba3Rid", "%d", sam->user_rid); + + /* FIXME: Passwords */ + } + + /* Groups */ + for (i = 0; i < samba3->group.groupmap_count; i++) { + struct samba3_groupmapping *grp = &samba3->group.groupmappings[i]; + + msg = msg_array_add(ldb, msgs, &count); + + if (grp->nt_name != NULL) + msg->dn = ldb_dn_build_child(msg, "cn", grp->nt_name, domaindn); + else + msg->dn = ldb_dn_build_child(msg, "cn", dom_sid_string(msg, grp->sid), domaindn); + + ldb_msg_add_string(ldb, msg, "objectClass", "top"); + ldb_msg_add_string(ldb, msg, "objectClass", "group"); + ldb_msg_add_string(ldb, msg, "description", grp->comment); + ldb_msg_add_string(ldb, msg, "cn", grp->nt_name); + ldb_msg_add_string(ldb, msg, "objectSid", dom_sid_string(msg, grp->sid)); + ldb_msg_add_string(ldb, msg, "unixName", "FIXME"); + ldb_msg_add_fmt(ldb, msg, "samba3SidNameUse", "%d", grp->sid_name_use); + } + + return count; } int samba3_upgrade_winbind(struct samba3 *samba3, struct ldb_context *ldb, struct ldb_message ***msgs) |