From 340b3d7301d81ed46af261d8c948f0e77e052243 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Tue, 19 Jul 2005 03:59:25 +0000 Subject: r8575: the beginnings of a smbstatus command (This used to be commit 4ecaf72a31cde2722315a61cbe823d44f0c14586) --- source4/scripting/bin/smbstatus | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100755 source4/scripting/bin/smbstatus (limited to 'source4/scripting/bin') diff --git a/source4/scripting/bin/smbstatus b/source4/scripting/bin/smbstatus new file mode 100755 index 0000000000..fd3009012b --- /dev/null +++ b/source4/scripting/bin/smbstatus @@ -0,0 +1,26 @@ +#!/bin/sh +exec smbscript "$0" ${1+"$@"} +/* + provide information on connected users and open files + Copyright Andrew Tridgell 2005 + Released under the GNU GPL v2 or later +*/ + +libinclude("base.js"); +libinclude("management.js"); + +var options = new Object(); + +ok = GetOptions(ARGV, options, + "POPT_AUTOHELP", + "POPT_COMMON_SAMBA"); +if (ok == false) { + println("Failed to parse options: " + options.ERROR); + return -1; +} + + +var sessions = smbsrv_sessions(); +printVars(sessions); + +return 0; -- cgit From a32fe0f293fb86d69f3f7001daac2614adfb6b98 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Tue, 19 Jul 2005 04:26:58 +0000 Subject: r8577: added management calls to list current tree connects (This used to be commit 658befc1e4df44bee1f365a730951001f0f36640) --- source4/scripting/bin/smbstatus | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'source4/scripting/bin') diff --git a/source4/scripting/bin/smbstatus b/source4/scripting/bin/smbstatus index fd3009012b..9f7566a642 100755 --- a/source4/scripting/bin/smbstatus +++ b/source4/scripting/bin/smbstatus @@ -21,6 +21,17 @@ if (ok == false) { var sessions = smbsrv_sessions(); +if (sessions == undefined) { + println("No sessions"); + exit(0); +} printVars(sessions); +var trees = smbsrv_trees(); +if (trees == undefined) { + println("No trees"); + exit(0); +} +printVars(trees); + return 0; -- cgit From ef948e53b7a4099663f55a9b1b3a23c6aa100b28 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Tue, 19 Jul 2005 06:08:06 +0000 Subject: r8583: nicer smbstatus output (This used to be commit 0578bcdf7f8919509a78a5c64f94aa5de7e90416) --- source4/scripting/bin/smbstatus | 58 ++++++++++++++++++++++++++++++++--------- 1 file changed, 45 insertions(+), 13 deletions(-) (limited to 'source4/scripting/bin') diff --git a/source4/scripting/bin/smbstatus b/source4/scripting/bin/smbstatus index 9f7566a642..eaf3aa1616 100755 --- a/source4/scripting/bin/smbstatus +++ b/source4/scripting/bin/smbstatus @@ -15,23 +15,55 @@ ok = GetOptions(ARGV, options, "POPT_AUTOHELP", "POPT_COMMON_SAMBA"); if (ok == false) { - println("Failed to parse options: " + options.ERROR); - return -1; + println("Failed to parse options: " + options.ERROR); + return -1; } - -var sessions = smbsrv_sessions(); -if (sessions == undefined) { - println("No sessions"); - exit(0); +/* + show open sessions +*/ +function show_sessions() +{ + var sessions = smbsrv_sessions(); + var i; + var sys = sys_init(); + if (sessions == undefined) { + println("No sessions open"); + return; + } + printf("User Client Connected at\n"); + printf("-------------------------------------------------------------------------------\n"); + for (i=0;i Date: Tue, 19 Jul 2005 06:18:48 +0000 Subject: r8584: added --nbt option to smbstatus for nbt server statistics (This used to be commit 26a676a4e3596d34aee391bf132f2525972c81df) --- source4/scripting/bin/smbstatus | 29 ++++++++++++++++++++++++++--- 1 file changed, 26 insertions(+), 3 deletions(-) (limited to 'source4/scripting/bin') diff --git a/source4/scripting/bin/smbstatus b/source4/scripting/bin/smbstatus index eaf3aa1616..df8864f7e8 100755 --- a/source4/scripting/bin/smbstatus +++ b/source4/scripting/bin/smbstatus @@ -13,7 +13,8 @@ var options = new Object(); ok = GetOptions(ARGV, options, "POPT_AUTOHELP", - "POPT_COMMON_SAMBA"); + "POPT_COMMON_SAMBA", + "nbt"); if (ok == false) { println("Failed to parse options: " + options.ERROR); return -1; @@ -62,8 +63,30 @@ function show_trees() } } +/* + show nbtd information +*/ +function show_nbt() +{ + var stats = nbtd_statistics(); + if (stats == undefined) { + println("nbt server not running"); + return; + } + var r; + println("NBT server statistics:"); + for (r in stats) { + print("\t" + r + ":\t" + stats[r] + "\n"); + } + println(""); +} -show_sessions(); -show_trees(); + +if (options['nbt'] != undefined) { + show_nbt(); +} else { + show_sessions(); + show_trees(); +} return 0; -- cgit From 0e7b9f84ce2dcd5363409acc99a7b887a29be595 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Tue, 19 Jul 2005 09:29:30 +0000 Subject: r8589: - support --version option to smbstatus - print samba version at startup (This used to be commit eb3e4bbe7f4a8f48c9246275ad6ef21ed0b4d357) --- source4/scripting/bin/smbstatus | 2 ++ 1 file changed, 2 insertions(+) (limited to 'source4/scripting/bin') diff --git a/source4/scripting/bin/smbstatus b/source4/scripting/bin/smbstatus index df8864f7e8..7fefae6963 100755 --- a/source4/scripting/bin/smbstatus +++ b/source4/scripting/bin/smbstatus @@ -14,6 +14,7 @@ var options = new Object(); ok = GetOptions(ARGV, options, "POPT_AUTOHELP", "POPT_COMMON_SAMBA", + "POPT_COMMON_VERSION", "nbt"); if (ok == false) { println("Failed to parse options: " + options.ERROR); @@ -81,6 +82,7 @@ function show_nbt() println(""); } +printf("%s\n\n", lpGet("server string")); if (options['nbt'] != undefined) { show_nbt(); -- cgit From 86d628a292a22973597e0c06d4a36e20c58ae31c Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Wed, 20 Jul 2005 07:20:03 +0000 Subject: r8639: moved loadparm calls into an ejs object (This used to be commit 2dc493eea6f9d87c40ad0dc755f528ce0b33ca47) --- source4/scripting/bin/smbstatus | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'source4/scripting/bin') diff --git a/source4/scripting/bin/smbstatus b/source4/scripting/bin/smbstatus index 7fefae6963..38f2ab06a9 100755 --- a/source4/scripting/bin/smbstatus +++ b/source4/scripting/bin/smbstatus @@ -82,7 +82,9 @@ function show_nbt() println(""); } -printf("%s\n\n", lpGet("server string")); +var lp = loadparm_init(); + +printf("%s\n\n", lp.get("server string")); if (options['nbt'] != undefined) { show_nbt(); -- cgit From 80f75d4138029f9d3548c02513aa2484cd400574 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Thu, 18 Aug 2005 05:09:26 +0000 Subject: r9377: made winreg a user tool (I find it quite useful). I expect it to get the ability to add/remove keys and values in the future. add it to the standard tests, ensuring that we know if winreg breaks. This is particularly important as winreg uses such unusual IDL constructs (This used to be commit e4ca36bda34cf5e6fecaef5fe60e5dd397ebee3c) --- source4/scripting/bin/winreg | 75 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 75 insertions(+) create mode 100755 source4/scripting/bin/winreg (limited to 'source4/scripting/bin') diff --git a/source4/scripting/bin/winreg b/source4/scripting/bin/winreg new file mode 100755 index 0000000000..d869d356fd --- /dev/null +++ b/source4/scripting/bin/winreg @@ -0,0 +1,75 @@ +#!/bin/sh +exec smbscript "$0" ${1+"$@"} +/* + tool to manipulate a remote registry + Copyright Andrew Tridgell 2005 + Released under the GNU GPL v2 or later +*/ + +libinclude("base.js"); +libinclude("winreg.js"); + +var options = new Object(); + +ok = GetOptions(ARGV, options, + "POPT_AUTOHELP", + "POPT_COMMON_SAMBA", + "POPT_COMMON_CREDENTIALS"); +if (ok == false) { + println("Failed to parse options: " + options.ERROR); + return -1; +} + +if (options.ARGV.length < 1) { + println("Usage: winreg.js [path]"); + return -1; +} +var binding = options.ARGV[0]; +reg = winreg_init(); +security_init(reg); + +print("Connecting to " + binding + "\n"); +status = reg.connect(binding); +if (status.is_ok != true) { + print("Failed to connect to " + binding + " - " + status.errstr + "\n"); + return -1; +} + +function list_values(path) { + var list = winreg_enum_values(reg, path); + var i; + if (list == undefined) { + return; + } + for (i=0;i 1) { + root = options.ARGV[1]; +} else { + root = ''; +} + +printf("Listing registry tree '%s'\n", root); +list_path(root); +return 0; -- cgit From 55e746ad560d4406821bc2d721cbb929b79a7a0a Mon Sep 17 00:00:00 2001 From: Rafal Szczesniak Date: Mon, 22 Aug 2005 14:32:58 +0000 Subject: r9477: Convert popt options to an ejs object. Doesn't seem to break anything except of popt help (-h) option (unexpected ?). rafal (This used to be commit 1990793b23d6198a85ce1bdf6ad43e12015db203) --- source4/scripting/bin/smbstatus | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'source4/scripting/bin') diff --git a/source4/scripting/bin/smbstatus b/source4/scripting/bin/smbstatus index 38f2ab06a9..d5610023d6 100755 --- a/source4/scripting/bin/smbstatus +++ b/source4/scripting/bin/smbstatus @@ -11,12 +11,12 @@ libinclude("management.js"); var options = new Object(); -ok = GetOptions(ARGV, options, +options = GetOptions(ARGV, "POPT_AUTOHELP", "POPT_COMMON_SAMBA", "POPT_COMMON_VERSION", "nbt"); -if (ok == false) { +if (options == undefined) { println("Failed to parse options: " + options.ERROR); return -1; } -- cgit From fef7a81478cb246a7d2fe29283a50d52501ccc33 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Mon, 22 Aug 2005 23:31:18 +0000 Subject: r9491: fixed up a few scripts that need to be updated for the new GetOptions syntax. Mimir, its a good idea to use grep -r to find places that need fixing when you change the syntax of a call :-) (This used to be commit 1ead49f8e823a69dbd9cd3df3f5be04dc17e0d1f) --- source4/scripting/bin/winreg | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) (limited to 'source4/scripting/bin') diff --git a/source4/scripting/bin/winreg b/source4/scripting/bin/winreg index d869d356fd..7656c8a441 100755 --- a/source4/scripting/bin/winreg +++ b/source4/scripting/bin/winreg @@ -9,14 +9,12 @@ exec smbscript "$0" ${1+"$@"} libinclude("base.js"); libinclude("winreg.js"); -var options = new Object(); - -ok = GetOptions(ARGV, options, - "POPT_AUTOHELP", - "POPT_COMMON_SAMBA", - "POPT_COMMON_CREDENTIALS"); -if (ok == false) { - println("Failed to parse options: " + options.ERROR); +var options = GetOptions(ARGV, + "POPT_AUTOHELP", + "POPT_COMMON_SAMBA", + "POPT_COMMON_CREDENTIALS"); +if (options == undefined) { + println("Failed to parse options"); return -1; } -- cgit From 60eb9f87a0a0c96cf67a33516b34ea8cd14dd5e9 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Tue, 23 Aug 2005 02:00:09 +0000 Subject: r9497: - converted the winreg library to a more OO style of interface - added a reg.typestring() method that returns a string representation of a type (This used to be commit 47cf409cdf501fc3e2b0c65688a9ef1d702278a5) --- source4/scripting/bin/winreg | 25 ++++++++++++++++++++----- 1 file changed, 20 insertions(+), 5 deletions(-) (limited to 'source4/scripting/bin') diff --git a/source4/scripting/bin/winreg b/source4/scripting/bin/winreg index 7656c8a441..7845f1034c 100755 --- a/source4/scripting/bin/winreg +++ b/source4/scripting/bin/winreg @@ -23,8 +23,7 @@ if (options.ARGV.length < 1) { return -1; } var binding = options.ARGV[0]; -reg = winreg_init(); -security_init(reg); +reg = winregObj(); print("Connecting to " + binding + "\n"); status = reg.connect(binding); @@ -34,18 +33,34 @@ if (status.is_ok != true) { } function list_values(path) { - var list = winreg_enum_values(reg, path); + var list = reg.enum_values(path); var i; if (list == undefined) { return; } for (i=0;i Date: Wed, 24 Aug 2005 08:32:51 +0000 Subject: r9568: updated the winreg js library for CreateKey, and add a --createkey option to the winreg tool (This used to be commit 881452c7b7cc00222328f743c2c0c4ece39f4c96) --- source4/scripting/bin/winreg | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) (limited to 'source4/scripting/bin') diff --git a/source4/scripting/bin/winreg b/source4/scripting/bin/winreg index 7845f1034c..12f40f1155 100755 --- a/source4/scripting/bin/winreg +++ b/source4/scripting/bin/winreg @@ -12,7 +12,8 @@ libinclude("winreg.js"); var options = GetOptions(ARGV, "POPT_AUTOHELP", "POPT_COMMON_SAMBA", - "POPT_COMMON_CREDENTIALS"); + "POPT_COMMON_CREDENTIALS", + "createkey=s"); if (options == undefined) { println("Failed to parse options"); return -1; @@ -61,6 +62,10 @@ function list_values(path) { function list_path(path) { var list = reg.enum_path(path); + if (list == undefined) { + println("Unable to list " + path); + return; + } var i; list_values(path); for (i=0;i 1) { root = ''; } -printf("Listing registry tree '%s'\n", root); -list_path(root); +if (options.createkey) { + var ok = reg.create_key("HKLM\\SOFTWARE", options.createkey); + if (!ok) { + + } +} else { + printf("Listing registry tree '%s'\n", root); + list_path(root); +} return 0; -- cgit From 10dcfca9f18648f3fb32f0810d36af4e1eaf76e0 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Wed, 24 Aug 2005 12:19:59 +0000 Subject: r9580: put the libinclude() after the GetOptions so the smb.conf is loaded to get the libjs path (This used to be commit ee0b693ffaf02e75d3d740c36fffb9ea75e54431) --- source4/scripting/bin/winreg | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'source4/scripting/bin') diff --git a/source4/scripting/bin/winreg b/source4/scripting/bin/winreg index 12f40f1155..ac6f9e61ba 100755 --- a/source4/scripting/bin/winreg +++ b/source4/scripting/bin/winreg @@ -6,9 +6,6 @@ exec smbscript "$0" ${1+"$@"} Released under the GNU GPL v2 or later */ -libinclude("base.js"); -libinclude("winreg.js"); - var options = GetOptions(ARGV, "POPT_AUTOHELP", "POPT_COMMON_SAMBA", @@ -19,6 +16,9 @@ if (options == undefined) { return -1; } +libinclude("base.js"); +libinclude("winreg.js"); + if (options.ARGV.length < 1) { println("Usage: winreg.js [path]"); return -1; @@ -91,7 +91,7 @@ if (options.ARGV.length > 1) { if (options.createkey) { var ok = reg.create_key("HKLM\\SOFTWARE", options.createkey); if (!ok) { - + println("Failed to create key"); } } else { printf("Listing registry tree '%s'\n", root); -- cgit From d152839e299e7e406bb938c5b413ad975a895d6f Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Sun, 28 Aug 2005 23:03:49 +0000 Subject: r9722: Initial attempt at converting samba3dump to EJS.. (This used to be commit 7e3b94dfb9c421793dab7813b96ca63da4b33960) --- source4/scripting/bin/samba3dump | 220 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 220 insertions(+) create mode 100644 source4/scripting/bin/samba3dump (limited to 'source4/scripting/bin') diff --git a/source4/scripting/bin/samba3dump b/source4/scripting/bin/samba3dump new file mode 100644 index 0000000000..71937c27c7 --- /dev/null +++ b/source4/scripting/bin/samba3dump @@ -0,0 +1,220 @@ +#!/bin/sh +exec smbscript "$0" ${1+"$@"} +/* + Dump Samba3 data + Copyright Jelmer Vernooij 2005 + Released under the GNU GPL v2 or later +*/ + +options = GetOptions(ARGV, + "POPT_AUTOHELP", + "POPT_COMMON_SAMBA", + "POPT_COMMON_VERSION", + 'format=s', + 'quiet', 'blank'); + +if (options == undefined) { + println("Failed to parse options"); + return -1; +} + +if (options.format == undefined) { + options.format = "summary"; +} + +if (options.format != "summary" && options.format != "full") { + printf("Unknown format %s\n", options.format); + return -1; +} + +libinclude("base.js"); + +if (ARGV.length != 3) { + println("Usage: samba3dump "); + return -1; +} + +function print_header(txt) +{ + printf("\n%s\n", txt); + for (i = 0; txt[i]; i++) putchar('='); + putchar('\n'); +} + +function print_samba3_policy(pol) +{ + print_header("Account Policies"); + printf("Min password length: %d\n", pol.min_password_length); + printf("Password history length: %d\n", pol.password_history); + printf("User must logon to change password: %d\n", pol.user_must_logon_to_change_password); + printf("Maximum password age: %d\n", pol.maximum_password_age); + printf("Minimum password age: %d\n", pol.minimum_password_age); + printf("Lockout duration: %d\n", pol.lockout_duration); + printf("Reset Count Minutes: %d\n", pol.reset_count_minutes); + printf("Bad Lockout Minutes: %d\n", pol.bad_lockout_minutes); + printf("Disconnect Time: %d\n", pol.disconnect_time); + printf("Refuse Machine Password Change: %d\n", pol.refuse_machine_password_change); +} + +function print_samba3_sam(samba3) +{ + print_header("SAM Database"); + + for (i = 0; i < samba3.samaccount_count; i++) { + printf("%d: %s\n", samba3.samaccounts[i].user_rid, samba3.samaccounts[i].username); + } +} + +function print_samba3_shares(samba3) +{ + print_header("Configured shares"); + for (i = 0; i < samba3.share_count; i++) { + printf("--- %s ---\n", samba3.shares[i].name); + + for (j = 0; j < samba3.shares[i].parameter_count; j++) { + printf("\t%s = %s\n", samba3.shares[i].parameters[j].name, samba3.shares[i].parameters[j].value); + } + + println(""); + } +} + +function print_samba3_secrets(secrets) +{ + print_header("Secrets"); + + println("IPC Credentials:"); + if (secrets.ipc_cred.username_obtained) + printf(" User: %s\n", secrets.ipc_cred.username); + if (secrets.ipc_cred.password_obtained) + printf(" Password: %s\n", secrets.ipc_cred.password); + + if (secrets.ipc_cred.domain_obtained) + printf(" Domain: %s\n\n", secrets.ipc_cred.domain); + + println("LDAP passwords:"); + for (i = 0; i < secrets.ldappw_count; i++) { + printf("\t%s -> %s\n", secrets.ldappws[i].dn, secrets.ldappws[i].password); + } + println(""); + + println("Domains:"); + for (i = 0; i < secrets.domain_count; i++) { + printf("\t--- %s ---\n", secrets.domains[i].name); + printf("\tSID: %s\n", secrets.domains[i].sid); + printf("\tGUID: %s\n", secrets.domains[i].guid); + printf("\tPlaintext pwd: %s\n", secrets.domains[i].plaintext_pw); + printf("\tLast Changed: %lu\n", secrets.domains[i].last_change_time); + printf("\tSecure Channel Type: %d\n\n", secrets.domains[i].sec_channel_type); + } + + println("Trusted domains:"); + for (i = 0; i < secrets.trusted_domain_count; i++) { + for (j = 0; j < secrets.trusted_domains[i].uni_name_len; j++) { + printf("\t--- %s ---\n", secrets.trusted_domains[i].uni_name[j]); + } + printf("\tPassword: %s\n", secrets.trusted_domains[i].pass); + printf("\tModified: %lu\n", secrets.trusted_domains[i].mod_time); + printf("\tSID: %s\n", secrets.trusted_domains[i].domain_sid); + } +} + +function print_samba3_regdb(regdb) +{ + print_header("Registry"); + + for (i = 0; i < regdb.key_count; i++) { + printf("%s\n", regdb.keys[i].name); + for (j = 0; j < regdb.keys[i].value_count; j++) { + printf("\t%s: type %d, length %d\n", + regdb.keys[i].values[j].name, + regdb.keys[i].values[j].type, + regdb.keys[i].values[j].data.length); + } + } +} + +function print_samba3_winsdb(samba3) +{ + print_header("WINS Database"); + + for (i = 0; i < samba3.winsdb_count; i++) { + printf("%s, nb_flags: %x, type: %d, ttl: %lu, %d ips\n", samba3.winsdb_entries[i].name, samba3.winsdb_entries[i].nb_flags, samba3.winsdb_entries[i].type, samba3.winsdb_entries[i].ttl, samba3.winsdb_entries[i].ip_count); + } +} + +function print_samba3_groupdb(groupdb) +{ + int i; + print_header("Group Mappings"); + + for (i = 0; i < groupdb.groupmap_count; i++) + { + printf("\t--- Group: %s ---\n", groupdb.groupmappings[i].nt_name); + printf("\tComment: %s\n", groupdb.groupmappings[i].comment); + printf("\tGID: %d\n", groupdb.groupmappings[i].gid); + printf("\tSID Name Use: %d\n", groupdb.groupmappings[i].sid_name_use); + printf("\tSID: %s\n\n", groupdb.groupmappings[i].sid); + } + + for (i = 0; i < groupdb.alias_count; i++) + { + int j; + printf("\t--- Alias: %s ---\n", groupdb.aliases[i].sid); + for (j = 0; j < groupdb.aliases[i].member_count; j++) { + printf("\t%s\n", groupdb.aliases[i].members[j]); + } + } +} + +function print_samba3_idmapdb(idmapdb) +{ + print_header("Winbindd SID<->GID/UID mappings"); + + printf("User High Water Mark: %d\n", idmapdb.user_hwm); + printf("Group High Water Mark: %d\n\n", idmapdb.group_hwm); + + for (i = 0; i < idmapdb.mapping_count; i++) { + printf("%s -> ", + idmapdb.mappings[i].sid); + + if (idmapdb.mappings[i].type == IDMAP_GROUP) { + printf("GID %d", idmapdb.mappings[i].unix_id); + } else { + printf("UID %d", idmapdb.mappings[i].unix_id); + } + } +} + +function print_samba3(samba3) +{ + print_samba3_sam(samba3); + print_samba3_policy(samba3.policy); + print_samba3_shares(samba3); + print_samba3_winsdb(samba3); + print_samba3_regdb(samba3.registry); + print_samba3_secrets(samba3.secrets); + print_samba3_groupdb(samba3.group); + print_samba3_idmapdb(samba3.idmap); +} + +function print_samba3_summary(samba3) +{ + printf("WINS db entries: %d\n", samba3.winsdb_count); + printf("SAM Accounts: %d\n", samba3.samaccount_count); + printf("Registry key count: %d\n", samba3.registry.key_count); + printf("Shares (including [global]): %d\n", samba3.share_count); + printf("Groupmap count: %d\n", samba3.group.groupmap_count); + printf("Alias count: %d\n", samba3.group.alias_count); + printf("Idmap count: %d\n", samba3.idmap.mapping_count); +} + +samba3 = samba3_read(ARGV[1], ARGV[2]); + +if (options.format == "summary") { + print_samba3_summary(samba3); +} else if (options.format == "full") { + print_samba3(samba3); +} + +return 0; -- cgit From 176da2a2813aa00fed8a485548f98e61ffa9350c Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Mon, 29 Aug 2005 00:48:24 +0000 Subject: r9724: Rewrite samba3dump in JS. The summary works now, but the full output is triggering some obscure EJS assert.. (This used to be commit 42605f4444998e3063ffd1bea17425ff825f6132) --- source4/scripting/bin/samba3dump | 125 +++++++++++++++++++-------------------- 1 file changed, 61 insertions(+), 64 deletions(-) (limited to 'source4/scripting/bin') diff --git a/source4/scripting/bin/samba3dump b/source4/scripting/bin/samba3dump index 71937c27c7..059af26e7e 100644 --- a/source4/scripting/bin/samba3dump +++ b/source4/scripting/bin/samba3dump @@ -29,7 +29,7 @@ if (options.format != "summary" && options.format != "full") { libinclude("base.js"); -if (ARGV.length != 3) { +if (options.ARGV.length != 2) { println("Usage: samba3dump "); return -1; } @@ -37,8 +37,7 @@ if (ARGV.length != 3) { function print_header(txt) { printf("\n%s\n", txt); - for (i = 0; txt[i]; i++) putchar('='); - putchar('\n'); + println("=========================================="); } function print_samba3_policy(pol) @@ -60,19 +59,19 @@ function print_samba3_sam(samba3) { print_header("SAM Database"); - for (i = 0; i < samba3.samaccount_count; i++) { - printf("%d: %s\n", samba3.samaccounts[i].user_rid, samba3.samaccounts[i].username); + for (a in samba3.samaccounts) { + printf("%d: %s\n", a.user_rid, a.username); } } function print_samba3_shares(samba3) { print_header("Configured shares"); - for (i = 0; i < samba3.share_count; i++) { - printf("--- %s ---\n", samba3.shares[i].name); + for (s in samba3.shares) { + printf("--- %s ---\n", s.name); - for (j = 0; j < samba3.shares[i].parameter_count; j++) { - printf("\t%s = %s\n", samba3.shares[i].parameters[j].name, samba3.shares[i].parameters[j].value); + for (p in s.parameters) { + printf("\t%s = %s\n", p.name, p.value); } println(""); @@ -85,37 +84,37 @@ function print_samba3_secrets(secrets) println("IPC Credentials:"); if (secrets.ipc_cred.username_obtained) - printf(" User: %s\n", secrets.ipc_cred.username); + printf(" User: %s\n", secrets.ipc_cred.get_username); if (secrets.ipc_cred.password_obtained) - printf(" Password: %s\n", secrets.ipc_cred.password); + printf(" Password: %s\n", secrets.ipc_cred.get_password); if (secrets.ipc_cred.domain_obtained) - printf(" Domain: %s\n\n", secrets.ipc_cred.domain); + printf(" Domain: %s\n\n", secrets.ipc_cred.get_domain); println("LDAP passwords:"); - for (i = 0; i < secrets.ldappw_count; i++) { - printf("\t%s -> %s\n", secrets.ldappws[i].dn, secrets.ldappws[i].password); + for (pw in secrets.ldappws) { + printf("\t%s -> %s\n", pw.dn, pw.password); } println(""); println("Domains:"); - for (i = 0; i < secrets.domain_count; i++) { - printf("\t--- %s ---\n", secrets.domains[i].name); - printf("\tSID: %s\n", secrets.domains[i].sid); - printf("\tGUID: %s\n", secrets.domains[i].guid); - printf("\tPlaintext pwd: %s\n", secrets.domains[i].plaintext_pw); - printf("\tLast Changed: %lu\n", secrets.domains[i].last_change_time); - printf("\tSecure Channel Type: %d\n\n", secrets.domains[i].sec_channel_type); + for (d in secrets.domains) { + printf("\t--- %s ---\n", d.name); + printf("\tSID: %s\n", d.sid); + printf("\tGUID: %s\n", d.guid); + printf("\tPlaintext pwd: %s\n", d.plaintext_pw); + printf("\tLast Changed: %lu\n", d.last_change_time); + printf("\tSecure Channel Type: %d\n\n", d.sec_channel_type); } println("Trusted domains:"); - for (i = 0; i < secrets.trusted_domain_count; i++) { - for (j = 0; j < secrets.trusted_domains[i].uni_name_len; j++) { - printf("\t--- %s ---\n", secrets.trusted_domains[i].uni_name[j]); + for (td in secrets.trusted_domains) { + for (j = 0; j < td.uni_name_len; j++) { + printf("\t--- %s ---\n", td.uni_name[j]); } - printf("\tPassword: %s\n", secrets.trusted_domains[i].pass); - printf("\tModified: %lu\n", secrets.trusted_domains[i].mod_time); - printf("\tSID: %s\n", secrets.trusted_domains[i].domain_sid); + printf("\tPassword: %s\n", td.pass); + printf("\tModified: %lu\n", td.mod_time); + printf("\tSID: %s\n", td.domain_sid); } } @@ -123,13 +122,10 @@ function print_samba3_regdb(regdb) { print_header("Registry"); - for (i = 0; i < regdb.key_count; i++) { - printf("%s\n", regdb.keys[i].name); - for (j = 0; j < regdb.keys[i].value_count; j++) { - printf("\t%s: type %d, length %d\n", - regdb.keys[i].values[j].name, - regdb.keys[i].values[j].type, - regdb.keys[i].values[j].data.length); + for (k in regdb.keys) { + printf("%s\n", k.name); + for (v in k.values) { + printf("\t%s: type %d, length %d\n", v.name, v.type, v.data.length); } } } @@ -138,31 +134,32 @@ function print_samba3_winsdb(samba3) { print_header("WINS Database"); - for (i = 0; i < samba3.winsdb_count; i++) { - printf("%s, nb_flags: %x, type: %d, ttl: %lu, %d ips\n", samba3.winsdb_entries[i].name, samba3.winsdb_entries[i].nb_flags, samba3.winsdb_entries[i].type, samba3.winsdb_entries[i].ttl, samba3.winsdb_entries[i].ip_count); + for (e in samba3.winsentries) { + printf("%s, nb_flags: %x, type: %d, ttl: %lu, %d ips\n", e.name, e.nb_flags, e.type, e.ttl, e.ip_count); } } -function print_samba3_groupdb(groupdb) +function print_samba3_groupmappings(groupdb) { int i; print_header("Group Mappings"); - for (i = 0; i < groupdb.groupmap_count; i++) - { - printf("\t--- Group: %s ---\n", groupdb.groupmappings[i].nt_name); - printf("\tComment: %s\n", groupdb.groupmappings[i].comment); - printf("\tGID: %d\n", groupdb.groupmappings[i].gid); - printf("\tSID Name Use: %d\n", groupdb.groupmappings[i].sid_name_use); - printf("\tSID: %s\n\n", groupdb.groupmappings[i].sid); + for (g in groupdb.groupmappings) { + printf("\t--- Group: %s ---\n", g.nt_name); + printf("\tComment: %s\n", g.comment); + printf("\tGID: %d\n", g.gid); + printf("\tSID Name Use: %d\n", g.sid_name_use); + printf("\tSID: %s\n\n", g.sid); } +} - for (i = 0; i < groupdb.alias_count; i++) - { +function print_samba3_aliases(groupdb) +{ + for (a in groupdb.aliases) { int j; - printf("\t--- Alias: %s ---\n", groupdb.aliases[i].sid); - for (j = 0; j < groupdb.aliases[i].member_count; j++) { - printf("\t%s\n", groupdb.aliases[i].members[j]); + printf("\t--- Alias: %s ---\n", a.sid); + for (j = 0; j < a.member_count; j++) { + printf("\t%s\n", a.members[j]); } } } @@ -174,14 +171,13 @@ function print_samba3_idmapdb(idmapdb) printf("User High Water Mark: %d\n", idmapdb.user_hwm); printf("Group High Water Mark: %d\n\n", idmapdb.group_hwm); - for (i = 0; i < idmapdb.mapping_count; i++) { - printf("%s -> ", - idmapdb.mappings[i].sid); + for (e in idmapdb.mappings) { + printf("%s -> ", e.sid); - if (idmapdb.mappings[i].type == IDMAP_GROUP) { - printf("GID %d", idmapdb.mappings[i].unix_id); + if (e.type == IDMAP_GROUP) { + printf("GID %d", e.unix_id); } else { - printf("UID %d", idmapdb.mappings[i].unix_id); + printf("UID %d", e.unix_id); } } } @@ -194,22 +190,23 @@ function print_samba3(samba3) print_samba3_winsdb(samba3); print_samba3_regdb(samba3.registry); print_samba3_secrets(samba3.secrets); - print_samba3_groupdb(samba3.group); + print_samba3_groupmappings(samba3); + print_samba3_aliases(samba3); print_samba3_idmapdb(samba3.idmap); } function print_samba3_summary(samba3) { - printf("WINS db entries: %d\n", samba3.winsdb_count); - printf("SAM Accounts: %d\n", samba3.samaccount_count); - printf("Registry key count: %d\n", samba3.registry.key_count); - printf("Shares (including [global]): %d\n", samba3.share_count); - printf("Groupmap count: %d\n", samba3.group.groupmap_count); - printf("Alias count: %d\n", samba3.group.alias_count); - printf("Idmap count: %d\n", samba3.idmap.mapping_count); + printf("WINS db entries: %d\n", samba3.winsentries.length); + printf("SAM Accounts: %d\n", samba3.samaccounts.length); + printf("Registry key count: %d\n", samba3.registry.keys.length); + printf("Shares (including [global]): %d\n", samba3.shares.length); + printf("Groupmap count: %d\n", samba3.groupmappings.length); + printf("Alias count: %d\n", samba3.aliases.length); + printf("Idmap count: %d\n", samba3.idmapdb.mappings.length); } -samba3 = samba3_read(ARGV[1], ARGV[2]); +samba3 = samba3_read(options.ARGV[0], options.ARGV[1]); if (options.format == "summary") { print_samba3_summary(samba3); -- cgit From 14ebeffc463426b969acfb611033ff57a18916d6 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Mon, 29 Aug 2005 01:17:20 +0000 Subject: r9725: Fix full output mode of samba3dump as well. Thanks to tridge for a bit for explanation about js. (This used to be commit 765a30a0493cbd150f53335c6648e8e56ef6dc23) --- source4/scripting/bin/samba3dump | 58 ++++++++++++++++++++++++++-------------- 1 file changed, 38 insertions(+), 20 deletions(-) (limited to 'source4/scripting/bin') diff --git a/source4/scripting/bin/samba3dump b/source4/scripting/bin/samba3dump index 059af26e7e..3960962f8b 100644 --- a/source4/scripting/bin/samba3dump +++ b/source4/scripting/bin/samba3dump @@ -57,20 +57,25 @@ function print_samba3_policy(pol) function print_samba3_sam(samba3) { + var i; print_header("SAM Database"); - for (a in samba3.samaccounts) { + for (i in samba3.samaccounts) { + var a = samba3.samaccounts[i]; printf("%d: %s\n", a.user_rid, a.username); } } function print_samba3_shares(samba3) { + var i, j; print_header("Configured shares"); - for (s in samba3.shares) { + for (i in samba3.shares) { + var s = samba3.shares[i]; printf("--- %s ---\n", s.name); - for (p in s.parameters) { + for (j in s.parameters) { + var p = s.parameters[j]; printf("\t%s = %s\n", p.name, p.value); } @@ -80,6 +85,7 @@ function print_samba3_shares(samba3) function print_samba3_secrets(secrets) { + var i; print_header("Secrets"); println("IPC Credentials:"); @@ -92,13 +98,15 @@ function print_samba3_secrets(secrets) printf(" Domain: %s\n\n", secrets.ipc_cred.get_domain); println("LDAP passwords:"); - for (pw in secrets.ldappws) { + for (i in secrets.ldappws) { + var pw = secrets.ldappws[i]; printf("\t%s -> %s\n", pw.dn, pw.password); } println(""); println("Domains:"); - for (d in secrets.domains) { + for (i in secrets.domains) { + var d = secrets.domains[i]; printf("\t--- %s ---\n", d.name); printf("\tSID: %s\n", d.sid); printf("\tGUID: %s\n", d.guid); @@ -108,7 +116,8 @@ function print_samba3_secrets(secrets) } println("Trusted domains:"); - for (td in secrets.trusted_domains) { + for (i in secrets.trusted_domains) { + var td = secrets.trusted_domains[i]; for (j = 0; j < td.uni_name_len; j++) { printf("\t--- %s ---\n", td.uni_name[j]); } @@ -120,11 +129,14 @@ function print_samba3_secrets(secrets) function print_samba3_regdb(regdb) { + var i, j; print_header("Registry"); - for (k in regdb.keys) { + for (i in regdb.keys) { + var k = regdb.keys[i]; printf("%s\n", k.name); - for (v in k.values) { + for (j in k.values) { + var v = k.values[j]; printf("\t%s: type %d, length %d\n", v.name, v.type, v.data.length); } } @@ -132,19 +144,22 @@ function print_samba3_regdb(regdb) function print_samba3_winsdb(samba3) { + var i; print_header("WINS Database"); - for (e in samba3.winsentries) { - printf("%s, nb_flags: %x, type: %d, ttl: %lu, %d ips\n", e.name, e.nb_flags, e.type, e.ttl, e.ip_count); + for (i in samba3.winsentries) { + var e = samba3.winsentries[i]; + printf("%s, nb_flags: %x, type: %d, ttl: %lu, %d ips, fst: %s\n", e.name, e.nb_flags, e.type, e.ttl, e.ips.length, e.ips[0]); } } function print_samba3_groupmappings(groupdb) { - int i; + var i; print_header("Group Mappings"); - for (g in groupdb.groupmappings) { + for (i in groupdb.groupmappings) { + var g = groupdb.groupmappings[i]; printf("\t--- Group: %s ---\n", g.nt_name); printf("\tComment: %s\n", g.comment); printf("\tGID: %d\n", g.gid); @@ -155,10 +170,11 @@ function print_samba3_groupmappings(groupdb) function print_samba3_aliases(groupdb) { - for (a in groupdb.aliases) { - int j; + var i, j; + for (i in groupdb.aliases) { + var a = groupdb.aliases[i]; printf("\t--- Alias: %s ---\n", a.sid); - for (j = 0; j < a.member_count; j++) { + for (j in a.members) { printf("\t%s\n", a.members[j]); } } @@ -166,18 +182,20 @@ function print_samba3_aliases(groupdb) function print_samba3_idmapdb(idmapdb) { + var i; print_header("Winbindd SID<->GID/UID mappings"); printf("User High Water Mark: %d\n", idmapdb.user_hwm); printf("Group High Water Mark: %d\n\n", idmapdb.group_hwm); - for (e in idmapdb.mappings) { + for (i in idmapdb.mappings) { + var e = idmapdb.mappings[i]; printf("%s -> ", e.sid); - if (e.type == IDMAP_GROUP) { - printf("GID %d", e.unix_id); + if (e.type == e.IDMAP_GROUP) { + printf("GID %d\n", e.unix_id); } else { - printf("UID %d", e.unix_id); + printf("UID %d\n", e.unix_id); } } } @@ -192,7 +210,7 @@ function print_samba3(samba3) print_samba3_secrets(samba3.secrets); print_samba3_groupmappings(samba3); print_samba3_aliases(samba3); - print_samba3_idmapdb(samba3.idmap); + print_samba3_idmapdb(samba3.idmapdb); } function print_samba3_summary(samba3) -- cgit From 0549763600b26fadac443555e1cbec5680f91340 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Mon, 29 Aug 2005 12:31:32 +0000 Subject: r9735: More work on generating a valid Samba4 configuration using the Samba3 data (both console and SWAT) (This used to be commit d569465dc4def55c27878028f2fc762960f453d8) --- source4/scripting/bin/samba3dump | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'source4/scripting/bin') diff --git a/source4/scripting/bin/samba3dump b/source4/scripting/bin/samba3dump index 3960962f8b..6b3d999803 100644 --- a/source4/scripting/bin/samba3dump +++ b/source4/scripting/bin/samba3dump @@ -155,10 +155,9 @@ function print_samba3_winsdb(samba3) function print_samba3_groupmappings(groupdb) { - var i; print_header("Group Mappings"); - for (i in groupdb.groupmappings) { + for (var i in groupdb.groupmappings) { var g = groupdb.groupmappings[i]; printf("\t--- Group: %s ---\n", g.nt_name); printf("\tComment: %s\n", g.comment); -- cgit From 783851099b43236666b2fc0cc866834773d6e7b7 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Wed, 2 Nov 2005 01:04:00 +0000 Subject: r11458: fixed our ejs smbscript interfaces to use arrays where appropriate. In js arrays are a special type of object where the length property is automatic, and cannot be modified manually. Our code was manually setting length, which made it abort when someone passed in a real ejs array. To fix this we need to create real arrays instead of objects, and remove the code that manually sets the length (This used to be commit ebdd1393fde44a0a35446d1a922d29a7c1769ba7) --- source4/scripting/bin/winreg | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) (limited to 'source4/scripting/bin') diff --git a/source4/scripting/bin/winreg b/source4/scripting/bin/winreg index ac6f9e61ba..2114394f45 100755 --- a/source4/scripting/bin/winreg +++ b/source4/scripting/bin/winreg @@ -61,13 +61,15 @@ function list_values(path) { } function list_path(path) { + var count = 0; var list = reg.enum_path(path); if (list == undefined) { println("Unable to list " + path); - return; + return 0; } var i; list_values(path); + count = count + list.length; for (i=0;i Date: Fri, 2 Dec 2005 07:02:38 +0000 Subject: r12012: fix renaming smbsrv_trees -> smbsrv_tcons metze (This used to be commit e5654f9791a2786e45108216344b2daea3ad9d91) --- source4/scripting/bin/smbstatus | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'source4/scripting/bin') diff --git a/source4/scripting/bin/smbstatus b/source4/scripting/bin/smbstatus index d5610023d6..ea41289dce 100755 --- a/source4/scripting/bin/smbstatus +++ b/source4/scripting/bin/smbstatus @@ -47,18 +47,18 @@ function show_sessions() /* show open tree connects */ -function show_trees() +function show_tcons() { - var trees = smbsrv_trees(); + var tcons = smbsrv_tcons(); var sys = sys_init(); - if (trees == undefined) { + if (tcons == undefined) { println("No tree connects"); return; } printf("Share Client Connected at\n"); printf("-------------------------------------------------------------------------------\n"); - for (i=0;i Date: Fri, 23 Dec 2005 12:28:26 +0000 Subject: r12445: Fix header in manpage, make script executable (This used to be commit 7ca00cd918760dccc51e56234126ead8535a22ef) --- source4/scripting/bin/samba3dump | 0 1 file changed, 0 insertions(+), 0 deletions(-) mode change 100644 => 100755 source4/scripting/bin/samba3dump (limited to 'source4/scripting/bin') diff --git a/source4/scripting/bin/samba3dump b/source4/scripting/bin/samba3dump old mode 100644 new mode 100755 -- cgit From e5e2b64449a476552bbad49792b13f7501ecdc0c Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Wed, 21 Nov 2007 12:31:43 +0100 Subject: r26079: Some cleanups in the old SWIG wrappers: - remove old torture tests for LDB (replaced by a much more extensive test) - moved tool to bin directory (This used to be commit d6d3b0ad7a789441c82cf30a640033a052921c37) --- source4/scripting/bin/rpcclient | 301 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 301 insertions(+) create mode 100755 source4/scripting/bin/rpcclient (limited to 'source4/scripting/bin') diff --git a/source4/scripting/bin/rpcclient b/source4/scripting/bin/rpcclient new file mode 100755 index 0000000000..34efafdf73 --- /dev/null +++ b/source4/scripting/bin/rpcclient @@ -0,0 +1,301 @@ +#!/usr/bin/python + +import sys, os, string +from cmd import Cmd +from optparse import OptionParser +from pprint import pprint + +import dcerpc, samr + +def swig2dict(obj): + """Convert a swig object to a dictionary.""" + + result = {} + + for attr in filter(lambda x: type(x) == str, dir(obj)): + + if attr[:2] == '__' and attr[-2:] == '__': + continue + + if attr == 'this' or attr == 'thisown': + continue + + result[attr] = getattr(obj, attr) + + return result + +class rpcclient(Cmd): + + prompt = 'rpcclient$ ' + + def __init__(self, server, cred): + Cmd.__init__(self) + self.server = server + self.cred = cred + + def emptyline(self): + + # Default for empty line is to repeat last command - yuck + + pass + + def onecmd(self, line): + + # Override the onecmd() method so we can trap error returns + + try: + Cmd.onecmd(self, line) + except dcerpc.NTSTATUS, arg: + print 'The command returned an error: %s' % arg[1] + + # Command handlers + + def do_help(self, line): + """Displays on-line help for rpcclient commands.""" + Cmd.do_help(self, line) + + def do_shell(self, line): + + status = os.system(line) + + if os.WIFEXITED(status): + if os.WEXITSTATUS(status) != 0: + print 'Command exited with code %d' % os.WEXITSTATUS(status) + else: + print 'Command exited with signal %d' % os.WTERMSIG(status) + + def do_EOF(self, line): + """Exits rpcclient.""" + print + sys.exit(0) + + # SAMR pipe commands + + def do_SamrEnumDomains(self, line): + """Enumerate domain names.""" + + usage = 'usage: SamrEnumDomains' + + if line != '': + print usage + return + + pipe = dcerpc.pipe_connect( + 'ncacn_np:%s' % self.server, + dcerpc.DCERPC_SAMR_UUID, int(dcerpc.DCERPC_SAMR_VERSION), + self.cred) + + connect_handle = samr.Connect(pipe) + + for i in connect_handle.EnumDomains(): + print i + + def do_SamrLookupDomain(self, line): + """Return the SID for a domain.""" + + usage = 'SamrLookupDomain DOMAIN' + + parser = OptionParser(usage) + options, args = parser.parse_args(string.split(line)) + + if len(args) != 1: + print 'usage:', usage + return + + pipe = dcerpc.pipe_connect( + 'ncacn_np:%s' % self.server, + dcerpc.DCERPC_SAMR_UUID, int(dcerpc.DCERPC_SAMR_VERSION), + self.cred) + + connect_handle = samr.Connect(pipe) + + print connect_handle.LookupDomain(args[0]) + + def do_SamrQueryDomInfo(self, line): + """Return information about a domain designated by its SID.""" + + usage = 'SamrQueryDomInfo DOMAIN_SID [info_level]' + + parser = OptionParser(usage) + options, args = parser.parse_args(string.split(line)) + + if (len(args) == 0) or (len(args) > 2): + print 'usage:', usage + return + + pipe = dcerpc.pipe_connect( + 'ncacn_np:%s' % self.server, + dcerpc.DCERPC_SAMR_UUID, int(dcerpc.DCERPC_SAMR_VERSION), + self.cred) + + connect_handle = samr.Connect(pipe) + domain_handle = connect_handle.OpenDomain(args[0]) + + if (len(args) == 2): + result = domain_handle.QueryDomainInfo(int(args[1])) + else: + result = domain_handle.QueryDomainInfo() + + pprint(swig2dict(result)) + + def do_SamrQueryDomInfo2(self, line): + """Return information about a domain designated by its SID. + (Windows 2000 and >)""" + + usage = 'SamrQueryDomInfo2 DOMAIN_SID [info_level] (Windows 2000 and >)' + parser = OptionParser(usage) + options, args = parser.parse_args(string.split(line)) + + if len(args) == 0 or len(args) > 2: + print 'usage:', usage + return + + pipe = dcerpc.pipe_connect( + 'ncacn_np:%s' % self.server, + dcerpc.DCERPC_SAMR_UUID, int(dcerpc.DCERPC_SAMR_VERSION), + self.cred) + + connect_handle = samr.Connect(pipe) + domain_handle = connect_handle.OpenDomain(args[0]) + + if (len(args) == 2): + result = domain_handle.QueryDomainInfo2(int(args[1])) + else: + result = domain_handle.QueryDomainInfo2() + + pprint(swig2dict(result)) + + def do_SamrEnumDomainGroups(self, line): + """Return the list of groups of a domain designated by its SID.""" + + usage = 'SamrEnumDomainGroups DOMAIN_SID' + + parser = OptionParser(usage) + options, args = parser.parse_args(string.split(line)) + + if len(args) != 1: + print 'usage:', usage + return + + pipe = dcerpc.pipe_connect( + 'ncacn_np:%s' % self.server, + dcerpc.DCERPC_SAMR_UUID, int(dcerpc.DCERPC_SAMR_VERSION), + self.cred) + + connect_handle = samr.Connect(pipe) + domain_handle = connect_handle.OpenDomain(args[0]) + + result = domain_handle.EnumDomainGroups() + + pprint(result) + + def do_SamrEnumDomainAliases(self, line): + """Return the list of aliases (local groups) of a domain designated + by its SID.""" + + usage = 'SamrEnumDomainAliases DOMAIN_SID' + + parser = OptionParser(usage) + options, args = parser.parse_args(string.split(line)) + + if len(args) != 1: + print 'usage:', usage + return + + pipe = dcerpc.pipe_connect( + 'ncacn_np:%s' % self.server, + dcerpc.DCERPC_SAMR_UUID, int(dcerpc.DCERPC_SAMR_VERSION), + self.cred) + + connect_handle = samr.Connect(pipe) + domain_handle = connect_handle.OpenDomain(args[0]) + + result = domain_handle.EnumDomainAliases() + + pprint(result) + + def do_SamrEnumDomainUsers(self, line): + """Return the list of users of a domain designated by its SID.""" + + usage = 'SamrEnumDomainUsers DOMAIN_SID [user_account_flags]' + + parser = OptionParser(usage) + options, args = parser.parse_args(string.split(line)) + + if (len(args) == 0) or (len(args) > 2): + print 'usage:', usage + return + + pipe = dcerpc.pipe_connect( + 'ncacn_np:%s' % self.server, + dcerpc.DCERPC_SAMR_UUID, int(dcerpc.DCERPC_SAMR_VERSION), + self.cred) + + connect_handle = samr.Connect(pipe) + domain_handle = connect_handle.OpenDomain(args[0]) + + if (len(args) == 2): + result = domain_handle.EnumDomainUsers(int(args[1])) + else: + result = domain_handle.EnumDomainUsers() + + pprint(result) + +if __name__ == '__main__': + + # Parse command line + + usage = 'rpcclient SERVER [options]' + + if len(sys.argv) == 1: + print usage + sys.exit(1) + + server = sys.argv[1] + del(sys.argv[1]) + + parser = OptionParser(usage) + + parser.add_option('-U', '--username', action='store', type='string', + help='Use given credentials when connecting', + metavar='DOMAIN\\username%password', + dest='username') + + parser.add_option('-c', '--command', action='store', type='string', + help='Execute COMMAND', dest='command') + + options, args = parser.parse_args() + + # Break --username up into domain, username and password + + cred = None + + if not options.username: + options.username = '%' + + domain = '' + if string.find(options.username, '\\') != -1: + domain, options.username = string.split(options.username, '\\') + + password = '' + if string.find(options.username, '%') != -1: + options.username, password = string.split(options.username, '%') + + username = options.username + + if username != '': + cred = (domain, username, password) + + # Run command loop + + c = rpcclient(server, cred) + + if options.command: + c.onecmd(options.command) + sys.exit(0) + + while 1: + try: + c.cmdloop() + except KeyboardInterrupt: + print 'KeyboardInterrupt' -- cgit From 26ae331f75317bfc0a4787d3960a861b25225615 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Thu, 29 Nov 2007 01:36:41 +0100 Subject: r26191: Import custom test runner for subunit, rather than using trial, which is part of twisted. (This used to be commit b0f808345f948c49ad46f34ba306ca8354393850) --- source4/scripting/bin/subunitrun | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100755 source4/scripting/bin/subunitrun (limited to 'source4/scripting/bin') diff --git a/source4/scripting/bin/subunitrun b/source4/scripting/bin/subunitrun new file mode 100755 index 0000000000..add2b91a44 --- /dev/null +++ b/source4/scripting/bin/subunitrun @@ -0,0 +1,25 @@ +#!/usr/bin/python + +# Simple subunit testrunner for python +# Copyright (C) Jelmer Vernooij 2007 +# +# 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 3 of the License, or +# (at your option) any later version. +# +# This program 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 General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . +# + +from subunit import SubunitTestRunner +import sys +from unittest import TestProgram + +program = TestProgram(module=None, argv=sys.argv, testRunner=SubunitTestRunner()) +program.runTests() -- cgit From aa0a06f13c44e0eca0b3f2f0c34f0f7995b87159 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Sun, 23 Dec 2007 19:19:41 -0600 Subject: r26570: - Trim size of the swig-generated Python bindings by removing a bunch of {}'s. - Start working on Python equivalents for various EJS tests. - Fix regression in argument order for reg_diff_apply() in EJS bindings. (This used to be commit c550c03372cb260b78f6a6c132e70571bc4cb852) --- source4/scripting/bin/samba3dump | 387 ++++++++++++++++----------------------- source4/scripting/bin/winreg.py | 93 ++++++++++ 2 files changed, 248 insertions(+), 232 deletions(-) create mode 100644 source4/scripting/bin/winreg.py (limited to 'source4/scripting/bin') diff --git a/source4/scripting/bin/samba3dump b/source4/scripting/bin/samba3dump index 6b3d999803..44ffc6a861 100755 --- a/source4/scripting/bin/samba3dump +++ b/source4/scripting/bin/samba3dump @@ -1,234 +1,157 @@ -#!/bin/sh -exec smbscript "$0" ${1+"$@"} -/* - Dump Samba3 data - Copyright Jelmer Vernooij 2005 - Released under the GNU GPL v2 or later -*/ - -options = GetOptions(ARGV, - "POPT_AUTOHELP", - "POPT_COMMON_SAMBA", - "POPT_COMMON_VERSION", - 'format=s', - 'quiet', 'blank'); - -if (options == undefined) { - println("Failed to parse options"); - return -1; -} - -if (options.format == undefined) { - options.format = "summary"; -} - -if (options.format != "summary" && options.format != "full") { - printf("Unknown format %s\n", options.format); - return -1; -} - -libinclude("base.js"); - -if (options.ARGV.length != 2) { - println("Usage: samba3dump "); - return -1; -} - -function print_header(txt) -{ - printf("\n%s\n", txt); - println("=========================================="); -} - -function print_samba3_policy(pol) -{ - print_header("Account Policies"); - printf("Min password length: %d\n", pol.min_password_length); - printf("Password history length: %d\n", pol.password_history); - printf("User must logon to change password: %d\n", pol.user_must_logon_to_change_password); - printf("Maximum password age: %d\n", pol.maximum_password_age); - printf("Minimum password age: %d\n", pol.minimum_password_age); - printf("Lockout duration: %d\n", pol.lockout_duration); - printf("Reset Count Minutes: %d\n", pol.reset_count_minutes); - printf("Bad Lockout Minutes: %d\n", pol.bad_lockout_minutes); - printf("Disconnect Time: %d\n", pol.disconnect_time); - printf("Refuse Machine Password Change: %d\n", pol.refuse_machine_password_change); -} - -function print_samba3_sam(samba3) -{ - var i; - print_header("SAM Database"); +#!/usr/bin/python +# +# Dump Samba3 data +# Copyright Jelmer Vernooij 2005-2007 +# Released under the GNU GPL v3 or later +# + +import optparse +import os, sys +sys.path.append(os.path.join(os.path.dirname(__file__), "../python")) +import samba +import samba.samba3 + +parser = optparse.OptionParser("provision ") +parser.add_option("--format", type="choice", metavar="FORMAT", + choices=["full", "summary"]) + +opts, args = parser.parse_args() + +if opts.format is None: + opts.format = "summary" + +def print_header(txt): + print "\n%s" % txt + print "==========================================" + +def print_samba3_policy(pol): + print_header("Account Policies") + print "Min password length: %d" % pol.min_password_length + print "Password history length: %d" % pol.password_history + print "User must logon to change password: %d" % pol.user_must_logon_to_change_password + print "Maximum password age: %d" % pol.maximum_password_age + print "Minimum password age: %d" % pol.minimum_password_age + print "Lockout duration: %d" % pol.lockout_duration + print "Reset Count Minutes: %d" % pol.reset_count_minutes + print "Bad Lockout Minutes: %d" % pol.bad_lockout_minutes + print "Disconnect Time: %d" % pol.disconnect_time + print "Refuse Machine Password Change: %d" % pol.refuse_machine_password_change + +def print_samba3_sam(samba3): + print_header("SAM Database") - for (i in samba3.samaccounts) { - var a = samba3.samaccounts[i]; - printf("%d: %s\n", a.user_rid, a.username); - } -} - -function print_samba3_shares(samba3) -{ - var i, j; - print_header("Configured shares"); - for (i in samba3.shares) { - var s = samba3.shares[i]; - printf("--- %s ---\n", s.name); - - for (j in s.parameters) { - var p = s.parameters[j]; - printf("\t%s = %s\n", p.name, p.value); - } - - println(""); - } -} - -function print_samba3_secrets(secrets) -{ - var i; - print_header("Secrets"); - - println("IPC Credentials:"); - if (secrets.ipc_cred.username_obtained) - printf(" User: %s\n", secrets.ipc_cred.get_username); - if (secrets.ipc_cred.password_obtained) - printf(" Password: %s\n", secrets.ipc_cred.get_password); - - if (secrets.ipc_cred.domain_obtained) - printf(" Domain: %s\n\n", secrets.ipc_cred.get_domain); - - println("LDAP passwords:"); - for (i in secrets.ldappws) { - var pw = secrets.ldappws[i]; - printf("\t%s -> %s\n", pw.dn, pw.password); - } - println(""); - - println("Domains:"); - for (i in secrets.domains) { - var d = secrets.domains[i]; - printf("\t--- %s ---\n", d.name); - printf("\tSID: %s\n", d.sid); - printf("\tGUID: %s\n", d.guid); - printf("\tPlaintext pwd: %s\n", d.plaintext_pw); - printf("\tLast Changed: %lu\n", d.last_change_time); - printf("\tSecure Channel Type: %d\n\n", d.sec_channel_type); - } - - println("Trusted domains:"); - for (i in secrets.trusted_domains) { - var td = secrets.trusted_domains[i]; - for (j = 0; j < td.uni_name_len; j++) { - printf("\t--- %s ---\n", td.uni_name[j]); - } - printf("\tPassword: %s\n", td.pass); - printf("\tModified: %lu\n", td.mod_time); - printf("\tSID: %s\n", td.domain_sid); - } -} - -function print_samba3_regdb(regdb) -{ - var i, j; - print_header("Registry"); - - for (i in regdb.keys) { - var k = regdb.keys[i]; - printf("%s\n", k.name); - for (j in k.values) { - var v = k.values[j]; - printf("\t%s: type %d, length %d\n", v.name, v.type, v.data.length); - } - } -} - -function print_samba3_winsdb(samba3) -{ - var i; - print_header("WINS Database"); - - for (i in samba3.winsentries) { - var e = samba3.winsentries[i]; - printf("%s, nb_flags: %x, type: %d, ttl: %lu, %d ips, fst: %s\n", e.name, e.nb_flags, e.type, e.ttl, e.ips.length, e.ips[0]); - } -} - -function print_samba3_groupmappings(groupdb) -{ - print_header("Group Mappings"); + for a in samba3.samaccounts: + print "%d: %s" % a.user_rid, a.username + +def print_samba3_shares(samba3): + print_header("Configured shares") + for s in samba3.shares: + print "--- %s ---" % s.name + + for p in s.parameters: + print "\t%s = %s" % (p.name, p.value) + + print "" + +def print_samba3_secrets(secrets): + print_header("Secrets") + + print "IPC Credentials:" + if secrets.ipc_cred.username_obtained: + print " User: %s\n" % secrets.ipc_cred.get_username + if secrets.ipc_cred.password_obtained: + print " Password: %s\n" % secrets.ipc_cred.get_password + + if secrets.ipc_cred.domain_obtained: + print " Domain: %s\n" % secrets.ipc_cred.get_domain + + print "LDAP passwords:" + for pw in secrets.ldappws: + print "\t%s -> %s" % (pw.dn, pw.password) + print "" + + print "Domains:" + for d in secrets.domains: + print "\t--- %s ---" % d.name + print "\tSID: %s" % d.sid + print "\tGUID: %s" % d.guid + print "\tPlaintext pwd: %s" % d.plaintext_pw + print "\tLast Changed: %lu" % d.last_change_time + print "\tSecure Channel Type: %d\n" % d.sec_channel_type + + print "Trusted domains:" + for td in secrets.trusted_domains: + for n in td.uni_name: + print "\t--- %s ---" % n + print "\tPassword: %s" % td.password + print "\tModified: %lu" % td.mod_time + print "\tSID: %s" % td.domain_sid + +def print_samba3_regdb(regdb): + print_header("Registry") + + for k in regdb.keys: + print "%s\n" % k.name + for v in regdb.values(k): + print "\t%s: type %d, length %d" % (v.name, v.type, v.data.length) + +def print_samba3_winsdb(samba3): + print_header("WINS Database") + + for e in samba3.winsentries: + print "%s, nb_flags: %x, type: %d, ttl: %lu, %d ips, fst: %s" % (e.name, e.nb_flags, e.type, e.ttl, e.ips.length, e.ips[0]) + +def print_samba3_groupmappings(groupdb): + print_header("Group Mappings") - for (var i in groupdb.groupmappings) { - var g = groupdb.groupmappings[i]; - printf("\t--- Group: %s ---\n", g.nt_name); - printf("\tComment: %s\n", g.comment); - printf("\tGID: %d\n", g.gid); - printf("\tSID Name Use: %d\n", g.sid_name_use); - printf("\tSID: %s\n\n", g.sid); - } -} - -function print_samba3_aliases(groupdb) -{ - var i, j; - for (i in groupdb.aliases) { - var a = groupdb.aliases[i]; - printf("\t--- Alias: %s ---\n", a.sid); - for (j in a.members) { - printf("\t%s\n", a.members[j]); - } - } -} - -function print_samba3_idmapdb(idmapdb) -{ - var i; - print_header("Winbindd SID<->GID/UID mappings"); - - printf("User High Water Mark: %d\n", idmapdb.user_hwm); - printf("Group High Water Mark: %d\n\n", idmapdb.group_hwm); - - for (i in idmapdb.mappings) { - var e = idmapdb.mappings[i]; - printf("%s -> ", e.sid); - - if (e.type == e.IDMAP_GROUP) { - printf("GID %d\n", e.unix_id); - } else { - printf("UID %d\n", e.unix_id); - } - } -} - -function print_samba3(samba3) -{ - print_samba3_sam(samba3); - print_samba3_policy(samba3.policy); - print_samba3_shares(samba3); - print_samba3_winsdb(samba3); - print_samba3_regdb(samba3.registry); - print_samba3_secrets(samba3.secrets); - print_samba3_groupmappings(samba3); - print_samba3_aliases(samba3); - print_samba3_idmapdb(samba3.idmapdb); -} - -function print_samba3_summary(samba3) -{ - printf("WINS db entries: %d\n", samba3.winsentries.length); - printf("SAM Accounts: %d\n", samba3.samaccounts.length); - printf("Registry key count: %d\n", samba3.registry.keys.length); - printf("Shares (including [global]): %d\n", samba3.shares.length); - printf("Groupmap count: %d\n", samba3.groupmappings.length); - printf("Alias count: %d\n", samba3.aliases.length); - printf("Idmap count: %d\n", samba3.idmapdb.mappings.length); -} - -samba3 = samba3_read(options.ARGV[0], options.ARGV[1]); - -if (options.format == "summary") { - print_samba3_summary(samba3); -} else if (options.format == "full") { - print_samba3(samba3); -} - -return 0; + for g in groupdb.groupmappings: + print "\t--- Group: %s ---" % g.nt_name + print "\tComment: %s" % g.comment + print "\tGID: %d" % g.gid + print "\tSID Name Use: %d" % g.sid_name_use + print "\tSID: %s\n" % g.sid + +def print_samba3_aliases(groupdb): + for a in groupdb.aliases: + print "\t--- Alias: %s ---" % a.sid + for m in a.members: + print "\t%s" % m + +def print_samba3_idmapdb(idmapdb): + print_header("Winbindd SID<->GID/UID mappings") + + print "User High Water Mark: %d" % idmapdb.user_hwm + print "Group High Water Mark: %d\n" % idmapdb.group_hwm + + for e in idmapdb.mappings: + if e.type == e.IDMAP_GROUP: + print "%s -> GID %d" % (e.sid, e.unix_id) + else: + print "%s -> UID %d" % (e.sid, e.unix_id) + +def print_samba3(samba3): + print_samba3_sam(samba3) + print_samba3_policy(samba3.get_policy_db()) + print_samba3_shares(samba3) + print_samba3_winsdb(samba3.get_wins_db()) + print_samba3_regdb(samba3.get_registry()) + print_samba3_secrets(samba3.get_secrets_db()) + print_samba3_groupmappings(samba3.get_groupmapping_db()) + print_samba3_aliases(samba3) + print_samba3_idmapdb(samba3.get_idmap_db()) + +def print_samba3_summary(samba3): + print "WINS db entries: %d" % len(samba3.winsentries) + print "SAM Accounts: %d" % len(samba3.samaccounts) + print "Registry key count: %d" % len(samba3.registry.keys) + print "Shares (including [global]): %d" % len(samba3.shares) + print "Groupmap count: %d" % len(samba3.groupmappings) + print "Alias count: %d" % len(samba3.aliases) + print "Idmap count: %d" % len(samba3.idmapdb.mappings) + +samba3 = samba.samba3.Samba3(args[0], args[1]) + +if opts.format == "summary": + print_samba3_summary(samba3) +elif opts.format == "full": + print_samba3(samba3) diff --git a/source4/scripting/bin/winreg.py b/source4/scripting/bin/winreg.py new file mode 100644 index 0000000000..6cdc3a5898 --- /dev/null +++ b/source4/scripting/bin/winreg.py @@ -0,0 +1,93 @@ +#!/usr/bin/python +# +# tool to manipulate a remote registry +# Copyright Andrew Tridgell 2005 +# Copyright Jelmer Vernooij 2007 +# Released under the GNU GPL v3 or later +# + +import sys + +options = GetOptions(ARGV, + "POPT_AUTOHELP", + "POPT_COMMON_SAMBA", + "POPT_COMMON_CREDENTIALS", + "createkey=s") +if (options == undefined) { + print "Failed to parse options" + sys.exit(-1) + +if len(sys.argv < 2: + print "Usage: %s [path]" % sys.argv[0] + sys.exit(-1) + +binding = options.ARGV[0] +reg = winregObj() + +print "Connecting to " + binding +status = reg.connect(binding) +if (status.is_ok != true) { + print("Failed to connect to " + binding + " - " + status.errstr + "\n") + return -1 +} + +def list_values(path): + list = reg.enum_values(path) + if (list == undefined) { + return + } + for (i=0;i 2: + root = sys.argv[2] +else: + root = '' + +if options.createkey: + try: + reg.create_key("HKLM\\SOFTWARE", options.createkey) + except: + print "Failed to create key" +else: + printf("Listing registry tree '%s'\n", root) + count = list_path(root) + if count == 0: + println("No entries found") + sys.exit(1) -- cgit From 3c22677a8ce1635d7e055f954153dec4c1796b17 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Mon, 24 Dec 2007 14:16:59 -0600 Subject: r26591: Get the first bits of samba3dump to work again. (This used to be commit 3511027515f8ea860fbe46639d9169999646a297) --- source4/scripting/bin/samba3dump | 123 ++++++++++++++++++++++----------------- 1 file changed, 69 insertions(+), 54 deletions(-) (limited to 'source4/scripting/bin') diff --git a/source4/scripting/bin/samba3dump b/source4/scripting/bin/samba3dump index 44ffc6a861..0aa54d91cc 100755 --- a/source4/scripting/bin/samba3dump +++ b/source4/scripting/bin/samba3dump @@ -11,7 +11,7 @@ sys.path.append(os.path.join(os.path.dirname(__file__), "../python")) import samba import samba.samba3 -parser = optparse.OptionParser("provision ") +parser = optparse.OptionParser("provision []") parser.add_option("--format", type="choice", metavar="FORMAT", choices=["full", "summary"]) @@ -28,14 +28,22 @@ def print_samba3_policy(pol): print_header("Account Policies") print "Min password length: %d" % pol.min_password_length print "Password history length: %d" % pol.password_history - print "User must logon to change password: %d" % pol.user_must_logon_to_change_password - print "Maximum password age: %d" % pol.maximum_password_age - print "Minimum password age: %d" % pol.minimum_password_age - print "Lockout duration: %d" % pol.lockout_duration - print "Reset Count Minutes: %d" % pol.reset_count_minutes - print "Bad Lockout Minutes: %d" % pol.bad_lockout_minutes - print "Disconnect Time: %d" % pol.disconnect_time - print "Refuse Machine Password Change: %d" % pol.refuse_machine_password_change + if pol.user_must_logon_to_change_password: + print "User must logon to change password: %d" % pol.user_must_logon_to_change_password + if pol.maximum_password_age: + print "Maximum password age: %d" % pol.maximum_password_age + if pol.minimum_password_age: + print "Minimum password age: %d" % pol.minimum_password_age + if pol.lockout_duration: + print "Lockout duration: %d" % pol.lockout_duration + if pol.reset_count_minutes: + print "Reset Count Minutes: %d" % pol.reset_count_minutes + if pol.bad_lockout_minutes: + print "Bad Lockout Minutes: %d" % pol.bad_lockout_minutes + if pol.disconnect_time: + print "Disconnect Time: %d" % pol.disconnect_time + if pol.refuse_machine_password_change: + print "Refuse Machine Password Change: %d" % pol.refuse_machine_password_change def print_samba3_sam(samba3): print_header("SAM Database") @@ -56,55 +64,55 @@ def print_samba3_shares(samba3): def print_samba3_secrets(secrets): print_header("Secrets") - print "IPC Credentials:" - if secrets.ipc_cred.username_obtained: - print " User: %s\n" % secrets.ipc_cred.get_username - if secrets.ipc_cred.password_obtained: - print " Password: %s\n" % secrets.ipc_cred.get_password - - if secrets.ipc_cred.domain_obtained: - print " Domain: %s\n" % secrets.ipc_cred.get_domain - - print "LDAP passwords:" - for pw in secrets.ldappws: - print "\t%s -> %s" % (pw.dn, pw.password) - print "" + if secrets.get_auth_user(): + print "IPC Credentials:" + if secrets.get_auth_user(): + print " User: %s\n" % secrets.get_auth_user() + if secrets.get_auth_password(): + print " Password: %s\n" % secrets.get_auth_password() + if secrets.get_auth_domain(): + print " Domain: %s\n" % secrets.get_auth_domain() + + if len(list(secrets.ldap_dns())) > 0: + print "LDAP passwords:" + for dn in secrets.ldap_dns(): + print "\t%s -> %s" % (dn, secrets.get_ldap_bind_pw(dn)) + print "" print "Domains:" - for d in secrets.domains: - print "\t--- %s ---" % d.name - print "\tSID: %s" % d.sid - print "\tGUID: %s" % d.guid - print "\tPlaintext pwd: %s" % d.plaintext_pw - print "\tLast Changed: %lu" % d.last_change_time - print "\tSecure Channel Type: %d\n" % d.sec_channel_type + for domain in secrets.domains(): + print "\t--- %s ---" % domain + print "\tSID: %s" % secrets.get_sid(domain) + print "\tGUID: %s" % secrets.get_dom_guid(domain) + print "\tPlaintext pwd: %s" % secrets.get_machine_password(domain) + if secrets.get_machine_last_change_time(domain): + print "\tLast Changed: %lu" % secrets.get_machine_last_change_time(domain) + if secrets.get_machine_sec_channel_type(domain): + print "\tSecure Channel Type: %d\n" % secrets.get_machine_sec_channel_type(domain) print "Trusted domains:" - for td in secrets.trusted_domains: - for n in td.uni_name: - print "\t--- %s ---" % n - print "\tPassword: %s" % td.password - print "\tModified: %lu" % td.mod_time - print "\tSID: %s" % td.domain_sid + for td in secrets.trusted_domains(): + print td def print_samba3_regdb(regdb): print_header("Registry") - for k in regdb.keys: - print "%s\n" % k.name + for k in regdb.keys(): + print "%s" % k for v in regdb.values(k): print "\t%s: type %d, length %d" % (v.name, v.type, v.data.length) -def print_samba3_winsdb(samba3): +def print_samba3_winsdb(winsdb): print_header("WINS Database") - for e in samba3.winsentries: - print "%s, nb_flags: %x, type: %d, ttl: %lu, %d ips, fst: %s" % (e.name, e.nb_flags, e.type, e.ttl, e.ips.length, e.ips[0]) + for name in winsdb: + (ttl, ips, nb_flags) = winsdb[name] + print "%s, nb_flags: %s, ttl: %lu, %d ips, fst: %s" % (name, nb_flags, ttl, len(ips), ips[0]) def print_samba3_groupmappings(groupdb): print_header("Group Mappings") - for g in groupdb.groupmappings: + for sid in groupdb.groupsids(): print "\t--- Group: %s ---" % g.nt_name print "\tComment: %s" % g.comment print "\tGID: %d" % g.gid @@ -130,26 +138,33 @@ def print_samba3_idmapdb(idmapdb): print "%s -> UID %d" % (e.sid, e.unix_id) def print_samba3(samba3): - print_samba3_sam(samba3) print_samba3_policy(samba3.get_policy_db()) - print_samba3_shares(samba3) print_samba3_winsdb(samba3.get_wins_db()) print_samba3_regdb(samba3.get_registry()) print_samba3_secrets(samba3.get_secrets_db()) - print_samba3_groupmappings(samba3.get_groupmapping_db()) - print_samba3_aliases(samba3) + groupdb = samba3.get_groupmapping_db() + print_samba3_groupmappings(groupdb) + print_samba3_aliases(groupdb) print_samba3_idmapdb(samba3.get_idmap_db()) + print_samba3_shares(samba3) + print_samba3_sam(samba3) def print_samba3_summary(samba3): - print "WINS db entries: %d" % len(samba3.winsentries) - print "SAM Accounts: %d" % len(samba3.samaccounts) - print "Registry key count: %d" % len(samba3.registry.keys) - print "Shares (including [global]): %d" % len(samba3.shares) - print "Groupmap count: %d" % len(samba3.groupmappings) - print "Alias count: %d" % len(samba3.aliases) - print "Idmap count: %d" % len(samba3.idmapdb.mappings) - -samba3 = samba.samba3.Samba3(args[0], args[1]) + print "WINS db entries: %d" % len(samba3.get_wins_db()) + print "Registry key count: %d" % len(samba3.get_registry()) + groupdb = samba3.get_groupmapping_db() + print "Groupmap count: %d" % len(list(groupdb.groupsids())) + print "Alias count: %d" % len(list(groupdb.aliases())) + idmapdb = samba3.get_idmap_db() + print "Idmap count: %d" % (len(list(idmapdb.uids())) + len(list(idmapdb.gids()))) + +libdir = args[0] +if len(args) > 1: + smbconf = args[2] +else: + smbconf = os.path.join(libdir, "smb.conf") + +samba3 = samba.samba3.Samba3(libdir, smbconf) if opts.format == "summary": print_samba3_summary(samba3) -- cgit From cc30cb5e24160d107b67936d71f54645d9b3d23f Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Tue, 25 Dec 2007 16:36:23 -0600 Subject: r26592: Finish fixing the samba3dump script. (This used to be commit 85679f3fc98238f90280f9f10d42550d71eeb918) --- source4/scripting/bin/samba3dump | 240 +++++++++++++++++++-------------------- 1 file changed, 117 insertions(+), 123 deletions(-) (limited to 'source4/scripting/bin') diff --git a/source4/scripting/bin/samba3dump b/source4/scripting/bin/samba3dump index 0aa54d91cc..157a708ff6 100755 --- a/source4/scripting/bin/samba3dump +++ b/source4/scripting/bin/samba3dump @@ -1,8 +1,8 @@ #!/usr/bin/python # -# Dump Samba3 data -# Copyright Jelmer Vernooij 2005-2007 -# Released under the GNU GPL v3 or later +# Dump Samba3 data +# Copyright Jelmer Vernooij 2005-2007 +# Released under the GNU GPL v3 or later # import optparse @@ -13,160 +13,154 @@ import samba.samba3 parser = optparse.OptionParser("provision []") parser.add_option("--format", type="choice", metavar="FORMAT", - choices=["full", "summary"]) + choices=["full", "summary"]) opts, args = parser.parse_args() if opts.format is None: - opts.format = "summary" + opts.format = "summary" def print_header(txt): - print "\n%s" % txt - print "==========================================" + print "\n%s" % txt + print "=" * len(txt) def print_samba3_policy(pol): - print_header("Account Policies") - print "Min password length: %d" % pol.min_password_length - print "Password history length: %d" % pol.password_history - if pol.user_must_logon_to_change_password: - print "User must logon to change password: %d" % pol.user_must_logon_to_change_password - if pol.maximum_password_age: - print "Maximum password age: %d" % pol.maximum_password_age - if pol.minimum_password_age: - print "Minimum password age: %d" % pol.minimum_password_age - if pol.lockout_duration: - print "Lockout duration: %d" % pol.lockout_duration - if pol.reset_count_minutes: - print "Reset Count Minutes: %d" % pol.reset_count_minutes - if pol.bad_lockout_minutes: - print "Bad Lockout Minutes: %d" % pol.bad_lockout_minutes - if pol.disconnect_time: - print "Disconnect Time: %d" % pol.disconnect_time - if pol.refuse_machine_password_change: - print "Refuse Machine Password Change: %d" % pol.refuse_machine_password_change - -def print_samba3_sam(samba3): - print_header("SAM Database") - - for a in samba3.samaccounts: - print "%d: %s" % a.user_rid, a.username - -def print_samba3_shares(samba3): - print_header("Configured shares") - for s in samba3.shares: - print "--- %s ---" % s.name - - for p in s.parameters: - print "\t%s = %s" % (p.name, p.value) - - print "" + print_header("Account Policies") + print "Min password length: %d" % pol.min_password_length + print "Password history length: %d" % pol.password_history + if pol.user_must_logon_to_change_password: + print "User must logon to change password: %d" % pol.user_must_logon_to_change_password + if pol.maximum_password_age: + print "Maximum password age: %d" % pol.maximum_password_age + if pol.minimum_password_age: + print "Minimum password age: %d" % pol.minimum_password_age + if pol.lockout_duration: + print "Lockout duration: %d" % pol.lockout_duration + if pol.reset_count_minutes: + print "Reset Count Minutes: %d" % pol.reset_count_minutes + if pol.bad_lockout_minutes: + print "Bad Lockout Minutes: %d" % pol.bad_lockout_minutes + if pol.disconnect_time: + print "Disconnect Time: %d" % pol.disconnect_time + if pol.refuse_machine_password_change: + print "Refuse Machine Password Change: %d" % pol.refuse_machine_password_change + +def print_samba3_sam(samdb): + print_header("SAM Database") + + for user in samdb: + print "%s" % user + +def print_samba3_shares(shares): + print_header("Configured shares") + for s in shares: + print "--- %s ---" % s.name + + for p in s: + print "\t%s = %s" % (p.key, p.value) + + print "" def print_samba3_secrets(secrets): - print_header("Secrets") - - if secrets.get_auth_user(): - print "IPC Credentials:" - if secrets.get_auth_user(): - print " User: %s\n" % secrets.get_auth_user() - if secrets.get_auth_password(): - print " Password: %s\n" % secrets.get_auth_password() - if secrets.get_auth_domain(): - print " Domain: %s\n" % secrets.get_auth_domain() - - if len(list(secrets.ldap_dns())) > 0: - print "LDAP passwords:" - for dn in secrets.ldap_dns(): - print "\t%s -> %s" % (dn, secrets.get_ldap_bind_pw(dn)) - print "" - - print "Domains:" - for domain in secrets.domains(): - print "\t--- %s ---" % domain - print "\tSID: %s" % secrets.get_sid(domain) - print "\tGUID: %s" % secrets.get_dom_guid(domain) - print "\tPlaintext pwd: %s" % secrets.get_machine_password(domain) - if secrets.get_machine_last_change_time(domain): - print "\tLast Changed: %lu" % secrets.get_machine_last_change_time(domain) - if secrets.get_machine_sec_channel_type(domain): - print "\tSecure Channel Type: %d\n" % secrets.get_machine_sec_channel_type(domain) - - print "Trusted domains:" - for td in secrets.trusted_domains(): - print td + print_header("Secrets") + + if secrets.get_auth_user(): + print "IPC Credentials:" + if secrets.get_auth_user(): + print " User: %s\n" % secrets.get_auth_user() + if secrets.get_auth_password(): + print " Password: %s\n" % secrets.get_auth_password() + if secrets.get_auth_domain(): + print " Domain: %s\n" % secrets.get_auth_domain() + + if len(list(secrets.ldap_dns())) > 0: + print "LDAP passwords:" + for dn in secrets.ldap_dns(): + print "\t%s -> %s" % (dn, secrets.get_ldap_bind_pw(dn)) + print "" + + print "Domains:" + for domain in secrets.domains(): + print "\t--- %s ---" % domain + print "\tSID: %s" % secrets.get_sid(domain) + print "\tGUID: %s" % secrets.get_dom_guid(domain) + print "\tPlaintext pwd: %s" % secrets.get_machine_password(domain) + if secrets.get_machine_last_change_time(domain): + print "\tLast Changed: %lu" % secrets.get_machine_last_change_time(domain) + if secrets.get_machine_sec_channel_type(domain): + print "\tSecure Channel Type: %d\n" % secrets.get_machine_sec_channel_type(domain) + + print "Trusted domains:" + for td in secrets.trusted_domains(): + print td def print_samba3_regdb(regdb): - print_header("Registry") + print_header("Registry") - for k in regdb.keys(): - print "%s" % k - for v in regdb.values(k): - print "\t%s: type %d, length %d" % (v.name, v.type, v.data.length) + for k in regdb.keys(): + print "%s" % k + for v in regdb.values(k): + print "\t%s: type %d, length %d" % (v.name, v.type, v.data.length) def print_samba3_winsdb(winsdb): - print_header("WINS Database") + print_header("WINS Database") - for name in winsdb: - (ttl, ips, nb_flags) = winsdb[name] - print "%s, nb_flags: %s, ttl: %lu, %d ips, fst: %s" % (name, nb_flags, ttl, len(ips), ips[0]) + for name in winsdb: + (ttl, ips, nb_flags) = winsdb[name] + print "%s, nb_flags: %s, ttl: %lu, %d ips, fst: %s" % (name, nb_flags, ttl, len(ips), ips[0]) def print_samba3_groupmappings(groupdb): - print_header("Group Mappings") - - for sid in groupdb.groupsids(): - print "\t--- Group: %s ---" % g.nt_name - print "\tComment: %s" % g.comment - print "\tGID: %d" % g.gid - print "\tSID Name Use: %d" % g.sid_name_use - print "\tSID: %s\n" % g.sid + print_header("Group Mappings") + + for sid in groupdb.groupsids(): + print "\t--- Group: %s ---" % sid def print_samba3_aliases(groupdb): - for a in groupdb.aliases: - print "\t--- Alias: %s ---" % a.sid - for m in a.members: - print "\t%s" % m + for sid in groupdb.aliases(): + print "\t--- Alias: %s ---" % sid def print_samba3_idmapdb(idmapdb): - print_header("Winbindd SID<->GID/UID mappings") + print_header("Winbindd SID<->GID/UID mappings") - print "User High Water Mark: %d" % idmapdb.user_hwm - print "Group High Water Mark: %d\n" % idmapdb.group_hwm + print "User High Water Mark: %d" % idmapdb.get_user_hwm() + print "Group High Water Mark: %d\n" % idmapdb.get_group_hwm() - for e in idmapdb.mappings: - if e.type == e.IDMAP_GROUP: - print "%s -> GID %d" % (e.sid, e.unix_id) - else: - print "%s -> UID %d" % (e.sid, e.unix_id) + for uid in idmapdb.uids(): + print "%s -> UID %d" % (idmapdb.get_user_sid(uid), uid) + + for gid in idmapdb.gids(): + print "%s -> GID %d" % (idmapdb.get_group_sid(gid), gid) def print_samba3(samba3): - print_samba3_policy(samba3.get_policy_db()) - print_samba3_winsdb(samba3.get_wins_db()) - print_samba3_regdb(samba3.get_registry()) - print_samba3_secrets(samba3.get_secrets_db()) - groupdb = samba3.get_groupmapping_db() - print_samba3_groupmappings(groupdb) - print_samba3_aliases(groupdb) - print_samba3_idmapdb(samba3.get_idmap_db()) - print_samba3_shares(samba3) - print_samba3_sam(samba3) + print_samba3_policy(samba3.get_policy_db()) + print_samba3_winsdb(samba3.get_wins_db()) + print_samba3_regdb(samba3.get_registry()) + print_samba3_secrets(samba3.get_secrets_db()) + print_samba3_idmapdb(samba3.get_idmap_db()) + print_samba3_sam(samba3.get_sam_db()) + groupdb = samba3.get_groupmapping_db() + print_samba3_groupmappings(groupdb) + print_samba3_aliases(groupdb) + print_samba3_shares(samba3.get_shares()) def print_samba3_summary(samba3): - print "WINS db entries: %d" % len(samba3.get_wins_db()) - print "Registry key count: %d" % len(samba3.get_registry()) - groupdb = samba3.get_groupmapping_db() - print "Groupmap count: %d" % len(list(groupdb.groupsids())) - print "Alias count: %d" % len(list(groupdb.aliases())) - idmapdb = samba3.get_idmap_db() - print "Idmap count: %d" % (len(list(idmapdb.uids())) + len(list(idmapdb.gids()))) + print "WINS db entries: %d" % len(samba3.get_wins_db()) + print "Registry key count: %d" % len(samba3.get_registry()) + groupdb = samba3.get_groupmapping_db() + print "Groupmap count: %d" % len(list(groupdb.groupsids())) + print "Alias count: %d" % len(list(groupdb.aliases())) + idmapdb = samba3.get_idmap_db() + print "Idmap count: %d" % (len(list(idmapdb.uids())) + len(list(idmapdb.gids()))) libdir = args[0] if len(args) > 1: - smbconf = args[2] + smbconf = args[2] else: - smbconf = os.path.join(libdir, "smb.conf") + smbconf = os.path.join(libdir, "smb.conf") samba3 = samba.samba3.Samba3(libdir, smbconf) if opts.format == "summary": - print_samba3_summary(samba3) + print_samba3_summary(samba3) elif opts.format == "full": - print_samba3(samba3) + print_samba3(samba3) -- cgit From 7c146c42d2cf51e891b9f29d3b61a40f173a3b23 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Tue, 25 Dec 2007 16:36:31 -0600 Subject: r26593: - More work on the python versions of samba3dump and the samba3sam tests. - Initial work converting the upgrade code to Python. - Removed the old EJS upgrade code because it has been broken for a long time. (This used to be commit 150cf39fbd4fe088546870fb0d8f20c0d9eb4aca) --- source4/scripting/bin/samba3dump | 3 --- 1 file changed, 3 deletions(-) (limited to 'source4/scripting/bin') diff --git a/source4/scripting/bin/samba3dump b/source4/scripting/bin/samba3dump index 157a708ff6..f8d10cbc71 100755 --- a/source4/scripting/bin/samba3dump +++ b/source4/scripting/bin/samba3dump @@ -47,7 +47,6 @@ def print_samba3_policy(pol): def print_samba3_sam(samdb): print_header("SAM Database") - for user in samdb: print "%s" % user @@ -55,10 +54,8 @@ def print_samba3_shares(shares): print_header("Configured shares") for s in shares: print "--- %s ---" % s.name - for p in s: print "\t%s = %s" % (p.key, p.value) - print "" def print_samba3_secrets(secrets): -- cgit From 43a03b0fb48ceb528539a16b0023fb5b30b7a79e Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Tue, 25 Dec 2007 16:36:53 -0600 Subject: r26598: Simplify the way Python tests are run. (This used to be commit d649f73431fc993e31522e7fc8e1e35e0a4421d8) --- source4/scripting/bin/subunitrun | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'source4/scripting/bin') diff --git a/source4/scripting/bin/subunitrun b/source4/scripting/bin/subunitrun index add2b91a44..7142abed85 100755 --- a/source4/scripting/bin/subunitrun +++ b/source4/scripting/bin/subunitrun @@ -21,5 +21,6 @@ from subunit import SubunitTestRunner import sys from unittest import TestProgram -program = TestProgram(module=None, argv=sys.argv, testRunner=SubunitTestRunner()) +program = TestProgram(module=None, argv=sys.argv, + testRunner=SubunitTestRunner()) program.runTests() -- cgit From c4d3666ac2821518be57ca89d963f77bbddaedf4 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Wed, 26 Dec 2007 20:55:05 -0600 Subject: r26607: Fix reading of values and subkeys in Samba 3 registry files. (This used to be commit e3d7454ef70d6fe9a1ce34eaf57268bd5b713ccf) --- source4/scripting/bin/samba3dump | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) (limited to 'source4/scripting/bin') diff --git a/source4/scripting/bin/samba3dump b/source4/scripting/bin/samba3dump index f8d10cbc71..8f56d423d8 100755 --- a/source4/scripting/bin/samba3dump +++ b/source4/scripting/bin/samba3dump @@ -80,7 +80,7 @@ def print_samba3_secrets(secrets): for domain in secrets.domains(): print "\t--- %s ---" % domain print "\tSID: %s" % secrets.get_sid(domain) - print "\tGUID: %s" % secrets.get_dom_guid(domain) + print "\tGUID: %s" % secrets.get_domain_guid(domain) print "\tPlaintext pwd: %s" % secrets.get_machine_password(domain) if secrets.get_machine_last_change_time(domain): print "\tLast Changed: %lu" % secrets.get_machine_last_change_time(domain) @@ -93,11 +93,12 @@ def print_samba3_secrets(secrets): def print_samba3_regdb(regdb): print_header("Registry") + from registry import str_regtype for k in regdb.keys(): - print "%s" % k - for v in regdb.values(k): - print "\t%s: type %d, length %d" % (v.name, v.type, v.data.length) + print "[%s]" % k + for (value_name, (type, value)) in regdb.values(k).items(): + print "\"%s\"=%s:%s" % (value_name, str_regtype(type), value) def print_samba3_winsdb(winsdb): print_header("WINS Database") @@ -151,7 +152,7 @@ def print_samba3_summary(samba3): libdir = args[0] if len(args) > 1: - smbconf = args[2] + smbconf = args[1] else: smbconf = os.path.join(libdir, "smb.conf") -- cgit From 2ebe80c27c8cd39a0f40ef6de3a9f805cb7d6bed Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Mon, 14 Jan 2008 19:51:08 +0100 Subject: python: Convert winreg.py completely to rpc, use new RPC Python bindings. (This used to be commit 9c21773737ea941b623105352b4625dcb8437706) --- source4/scripting/bin/winreg.py | 133 ++++++++++++++++++---------------------- 1 file changed, 61 insertions(+), 72 deletions(-) mode change 100644 => 100755 source4/scripting/bin/winreg.py (limited to 'source4/scripting/bin') diff --git a/source4/scripting/bin/winreg.py b/source4/scripting/bin/winreg.py old mode 100644 new mode 100755 index 6cdc3a5898..f68f2d12f2 --- a/source4/scripting/bin/winreg.py +++ b/source4/scripting/bin/winreg.py @@ -7,87 +7,76 @@ # import sys +import winreg +import optparse +import samba.getopt as options -options = GetOptions(ARGV, - "POPT_AUTOHELP", - "POPT_COMMON_SAMBA", - "POPT_COMMON_CREDENTIALS", - "createkey=s") -if (options == undefined) { - print "Failed to parse options" - sys.exit(-1) +parser = optparse.OptionParser("%s [path]" % sys.argv[0]) +parser.add_option_group(options.SambaOptions(parser)) +parser.add_option("--createkey", type="string", metavar="KEYNAME", + help="create a key") -if len(sys.argv < 2: - print "Usage: %s [path]" % sys.argv[0] - sys.exit(-1) +opts, args = parser.parse_args() -binding = options.ARGV[0] -reg = winregObj() +if len(args) < 1: + parser.print_usage() + sys.exit(-1) + +binding = args[0] print "Connecting to " + binding -status = reg.connect(binding) -if (status.is_ok != true) { - print("Failed to connect to " + binding + " - " + status.errstr + "\n") - return -1 -} +conn = winreg.winreg(binding, opts.configfile) -def list_values(path): - list = reg.enum_values(path) - if (list == undefined) { - return - } - for (i=0;i 2: - root = sys.argv[2] +if len(args) > 1: + root = args[1] else: - root = '' + root = "HKLM" -if options.createkey: - try: - reg.create_key("HKLM\\SOFTWARE", options.createkey) - except: - print "Failed to create key" +if opts.createkey: + reg.create_key("HKLM\\SOFTWARE", opt.createkey) else: - printf("Listing registry tree '%s'\n", root) - count = list_path(root) + print "Listing registry tree '%s'" % root + try: + root_key = getattr(conn, "Open%s" % root)(None, winreg.KEY_QUERY_VALUE | winreg.KEY_ENUMERATE_SUB_KEYS) + except AttributeError: + print "Unknown root key name %s" % root + sys.exit(1) + count = list_path(root_key, root) if count == 0: - println("No entries found") - sys.exit(1) + print "No entries found" + sys.exit(1) -- cgit From d869de531c9f6b81c7eca43c3bfaab294c14cab1 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Mon, 14 Jan 2008 20:14:53 +0100 Subject: python: Enable building of the wkssvc python bindings. (This used to be commit 7a00d48a478be84e9f38c5e6cb57739063d0d613) --- source4/scripting/bin/epdump.py | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 source4/scripting/bin/epdump.py (limited to 'source4/scripting/bin') diff --git a/source4/scripting/bin/epdump.py b/source4/scripting/bin/epdump.py new file mode 100644 index 0000000000..15dee33774 --- /dev/null +++ b/source4/scripting/bin/epdump.py @@ -0,0 +1,24 @@ +#!/usr/bin/python + +# Unix SMB/CIFS implementation. +# Copyright (C) Jelmer Vernooij 2008 +# +# 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 3 of the License, or +# (at your option) any later version. +# +# This program 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 General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . +# + +import sys + +if len(sys.argv) < 2: + print "Usage: %s " % sys.argv[0] + sys.exit(1) -- cgit From decdf5954d5e1ae84318d6767317965f544a897f Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Wed, 23 Jan 2008 23:33:36 +0100 Subject: python: Add convenience function for getting command line loadparm context and default to using system smb.conf. (This used to be commit b3afde0f00ab5093b577b139a062c233d4db2524) --- source4/scripting/bin/winreg.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'source4/scripting/bin') diff --git a/source4/scripting/bin/winreg.py b/source4/scripting/bin/winreg.py index f68f2d12f2..1e39ee8f78 100755 --- a/source4/scripting/bin/winreg.py +++ b/source4/scripting/bin/winreg.py @@ -12,7 +12,8 @@ import optparse import samba.getopt as options parser = optparse.OptionParser("%s [path]" % sys.argv[0]) -parser.add_option_group(options.SambaOptions(parser)) +sambaopts = options.SambaOptions(parser) +parser.add_option_group(sambaopts) parser.add_option("--createkey", type="string", metavar="KEYNAME", help="create a key") @@ -25,7 +26,7 @@ if len(args) < 1: binding = args[0] print "Connecting to " + binding -conn = winreg.winreg(binding, opts.configfile) +conn = winreg.winreg(binding, sambaopts.get_loadparm()) def list_values(key): (num_values, max_valnamelen, max_valbufsize) = conn.QueryInfoKey(key, winreg.String())[4:8] -- cgit From f75d6241291eaa079d01e658efd7d00a60584830 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Sun, 10 Feb 2008 00:21:41 +0100 Subject: Start working on python conversion of minschema. (This used to be commit 239a1616644321e2d1e64985ea3f3c4971997228) --- source4/scripting/bin/minschema.py | 660 +++++++++++++++++++++++++++++++++++++ 1 file changed, 660 insertions(+) create mode 100755 source4/scripting/bin/minschema.py (limited to 'source4/scripting/bin') diff --git a/source4/scripting/bin/minschema.py b/source4/scripting/bin/minschema.py new file mode 100755 index 0000000000..0a16cc9886 --- /dev/null +++ b/source4/scripting/bin/minschema.py @@ -0,0 +1,660 @@ +#!/usr/bin/python +# +# work out the minimal schema for a set of objectclasses +# + +import getopt +import optparse +import samba + +parser = optparse.OptionParser("minschema ") +sambaopts = options.SambaOptions(parser) +parser.add_option_group(sambaopts) +credopts = options.CredentialsOptions(parser) +parser.add_option_group(credopts) +parser.add_option_group(options.VersionOptions(parser)) +parser.add_option("--verbose", help="Be verbose", action="store_true") +parser.add_option("--dump-classes", action="store_true") +parser.add_option("--dump-attributes", action="store_true") +parser.add_option("--dump-subschema", action="store_true") +parser.add_option("--dump-subschema-auto", action="store_true") + +opts, args = parser.parse_args() +opts.dump_all = True + +if opts.dump_classes: + opts.dump_all = False +if opts.dump_attributes: + opts.dump_all = False +if opts.dump_subschema: + opts.dump_all = False +if dump_subschema_auto: + opts.dump_all = False + opts.dump_subschema = True +if opts.dump_all: + opts.dump_classes = True + opts.dump_attributes = True + opts.dump_subschema = True + opts.dump_subschema_auto = True + +if len(args) != 2: + parser.print_usage() + sys.exit(1) + +(url, classfile) = args + +creds = credopts.get_credentials() +ldb = Ldb(url, credentials=creds) + +objectclasses = [] +attributes = [] +rootDse = {} + +objectclasses_expanded = [] + +# the attributes we need for objectclasses +class_attrs = ["objectClass", + "subClassOf", + "governsID", + "possSuperiors", + "possibleInferiors", + "mayContain", + "mustContain", + "auxiliaryClass", + "rDNAttID", + "showInAdvancedViewOnly", + "adminDisplayName", + "adminDescription", + "objectClassCategory", + "lDAPDisplayName", + "schemaIDGUID", + "systemOnly", + "systemPossSuperiors", + "systemMayContain", + "systemMustContain", + "systemAuxiliaryClass", + "defaultSecurityDescriptor", + "systemFlags", + "defaultHidingValue", + "objectCategory", + "defaultObjectCategory", + + # this attributes are not used by w2k3 + "schemaFlagsEx", + "msDs-IntId", + "msDs-Schema-Extensions", + "classDisplayName", + "isDefunct"] + +attrib_attrs = ["objectClass", + "attributeID", + "attributeSyntax", + "isSingleValued", + "rangeLower", + "rangeUpper", + "mAPIID", + "linkID", + "showInAdvancedViewOnly", + "adminDisplayName", + "oMObjectClass", + "adminDescription", + "oMSyntax", + "searchFlags", + "extendedCharsAllowed", + "lDAPDisplayName", + "schemaIDGUID", + "attributeSecurityGUID", + "systemOnly", + "systemFlags", + "isMemberOfPartialAttributeSet", + "objectCategory", + + # this attributes are not used by w2k3 + "schemaFlagsEx", + "msDs-IntId", + "msDs-Schema-Extensions", + "classDisplayName", + "isEphemeral", + "isDefunct"] + +# +# notes: +# +# objectClassCategory +# 1: structural +# 2: abstract +# 3: auxiliary + +# +# print only if verbose is set +# +def dprintf(text): + if verbose is not None: + print text + +def get_object_cn(ldb, name): + attrs = ["cn"] + + res = ldb.search("(ldapDisplayName=%s)" % name, rootDse.schemaNamingContext, ldb.SCOPE_SUBTREE, attrs) + assert len(res) == 1 + + cn = res[0]["cn"] + +# +# create an objectclass object +# +def obj_objectClass(ldb, name): + var o = new Object() + o.name = name + o.cn = get_object_cn(ldb, name) + return o + +# +# create an attribute object +# +def obj_attribute(ldb, name): + var o = new Object() + o.name = name + o.cn = get_object_cn(ldb, name) + return o + + +syntaxmap = dict() + +syntaxmap['2.5.5.1'] = '1.3.6.1.4.1.1466.115.121.1.12' +syntaxmap['2.5.5.2'] = '1.3.6.1.4.1.1466.115.121.1.38' +syntaxmap['2.5.5.3'] = '1.2.840.113556.1.4.1362' +syntaxmap['2.5.5.4'] = '1.2.840.113556.1.4.905' +syntaxmap['2.5.5.5'] = '1.3.6.1.4.1.1466.115.121.1.26' +syntaxmap['2.5.5.6'] = '1.3.6.1.4.1.1466.115.121.1.36' +syntaxmap['2.5.5.7'] = '1.2.840.113556.1.4.903' +syntaxmap['2.5.5.8'] = '1.3.6.1.4.1.1466.115.121.1.7' +syntaxmap['2.5.5.9'] = '1.3.6.1.4.1.1466.115.121.1.27' +syntaxmap['2.5.5.10'] = '1.3.6.1.4.1.1466.115.121.1.40' +syntaxmap['2.5.5.11'] = '1.3.6.1.4.1.1466.115.121.1.24' +syntaxmap['2.5.5.12'] = '1.3.6.1.4.1.1466.115.121.1.15' +syntaxmap['2.5.5.13'] = '1.3.6.1.4.1.1466.115.121.1.43' +syntaxmap['2.5.5.14'] = '1.2.840.113556.1.4.904' +syntaxmap['2.5.5.15'] = '1.2.840.113556.1.4.907' +syntaxmap['2.5.5.16'] = '1.2.840.113556.1.4.906' +syntaxmap['2.5.5.17'] = '1.3.6.1.4.1.1466.115.121.1.40' + +# +# map some attribute syntaxes from some apparently MS specific +# syntaxes to the standard syntaxes +# +def map_attribute_syntax(s): + if syntaxmap.has_key(s): + return syntaxmap[s] + return s + +# +# fix a string DN to use ${SCHEMADN} +# +def fix_dn(dn): + s = strstr(dn, rootDse.schemaNamingContext) + if (s == NULL) { + return dn + } + return substr(dn, 0, strlen(dn) - strlen(s)) + "${SCHEMADN}" + +# +# dump an object as ldif +# +def write_ldif_one(o, attrs): + print "dn: CN=%s,${SCHEMADN}\n" % o["cn"] + for a in attrs: + if not o.has_key(a): + continue + # special case for oMObjectClass, which is a binary object + if a == "oMObjectClass": + print "%s:: %s\n" % (a, o[a]) + continue + v = o[a] + if isinstance(v, str): + v = [v] + for j in v: + print "%s: %s\n" % (a, fix_dn(j)) + print "\n" + +# +# dump an array of objects as ldif +# +def write_ldif(o, attrs): + for i in o: + write_ldif_one(i, attrs) + + +# +# create a testDN based an an example DN +# the idea is to ensure we obey any structural rules +# +def create_testdn(exampleDN): + a = split(",", exampleDN) + a[0] = "CN=TestDN" + return ",".join(a) + +# +# find the properties of an objectclass +# +def find_objectclass_properties(ldb, o): + res = ldb.search( + expression="(ldapDisplayName=%s)" % o.name, + rootDse.schemaNamingContext, ldb.SCOPE_SUBTREE, class_attrs) + assert(len(res) == 1) + msg = res[0] + for a in msg: + o[a] = msg[a] + +# +# find the properties of an attribute +# +def find_attribute_properties(ldb, o): + res = ldb.search( + expression="(ldapDisplayName=%s)" % o.name, + rootDse.schemaNamingContext, ldb.SCOPE_SUBTREE, attrib_attrs) + assert(len(res) == 1) + msg = res[0] + for a in msg: + # special case for oMObjectClass, which is a binary object + if a == "oMObjectClass": + o[a] = ldb.encode(msg[a]) + continue + o[a] = msg[a] + +# +# find the auto-created properties of an objectclass. Only works for classes +# that can be created using just a DN and the objectclass +# +def find_objectclass_auto(ldb, o): + if not o.has_key("exampleDN"): + return + testdn = create_testdn(o.exampleDN) + + print "testdn is '%s'\n" % testdn + + ldif = "dn: " + testdn + ldif += "\nobjectClass: " + o.name + try: + ldb.add(ldif) + except LdbError, e: + print "error adding %s: %s\n" % (o.name, e) + print "%s\n" % ldif + return + + res = ldb.search("", testdn, ldb.SCOPE_BASE) + ldb.delete(testdn) + + for a in res.msgs[0]: + attributes[a].autocreate = True + + +# +# look at auxiliary information from a class to intuit the existance of more +# classes needed for a minimal schema +# +def expand_objectclass(ldb, o): + attrs = ["auxiliaryClass", "systemAuxiliaryClass", + "possSuperiors", "systemPossSuperiors", + "subClassOf"] + res = ldb.search( + "(&(objectClass=classSchema)(ldapDisplayName=%s))" % o.name, + rootDse.schemaNamingContext, ldb.SCOPE_SUBTREE, attrs) + print "Expanding class %s\n" % o.name + assert(len(res) == 1) + msg = res[0] + for a in attrs: + if not msg.has_key(aname): + continue + list = msg[aname] + if isinstance(list, str): + list = [msg[aname]] + for name in list: + if not objectclasses.has_key(name): + print "Found new objectclass '%s'\n" % name + objectclasses[name] = obj_objectClass(ldb, name) + + +# +# add the must and may attributes from an objectclass to the full list +# of attributes +# +def add_objectclass_attributes(ldb, class): + attrs = ["mustContain", "systemMustContain", + "mayContain", "systemMayContain"] + for aname in attrs: + if not class.has_key(aname): + continue + alist = class[aname] + if isinstance(alist, str): + alist = [alist] + for a in alist: + if not attributes.has_key(a): + attributes[a] = obj_attribute(ldb, a) + + +# +# process an individual record, working out what attributes it has +# +def walk_dn(ldb, dn): + # get a list of all possible attributes for this object + attrs = ["allowedAttributes"] + try: + res = ldb.search("objectClass=*", dn, ldb.SCOPE_BASE, attrs) + except LdbError, e: + print "Unable to fetch allowedAttributes for '%s' - %r\n" % (dn, e) + return + allattrs = res[0]["allowedAttributes"] + try: + res = ldb.search("objectClass=*", dn, ldb.SCOPE_BASE, allattrs) + except LdbError, e: + print "Unable to fetch all attributes for '%s' - %s\n" % (dn, e) + return + msg = res[0] + for a in msg: + if not attributes.has_key(a): + attributes[a] = obj_attribute(ldb, a) + +# +# walk a naming context, looking for all records +# +def walk_naming_context(ldb, namingContext): + try: + res = ldb.search("objectClass=*", namingContext, ldb.SCOPE_DEFAULT, + ["objectClass"]) + except LdbError, e: + print "Unable to fetch objectClasses for '%s' - %s\n" % (namingContext, e) + return + for msg in res: + msg = res.msgs[r]["objectClass"] + for objectClass in msg: + if not objectclasses.has_key(objectClass): + objectclasses[objectClass] = obj_objectClass(ldb, objectClass) + objectclasses[objectClass].exampleDN = res.msgs[r]["dn"] + walk_dn(ldb, res.msgs[r].dn) + +# +# trim the may attributes for an objectClass +# +def trim_objectclass_attributes(ldb, class): + # trim possibleInferiors, + # include only the classes we extracted + if class.has_key("possibleInferiors"): + possinf = class["possibleInferiors"] + newpossinf = [] + if isinstance(possinf, str): + possinf = [possinf] + for x in possinf: + if objectclasses.has_key(x): + newpossinf[n] = x + n++ + class["possibleInferiors"] = newpossinf + + # trim systemMayContain, + # remove duplicates + if class.has_key("systemMayContain"): + sysmay = class["systemMayContain"] + newsysmay = [] + if isinstance(sysmay, str): + sysmay = [sysmay] + for x in sysmay: + dup = False + if newsysmay[0] == undefined) { + newsysmay[0] = x + else: + for (n = 0; n < newsysmay.length; n++) { + if (newsysmay[n] == x) { + dup = True + if not dup: + newsysmay[n] = x + class["systemMayContain"] = newsysmay + + # trim mayContain, + # remove duplicates + if not class.has_key("mayContain"): + may = class["mayContain"] + newmay = [] + if isinstance(may, str): + may = [may] + for x in may: + dup = False + if (newmay[0] == undefined) { + newmay[0] = x + } else { + for (n = 0; n < newmay.length; n++) { + if (newmay[n] == x) { + dup = True + if not dup: + newmay[n] = x + class["mayContain"] = newmay + +# +# load the basic attributes of an objectClass +# +def build_objectclass(ldb, name): + attrs = ["name"] + try: + res = ldb.search( + expression="(&(objectClass=classSchema)(ldapDisplayName=%s))" % name, + rootDse.schemaNamingContext, ldb.SCOPE_SUBTREE, attrs) + except LdbError, e: + print "unknown class '%s'\n" % name + return None + if len(res) == 0: + print "unknown class '%s'\n" % name + return None + return obj_objectClass(ldb, name) + +# +# append 2 lists +# +def list_append(a1, a2): + if (a1 == undefined) { + return a2 + if (a2 == undefined) + return a1 + for (i=0;i Date: Sun, 10 Feb 2008 00:56:55 +0100 Subject: More syntax fixes, use more standard python functions. (This used to be commit ea07509b4a9335a3b3fe6f6da1124fd1aab33c96) --- source4/scripting/bin/minschema.py | 575 ++++++++++++++++--------------------- 1 file changed, 247 insertions(+), 328 deletions(-) (limited to 'source4/scripting/bin') diff --git a/source4/scripting/bin/minschema.py b/source4/scripting/bin/minschema.py index 0a16cc9886..fb9d7b05aa 100755 --- a/source4/scripting/bin/minschema.py +++ b/source4/scripting/bin/minschema.py @@ -3,9 +3,10 @@ # work out the minimal schema for a set of objectclasses # -import getopt import optparse import samba +from samba import getopt as options +import sys parser = optparse.OptionParser("minschema ") sambaopts = options.SambaOptions(parser) @@ -28,14 +29,14 @@ if opts.dump_attributes: opts.dump_all = False if opts.dump_subschema: opts.dump_all = False -if dump_subschema_auto: - opts.dump_all = False - opts.dump_subschema = True +if opts.dump_subschema_auto: + opts.dump_all = False + opts.dump_subschema = True if opts.dump_all: - opts.dump_classes = True - opts.dump_attributes = True - opts.dump_subschema = True - opts.dump_subschema_auto = True + opts.dump_classes = True + opts.dump_attributes = True + opts.dump_subschema = True + opts.dump_subschema_auto = True if len(args) != 2: parser.print_usage() @@ -48,9 +49,8 @@ ldb = Ldb(url, credentials=creds) objectclasses = [] attributes = [] -rootDse = {} -objectclasses_expanded = [] +objectclasses_expanded = set() # the attributes we need for objectclasses class_attrs = ["objectClass", @@ -130,33 +130,28 @@ attrib_attrs = ["objectClass", # def dprintf(text): if verbose is not None: - print text + print text def get_object_cn(ldb, name): - attrs = ["cn"] + attrs = ["cn"] - res = ldb.search("(ldapDisplayName=%s)" % name, rootDse.schemaNamingContext, ldb.SCOPE_SUBTREE, attrs) - assert len(res) == 1 + res = ldb.search("(ldapDisplayName=%s)" % name, rootDse["schemaNamingContext"], ldb.SCOPE_SUBTREE, attrs) + assert len(res) == 1 - cn = res[0]["cn"] + return res[0]["cn"] -# -# create an objectclass object -# -def obj_objectClass(ldb, name): - var o = new Object() - o.name = name - o.cn = get_object_cn(ldb, name) - return o +class Objectclass: + def __init__(self, ldb, name): + """create an objectclass object""" + self.name = name + self.cn = get_object_cn(ldb, name) -# -# create an attribute object -# -def obj_attribute(ldb, name): - var o = new Object() - o.name = name - o.cn = get_object_cn(ldb, name) - return o + +class Attribute: + def __init__(self, ldb, name): + """create an attribute object""" + self.name = name + self.cn = get_object_cn(ldb, name) syntaxmap = dict() @@ -179,397 +174,330 @@ syntaxmap['2.5.5.15'] = '1.2.840.113556.1.4.907' syntaxmap['2.5.5.16'] = '1.2.840.113556.1.4.906' syntaxmap['2.5.5.17'] = '1.3.6.1.4.1.1466.115.121.1.40' -# -# map some attribute syntaxes from some apparently MS specific -# syntaxes to the standard syntaxes -# + def map_attribute_syntax(s): + """map some attribute syntaxes from some apparently MS specific + syntaxes to the standard syntaxes""" if syntaxmap.has_key(s): - return syntaxmap[s] - return s + return syntaxmap[s] + return s + -# -# fix a string DN to use ${SCHEMADN} -# def fix_dn(dn): - s = strstr(dn, rootDse.schemaNamingContext) - if (s == NULL) { - return dn - } - return substr(dn, 0, strlen(dn) - strlen(s)) + "${SCHEMADN}" + """fix a string DN to use ${SCHEMADN}""" + return dn.replace(rootDse["schemaNamingContext"], "${SCHEMADN}") + -# -# dump an object as ldif -# def write_ldif_one(o, attrs): - print "dn: CN=%s,${SCHEMADN}\n" % o["cn"] + """dump an object as ldif""" + print "dn: CN=%s,${SCHEMADN}\n" % o["cn"] for a in attrs: if not o.has_key(a): - continue - # special case for oMObjectClass, which is a binary object + continue + # special case for oMObjectClass, which is a binary object if a == "oMObjectClass": - print "%s:: %s\n" % (a, o[a]) - continue - v = o[a] + print "%s:: %s\n" % (a, o[a]) + continue + v = o[a] if isinstance(v, str): - v = [v] + v = [v] for j in v: - print "%s: %s\n" % (a, fix_dn(j)) - print "\n" + print "%s: %s\n" % (a, fix_dn(j)) + print "\n" -# -# dump an array of objects as ldif -# def write_ldif(o, attrs): + """dump an array of objects as ldif""" for i in o: - write_ldif_one(i, attrs) + write_ldif_one(i, attrs) -# -# create a testDN based an an example DN -# the idea is to ensure we obey any structural rules -# def create_testdn(exampleDN): - a = split(",", exampleDN) - a[0] = "CN=TestDN" - return ",".join(a) + """create a testDN based an an example DN + the idea is to ensure we obey any structural rules""" + a = exampleDN.split(",") + a[0] = "CN=TestDN" + return ",".join(a) + -# -# find the properties of an objectclass -# def find_objectclass_properties(ldb, o): - res = ldb.search( - expression="(ldapDisplayName=%s)" % o.name, - rootDse.schemaNamingContext, ldb.SCOPE_SUBTREE, class_attrs) - assert(len(res) == 1) + """the properties of an objectclass""" + res = ldb.search( + expression="(ldapDisplayName=%s)" % o.name, + basedn=rootDse["schemaNamingContext"], scope=ldb.SCOPE_SUBTREE, attrs=class_attrs) + assert(len(res) == 1) msg = res[0] for a in msg: - o[a] = msg[a] + o[a] = msg[a] -# -# find the properties of an attribute -# def find_attribute_properties(ldb, o): - res = ldb.search( - expression="(ldapDisplayName=%s)" % o.name, - rootDse.schemaNamingContext, ldb.SCOPE_SUBTREE, attrib_attrs) - assert(len(res) == 1) + """find the properties of an attribute""" + res = ldb.search( + expression="(ldapDisplayName=%s)" % o.name, + basedn=rootDse["schemaNamingContext"], scope=ldb.SCOPE_SUBTREE, + attrs=attrib_attrs) + assert(len(res) == 1) msg = res[0] for a in msg: - # special case for oMObjectClass, which is a binary object + # special case for oMObjectClass, which is a binary object if a == "oMObjectClass": - o[a] = ldb.encode(msg[a]) - continue - o[a] = msg[a] + o[a] = ldb.encode(msg[a]) + continue + o[a] = msg[a] + -# -# find the auto-created properties of an objectclass. Only works for classes -# that can be created using just a DN and the objectclass -# def find_objectclass_auto(ldb, o): + """find the auto-created properties of an objectclass. Only works for + classes that can be created using just a DN and the objectclass""" if not o.has_key("exampleDN"): - return - testdn = create_testdn(o.exampleDN) + return + testdn = create_testdn(o.exampleDN) - print "testdn is '%s'\n" % testdn + print "testdn is '%s'\n" % testdn - ldif = "dn: " + testdn - ldif += "\nobjectClass: " + o.name + ldif = "dn: " + testdn + ldif += "\nobjectClass: " + o.name try: ldb.add(ldif) except LdbError, e: print "error adding %s: %s\n" % (o.name, e) - print "%s\n" % ldif + print "%s\n" % ldif return - res = ldb.search("", testdn, ldb.SCOPE_BASE) - ldb.delete(testdn) + res = ldb.search("", testdn, ldb.SCOPE_BASE) + ldb.delete(testdn) for a in res.msgs[0]: - attributes[a].autocreate = True + attributes[a].autocreate = True -# -# look at auxiliary information from a class to intuit the existance of more -# classes needed for a minimal schema -# def expand_objectclass(ldb, o): - attrs = ["auxiliaryClass", "systemAuxiliaryClass", - "possSuperiors", "systemPossSuperiors", - "subClassOf"] - res = ldb.search( - "(&(objectClass=classSchema)(ldapDisplayName=%s))" % o.name, - rootDse.schemaNamingContext, ldb.SCOPE_SUBTREE, attrs) - print "Expanding class %s\n" % o.name - assert(len(res) == 1) - msg = res[0] + """look at auxiliary information from a class to intuit the existance of + more classes needed for a minimal schema""" + attrs = ["auxiliaryClass", "systemAuxiliaryClass", + "possSuperiors", "systemPossSuperiors", + "subClassOf"] + res = ldb.search( + expression="(&(objectClass=classSchema)(ldapDisplayName=%s))" % o.name, + basedn=rootDse["schemaNamingContext"], scope=ldb.SCOPE_SUBTREE, + attrs=attrs) + print "Expanding class %s\n" % o.name + assert(len(res) == 1) + msg = res[0] for a in attrs: if not msg.has_key(aname): - continue - list = msg[aname] + continue + list = msg[aname] if isinstance(list, str): - list = [msg[aname]] + list = [msg[aname]] for name in list: if not objectclasses.has_key(name): - print "Found new objectclass '%s'\n" % name - objectclasses[name] = obj_objectClass(ldb, name) + print "Found new objectclass '%s'\n" % name + objectclasses[name] = Objectclass(ldb, name) -# -# add the must and may attributes from an objectclass to the full list -# of attributes -# -def add_objectclass_attributes(ldb, class): - attrs = ["mustContain", "systemMustContain", - "mayContain", "systemMayContain"] +def add_objectclass_attributes(ldb, objectclass): + """add the must and may attributes from an objectclass to the full list + of attributes""" + attrs = ["mustContain", "systemMustContain", + "mayContain", "systemMayContain"] for aname in attrs: - if not class.has_key(aname): - continue - alist = class[aname] + if not objectclass.has_key(aname): + continue + alist = objectclass[aname] if isinstance(alist, str): - alist = [alist] + alist = [alist] for a in alist: if not attributes.has_key(a): - attributes[a] = obj_attribute(ldb, a) + attributes[a] = Attribute(ldb, a) -# -# process an individual record, working out what attributes it has -# def walk_dn(ldb, dn): - # get a list of all possible attributes for this object - attrs = ["allowedAttributes"] + """process an individual record, working out what attributes it has""" + # get a list of all possible attributes for this object + attrs = ["allowedAttributes"] try: res = ldb.search("objectClass=*", dn, ldb.SCOPE_BASE, attrs) except LdbError, e: - print "Unable to fetch allowedAttributes for '%s' - %r\n" % (dn, e) - return - allattrs = res[0]["allowedAttributes"] + print "Unable to fetch allowedAttributes for '%s' - %r\n" % (dn, e) + return + allattrs = res[0]["allowedAttributes"] try: res = ldb.search("objectClass=*", dn, ldb.SCOPE_BASE, allattrs) except LdbError, e: print "Unable to fetch all attributes for '%s' - %s\n" % (dn, e) - return - msg = res[0] + return + msg = res[0] for a in msg: if not attributes.has_key(a): - attributes[a] = obj_attribute(ldb, a) + attributes[a] = Attribute(ldb, a) -# -# walk a naming context, looking for all records -# def walk_naming_context(ldb, namingContext): + """walk a naming context, looking for all records""" try: res = ldb.search("objectClass=*", namingContext, ldb.SCOPE_DEFAULT, ["objectClass"]) except LdbError, e: - print "Unable to fetch objectClasses for '%s' - %s\n" % (namingContext, e) - return + print "Unable to fetch objectClasses for '%s' - %s\n" % (namingContext, e) + return for msg in res: - msg = res.msgs[r]["objectClass"] + msg = res.msgs[r]["objectClass"] for objectClass in msg: if not objectclasses.has_key(objectClass): - objectclasses[objectClass] = obj_objectClass(ldb, objectClass) - objectclasses[objectClass].exampleDN = res.msgs[r]["dn"] - walk_dn(ldb, res.msgs[r].dn) - -# -# trim the may attributes for an objectClass -# -def trim_objectclass_attributes(ldb, class): - # trim possibleInferiors, - # include only the classes we extracted - if class.has_key("possibleInferiors"): - possinf = class["possibleInferiors"] - newpossinf = [] + objectclasses[objectClass] = Objectclass(ldb, objectClass) + objectclasses[objectClass].exampleDN = res.msgs[r]["dn"] + walk_dn(ldb, res.msgs[r].dn) + +def trim_objectclass_attributes(ldb, objectclass): + """trim the may attributes for an objectClass""" + # trim possibleInferiors, + # include only the classes we extracted + if objectclass.has_key("possibleInferiors"): + possinf = objectclass["possibleInferiors"] + newpossinf = [] if isinstance(possinf, str): - possinf = [possinf] + possinf = [possinf] for x in possinf: if objectclasses.has_key(x): - newpossinf[n] = x - n++ - class["possibleInferiors"] = newpossinf - - # trim systemMayContain, - # remove duplicates - if class.has_key("systemMayContain"): - sysmay = class["systemMayContain"] - newsysmay = [] + newpossinf[n] = x + n+=1 + objectclass["possibleInferiors"] = newpossinf + + # trim systemMayContain, + # remove duplicates + if objectclass.has_key("systemMayContain"): + sysmay = objectclass["systemMayContain"] + newsysmay = [] if isinstance(sysmay, str): - sysmay = [sysmay] + sysmay = [sysmay] for x in sysmay: - dup = False - if newsysmay[0] == undefined) { - newsysmay[0] = x - else: - for (n = 0; n < newsysmay.length; n++) { - if (newsysmay[n] == x) { - dup = True - if not dup: - newsysmay[n] = x - class["systemMayContain"] = newsysmay - - # trim mayContain, - # remove duplicates - if not class.has_key("mayContain"): - may = class["mayContain"] - newmay = [] + if not x in newsysmay: + newsysmay.append(x) + objectclass["systemMayContain"] = newsysmay + + # trim mayContain, + # remove duplicates + if not objectclass.has_key("mayContain"): + may = objectclass["mayContain"] + newmay = [] if isinstance(may, str): - may = [may] + may = [may] for x in may: - dup = False - if (newmay[0] == undefined) { - newmay[0] = x - } else { - for (n = 0; n < newmay.length; n++) { - if (newmay[n] == x) { - dup = True - if not dup: - newmay[n] = x - class["mayContain"] = newmay + if not x in newmay: + newmay.append(x) + objectclass["mayContain"] = newmay -# -# load the basic attributes of an objectClass -# def build_objectclass(ldb, name): - attrs = ["name"] + """load the basic attributes of an objectClass""" + attrs = ["name"] try: res = ldb.search( expression="(&(objectClass=classSchema)(ldapDisplayName=%s))" % name, - rootDse.schemaNamingContext, ldb.SCOPE_SUBTREE, attrs) + basedn=rootDse["schemaNamingContext"], scope=ldb.SCOPE_SUBTREE, + attrs=attrs) except LdbError, e: - print "unknown class '%s'\n" % name - return None + print "unknown class '%s'\n" % name + return None if len(res) == 0: - print "unknown class '%s'\n" % name - return None - return obj_objectClass(ldb, name) - -# -# append 2 lists -# -def list_append(a1, a2): - if (a1 == undefined) { - return a2 - if (a2 == undefined) - return a1 - for (i=0;i Date: Tue, 12 Feb 2008 21:59:23 +0100 Subject: Correctly increment counters in Subunit test runner. (This used to be commit c474a2bb83a3e28a0b83f3b8ca1b646742dfca3d) --- source4/scripting/bin/subunitrun | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) (limited to 'source4/scripting/bin') diff --git a/source4/scripting/bin/subunitrun b/source4/scripting/bin/subunitrun index 7142abed85..8dfe2def9c 100755 --- a/source4/scripting/bin/subunitrun +++ b/source4/scripting/bin/subunitrun @@ -21,6 +21,4 @@ from subunit import SubunitTestRunner import sys from unittest import TestProgram -program = TestProgram(module=None, argv=sys.argv, - testRunner=SubunitTestRunner()) -program.runTests() +TestProgram(module=None, argv=sys.argv, testRunner=SubunitTestRunner()) -- cgit From 04aef38453ff977bf260546545e968fce3ddd599 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Tue, 12 Feb 2008 22:10:25 +0100 Subject: Fix subunit runner exit codes. (This used to be commit 7911308dbc1233838e44c533302f77b03ea41148) --- source4/scripting/bin/subunitrun | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'source4/scripting/bin') diff --git a/source4/scripting/bin/subunitrun b/source4/scripting/bin/subunitrun index 8dfe2def9c..11ac426589 100755 --- a/source4/scripting/bin/subunitrun +++ b/source4/scripting/bin/subunitrun @@ -21,4 +21,5 @@ from subunit import SubunitTestRunner import sys from unittest import TestProgram -TestProgram(module=None, argv=sys.argv, testRunner=SubunitTestRunner()) +runner = SubunitTestRunner() +TestProgram(module=None, argv=sys.argv, testRunner=runner) -- cgit From 8f8c56bfbcbfe8f80afb09eb1d481a108b252bee Mon Sep 17 00:00:00 2001 From: Andrew Kroeger Date: Fri, 28 Mar 2008 01:08:49 -0500 Subject: Convert some more files to GPLv3. (This used to be commit ebe5e8399422eb7e2ff4deb546338823e2718907) --- source4/scripting/bin/smbstatus | 2 +- source4/scripting/bin/winreg | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'source4/scripting/bin') diff --git a/source4/scripting/bin/smbstatus b/source4/scripting/bin/smbstatus index ea41289dce..4dfc3365a1 100755 --- a/source4/scripting/bin/smbstatus +++ b/source4/scripting/bin/smbstatus @@ -3,7 +3,7 @@ exec smbscript "$0" ${1+"$@"} /* provide information on connected users and open files Copyright Andrew Tridgell 2005 - Released under the GNU GPL v2 or later + Released under the GNU GPL version 3 or later */ libinclude("base.js"); diff --git a/source4/scripting/bin/winreg b/source4/scripting/bin/winreg index 2114394f45..883c6d7ee3 100755 --- a/source4/scripting/bin/winreg +++ b/source4/scripting/bin/winreg @@ -3,7 +3,7 @@ exec smbscript "$0" ${1+"$@"} /* tool to manipulate a remote registry Copyright Andrew Tridgell 2005 - Released under the GNU GPL v2 or later + Released under the GNU GPL version 3 or later */ var options = GetOptions(ARGV, -- cgit From 1bcbc4afcf2f9984081652c1fbe50d329c86b3b5 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Mon, 14 Apr 2008 19:13:41 +0200 Subject: Allow command line options in the subunitrun script. (This used to be commit 524ec0796efebd48e7b5b2eb5fcc92ecc13c0071) --- source4/scripting/bin/subunitrun | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) (limited to 'source4/scripting/bin') diff --git a/source4/scripting/bin/subunitrun b/source4/scripting/bin/subunitrun index 11ac426589..3730a15e1b 100755 --- a/source4/scripting/bin/subunitrun +++ b/source4/scripting/bin/subunitrun @@ -20,6 +20,26 @@ from subunit import SubunitTestRunner import sys from unittest import TestProgram +import optparse +import os +import param +import samba.getopt as options +import samba.tests + +parser = optparse.OptionParser("subunitrun [options] ") +credopts = options.CredentialsOptions(parser) +parser.add_option_group(credopts) +sambaopts = options.SambaOptions(parser) +parser.add_option_group(sambaopts) +parser.add_option_group(options.VersionOptions(parser)) + +args = parser.parse_args()[1] + +samba.tests.cmdline_loadparm = sambaopts.get_loadparm() +samba.tests.cmdline_credentials = credopts.get_credentials(samba.tests.cmdline_loadparm) + +import pdb +pdb.set_trace() runner = SubunitTestRunner() -TestProgram(module=None, argv=sys.argv, testRunner=runner) +program = TestProgram(module=None, argv=[sys.argv[0]] + args, testRunner=runner) -- cgit From 2cdfaedee203a726bddfb46fb10d9604de32a05f Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Mon, 14 Apr 2008 19:20:43 +0200 Subject: Make sure credentials are specified when running the Python winreg RPC tests. (This used to be commit 280339e3d126f5c72dc271051b72839fde0c5c9f) --- source4/scripting/bin/subunitrun | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'source4/scripting/bin') diff --git a/source4/scripting/bin/subunitrun b/source4/scripting/bin/subunitrun index 3730a15e1b..fbbffde42c 100755 --- a/source4/scripting/bin/subunitrun +++ b/source4/scripting/bin/subunitrun @@ -38,8 +38,7 @@ args = parser.parse_args()[1] samba.tests.cmdline_loadparm = sambaopts.get_loadparm() samba.tests.cmdline_credentials = credopts.get_credentials(samba.tests.cmdline_loadparm) -import pdb -pdb.set_trace() +param.cvar.default_config = samba.tests.cmdline_loadparm runner = SubunitTestRunner() program = TestProgram(module=None, argv=[sys.argv[0]] + args, testRunner=runner) -- cgit From babdcc6135e6d3a91a9ddeae0555652026f09344 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Sun, 11 May 2008 05:29:20 +0200 Subject: Use system python rather than smbpython. (This used to be commit d3df51cd01e53383dcc05923d248db03bc6f62e9) --- source4/scripting/bin/subunitrun | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'source4/scripting/bin') diff --git a/source4/scripting/bin/subunitrun b/source4/scripting/bin/subunitrun index fbbffde42c..719a58d9e5 100755 --- a/source4/scripting/bin/subunitrun +++ b/source4/scripting/bin/subunitrun @@ -17,8 +17,10 @@ # along with this program. If not, see . # -from subunit import SubunitTestRunner import sys +sys.path.append("bin/python") + +from subunit import SubunitTestRunner from unittest import TestProgram import optparse import os -- cgit From 47d22189227c0dd6f2f370ade2cfb878eef0f240 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Sun, 11 May 2008 05:45:49 +0200 Subject: Set sys.path for running inside source tree. (This used to be commit b507109bb676715f7d9616e13b0e19305e9c2559) --- source4/scripting/bin/minschema.py | 4 ++++ source4/scripting/bin/rpcclient | 4 ++++ source4/scripting/bin/samba3dump | 5 ++++- source4/scripting/bin/subunitrun | 4 +++- source4/scripting/bin/winreg.py | 4 ++++ 5 files changed, 19 insertions(+), 2 deletions(-) (limited to 'source4/scripting/bin') diff --git a/source4/scripting/bin/minschema.py b/source4/scripting/bin/minschema.py index fb9d7b05aa..6dd5b42aff 100755 --- a/source4/scripting/bin/minschema.py +++ b/source4/scripting/bin/minschema.py @@ -4,6 +4,10 @@ # import optparse + +# Find right directory when running from source tree +sys.path.insert(0, "bin/python") + import samba from samba import getopt as options import sys diff --git a/source4/scripting/bin/rpcclient b/source4/scripting/bin/rpcclient index 34efafdf73..aba4f9ddb3 100755 --- a/source4/scripting/bin/rpcclient +++ b/source4/scripting/bin/rpcclient @@ -1,6 +1,10 @@ #!/usr/bin/python import sys, os, string + +# Find right directory when running from source tree +sys.path.insert(0, "bin/python") + from cmd import Cmd from optparse import OptionParser from pprint import pprint diff --git a/source4/scripting/bin/samba3dump b/source4/scripting/bin/samba3dump index 8f56d423d8..d89667233f 100755 --- a/source4/scripting/bin/samba3dump +++ b/source4/scripting/bin/samba3dump @@ -7,7 +7,10 @@ import optparse import os, sys -sys.path.append(os.path.join(os.path.dirname(__file__), "../python")) + +# Find right directory when running from source tree +sys.path.insert(0, "bin/python") + import samba import samba.samba3 diff --git a/source4/scripting/bin/subunitrun b/source4/scripting/bin/subunitrun index 719a58d9e5..de11aba3cc 100755 --- a/source4/scripting/bin/subunitrun +++ b/source4/scripting/bin/subunitrun @@ -18,7 +18,9 @@ # import sys -sys.path.append("bin/python") + +# Find right directory when running from source tree +sys.path.insert(0, "bin/python") from subunit import SubunitTestRunner from unittest import TestProgram diff --git a/source4/scripting/bin/winreg.py b/source4/scripting/bin/winreg.py index 1e39ee8f78..19d39e56ab 100755 --- a/source4/scripting/bin/winreg.py +++ b/source4/scripting/bin/winreg.py @@ -7,6 +7,10 @@ # import sys + +# Find right directory when running from source tree +sys.path.insert(0, "bin/python") + import winreg import optparse import samba.getopt as options -- cgit From 49706ab19bd3ffd6125639e6a7753b2350cf54e1 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Wed, 21 May 2008 23:59:34 +0200 Subject: Move more modules inside of the samba package. (This used to be commit 9b39e99f48266a54ed0b8890c2efde218b4b118a) --- source4/scripting/bin/subunitrun | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source4/scripting/bin') diff --git a/source4/scripting/bin/subunitrun b/source4/scripting/bin/subunitrun index de11aba3cc..6f1086ad37 100755 --- a/source4/scripting/bin/subunitrun +++ b/source4/scripting/bin/subunitrun @@ -26,7 +26,7 @@ from subunit import SubunitTestRunner from unittest import TestProgram import optparse import os -import param +from samba import param import samba.getopt as options import samba.tests -- cgit From 7cfcec2e9d8ea5ad9619848f60c846e805fb15a2 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Fri, 23 May 2008 02:44:42 +0200 Subject: Fix imports for minschema. (This used to be commit bda223a49e6bdeda68518cba27bc92df33784939) --- source4/scripting/bin/minschema.py | 2 ++ 1 file changed, 2 insertions(+) (limited to 'source4/scripting/bin') diff --git a/source4/scripting/bin/minschema.py b/source4/scripting/bin/minschema.py index 6dd5b42aff..111557126d 100755 --- a/source4/scripting/bin/minschema.py +++ b/source4/scripting/bin/minschema.py @@ -5,6 +5,8 @@ import optparse +import os, sys + # Find right directory when running from source tree sys.path.insert(0, "bin/python") -- cgit From 27005cb7a2182c50c8bf9e683de1bea2613a3078 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Thu, 22 May 2008 05:13:31 +0200 Subject: Convert samr test to python. (This used to be commit 88d473b202e82b462ef82ffdeb4f1710918ffda5) --- source4/scripting/bin/samr.py | 114 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 114 insertions(+) create mode 100755 source4/scripting/bin/samr.py (limited to 'source4/scripting/bin') diff --git a/source4/scripting/bin/samr.py b/source4/scripting/bin/samr.py new file mode 100755 index 0000000000..118cf759fe --- /dev/null +++ b/source4/scripting/bin/samr.py @@ -0,0 +1,114 @@ +#!/usr/bin/python +# -*- coding: utf-8 -*- + +# Unix SMB/CIFS implementation. +# Copyright © Jelmer Vernooij 2008 +# +# Based on samr.js © Andrew Tridgell +# +# 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 3 of the License, or +# (at your option) any later version. +# +# This program 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 General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . +# + +import sys + +sys.path.insert(0, "bin/python") + +from samba.dcerpc import samr, security + +def FillUserInfo(samr, dom_handle, users, level): + """fill a user array with user information from samrQueryUserInfo""" + for i in range(len(users)): + user_handle = samr.OpenUser(handle, security.SEC_FLAG_MAXIMUM_ALLOWED, users[i].idx) + info = samr.QueryUserInfo(user_handle, level) + info.name = users[i].name + info.idx = users[i].idx + users[i] = info + samr.Close(user_handle) + +def toArray((handle, array, num_entries)): + ret = [] + for x in range(num_entries): + ret.append((array.entries[x].idx, array.entries[x].name)) + return ret + + +def test_Connect(samr): + """test the samr_Connect interface""" + print "Testing samr_Connect" + return samr.Connect2(None, security.SEC_FLAG_MAXIMUM_ALLOWED) + +def test_LookupDomain(samr, handle, domain): + """test the samr_LookupDomain interface""" + print "Testing samr_LookupDomain" + return samr.LookupDomain(handle, domain) + +def test_OpenDomain(samr, handle, sid): + """test the samr_OpenDomain interface""" + print "Testing samr_OpenDomain" + return samr.OpenDomain(handle, security.SEC_FLAG_MAXIMUM_ALLOWED, sid) + +def test_EnumDomainUsers(samr, dom_handle): + """test the samr_EnumDomainUsers interface""" + print "Testing samr_EnumDomainUsers" + users = toArray(samr.EnumDomainUsers(dom_handle, 0, 0, -1)) + print "Found %d users" % len(users) + for idx, user in users: + print "\t%s\t(%d)" % (user, idx) + +def test_EnumDomainGroups(samr, dom_handle): + """test the samr_EnumDomainGroups interface""" + print "Testing samr_EnumDomainGroups" + groups = toArray(samr.EnumDomainGroups(dom_handle, 0, 0, -1)) + print "Found %d groups" % len(groups) + for idx, group in groups: + print "\t" + group + "\t(" + idx + ")" + +def test_domain_ops(samr, dom_handle): + """test domain specific ops""" + test_EnumDomainUsers(samr, dom_handle) + test_EnumDomainGroups(samr, dom_handle) + +def test_EnumDomains(samr, handle): + """test the samr_EnumDomains interface""" + print "Testing samr_EnumDomains" + + domains = toArray(samr.EnumDomains(handle, 0, -1)) + print "Found %d domains" % len(domains) + for idx, domain in domains: + print "\t%s (%d)" % (domain, idx) + for idx, domain in domains: + print "Testing domain %s" % domain + sid = samr.LookupDomain(handle, domain) + dom_handle = test_OpenDomain(samr, handle, sid) + test_domain_ops(samr, dom_handle) + samr.Close(dom_handle) + +if len(sys.argv) != 2: + print "Usage: samr.js " + sys.exit(1) + +binding = sys.argv[1] + +print "Connecting to " + binding +try: + samr = samr.samr(binding) +except Exception, e: + print "Failed to connect to %s: %s" % (binding, e.message) + sys.exit(1) + +handle = test_Connect(samr) +test_EnumDomains(samr, handle) +samr.Close(handle) + +print "All OK" -- cgit From 5eed56d0ad5245a346ea564bc34e882828394611 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Fri, 23 May 2008 15:10:35 +0200 Subject: Fix bugs in samr python tests. (This used to be commit 09c6b106ac144820b8c072bda4dad3d8e2145ff0) --- source4/scripting/bin/samr.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'source4/scripting/bin') diff --git a/source4/scripting/bin/samr.py b/source4/scripting/bin/samr.py index 118cf759fe..e91b5bc312 100755 --- a/source4/scripting/bin/samr.py +++ b/source4/scripting/bin/samr.py @@ -24,7 +24,7 @@ import sys sys.path.insert(0, "bin/python") -from samba.dcerpc import samr, security +from samba.dcerpc import samr, security, lsa def FillUserInfo(samr, dom_handle, users, level): """fill a user array with user information from samrQueryUserInfo""" @@ -69,10 +69,10 @@ def test_EnumDomainUsers(samr, dom_handle): def test_EnumDomainGroups(samr, dom_handle): """test the samr_EnumDomainGroups interface""" print "Testing samr_EnumDomainGroups" - groups = toArray(samr.EnumDomainGroups(dom_handle, 0, 0, -1)) + groups = toArray(samr.EnumDomainGroups(dom_handle, 0, 0)) print "Found %d groups" % len(groups) for idx, group in groups: - print "\t" + group + "\t(" + idx + ")" + print "\t%s\t(%d)" % (group, idx) def test_domain_ops(samr, dom_handle): """test domain specific ops""" -- cgit From a2446e5f8550582c0d4353bb85874dea17cf1d98 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Sun, 25 May 2008 02:32:21 +0200 Subject: Add initial work for script that uses probing to figure out IDL. (This used to be commit 4e5687e813e50d0bc8d6314e389d1d7a0be2f8c1) --- source4/scripting/bin/autoidl.py | 161 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 161 insertions(+) create mode 100755 source4/scripting/bin/autoidl.py (limited to 'source4/scripting/bin') diff --git a/source4/scripting/bin/autoidl.py b/source4/scripting/bin/autoidl.py new file mode 100755 index 0000000000..eed4ba3a80 --- /dev/null +++ b/source4/scripting/bin/autoidl.py @@ -0,0 +1,161 @@ +#!/usr/bin/python +# -*- coding: utf-8 -*- + +# Unix SMB/CIFS implementation. +# Copyright © Jelmer Vernooij 2008 +# +# 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 3 of the License, or +# (at your option) any later version. +# +# This program 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 General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . +# + +import sys + +MAX_OPNUM = 1000 +MAX_BASE_SIZE = 0x1000 +MAX_IFACE_VERSION = 1000 + +DCERPC_FAULT_OP_RNG_ERROR = 0x1c010002 +DCERPC_FAULT_NDR = 0x6f7 +NT_STATUS_NET_WRITE_FAULT = -1073741614 + + +sys.path.insert(0, "bin/python") + +from samba.dcerpc import ClientConnection + +def find_num_funcs(conn): + for i in xrange(MAX_OPNUM): + try: + conn.request(i, "") + except RuntimeError, (num, msg): + if num == DCERPC_FAULT_OP_RNG_ERROR: + return i + raise Exception("More than %d functions" % MAX_OPNUM) + +class Function: + def __init__(self, conn, opnum): + self.conn = conn + self.opnum = opnum + + def request(self, data): + assert isinstance(data, str) + self.conn.request(self.opnum, data) + + def valid_ndr(self, data): + try: + self.request(data) + except RuntimeError, (num, msg): + if num == DCERPC_FAULT_NDR: + return False + return True + + def find_base_request(self, start=""): + """Find the smallest possible request that we can do that is + valid. + + This generally means sending all zeroes so we get NULL pointers where + possible.""" + # TODO: Don't try with just 0's as there may be switch_is() variables + # for which 0 is not a valid value or variables with range() set + # See how much input bytes we need + for i in range(MAX_BASE_SIZE): + data = start + chr(0) * i + if self.valid_ndr(data): + return data + return None + + def check_decision_byte(self, base_request, i): + """Check whether the specified byte is a possible "decision" byte, + e.g. a byte that is part of a pointer, array size variable or + discriminant. + + Note that this function only checks if a byte is definitely a decision + byte. It may return False in some cases while the byte is actually + a decision byte.""" + data = list(base_request) + data[i] = chr(1) + return not self.valid_ndr("".join(data)) + + def find_deferrant_data(self, base_request, idx): + data = list(base_request) + data[idx*4] = chr(1) + # Just check that this is a pointer to something non-empty: + assert not self.valid_ndr("".join(data)) + + newdata = self.find_base_request("".join(data)) + + if newdata is None: + return None + + assert newdata.startswith(data) + + return newdata[len(data):] + + def find_idl(self): + base_request = self.find_base_request() + + if base_request is None: + raise Exception("Unable to determine base size for opnum %d" % self.opnum) + + print "\tBase request is %r" % base_request + + decision_byte_map = map(lambda x: self.check_decision_byte(base_request, x), range(len(base_request))) + + print decision_byte_map + + # find pointers + possible_pointers = map(all, + [decision_byte_map[i*4:(i+1)*4] for i in range(int(len(base_request)/4))]) + print possible_pointers + + pointer_deferrant_bases = map( + lambda x: self.find_deferrant_data(base_request, x) if possible_pointers[x] else None, range(len(possible_pointers))) + + print pointer_deferrant_bases + + +if len(sys.argv) < 3: + print "Usage: autoidl []" + sys.exit(1) + +(binding, uuid) = sys.argv[1:3] +if len(sys.argv) == 4: + version = sys.argv[3] +else: + version = None + +if version is None: + for i in range(MAX_IFACE_VERSION): + try: + conn = ClientConnection(binding, (uuid, i)) + except RuntimeError, (num, msg): + if num == NT_STATUS_NET_WRITE_FAULT: + continue + raise + else: + break +else: + conn = ClientConnection(binding, (uuid, version)) + +print "Figuring out number of connections...", +num_funcs = find_num_funcs(conn) +print "%d" % num_funcs + +# Figure out the syntax for each one +for i in range(num_funcs): + print "Function %d" % i + data = Function(conn, i) + try: + data.find_idl() + except Exception, e: + print "Error: %r" % e -- cgit From c17166fb3d9260d0c02e3f9f559413acde5ce048 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Mon, 26 May 2008 02:04:00 +0200 Subject: Convert smbstatus to Python. (This used to be commit f14ad6cd92227c7ed5c570b581e5db82b7d42e25) --- source4/scripting/bin/smbstatus | 159 ++++++++++++++++------------------------ 1 file changed, 63 insertions(+), 96 deletions(-) (limited to 'source4/scripting/bin') diff --git a/source4/scripting/bin/smbstatus b/source4/scripting/bin/smbstatus index 4dfc3365a1..782e83e4cf 100755 --- a/source4/scripting/bin/smbstatus +++ b/source4/scripting/bin/smbstatus @@ -1,96 +1,63 @@ -#!/bin/sh -exec smbscript "$0" ${1+"$@"} -/* - provide information on connected users and open files - Copyright Andrew Tridgell 2005 - Released under the GNU GPL version 3 or later -*/ - -libinclude("base.js"); -libinclude("management.js"); - -var options = new Object(); - -options = GetOptions(ARGV, - "POPT_AUTOHELP", - "POPT_COMMON_SAMBA", - "POPT_COMMON_VERSION", - "nbt"); -if (options == undefined) { - println("Failed to parse options: " + options.ERROR); - return -1; -} - -/* - show open sessions -*/ -function show_sessions() -{ - var sessions = smbsrv_sessions(); - var i; - var sys = sys_init(); - if (sessions == undefined) { - println("No sessions open"); - return; - } - printf("User Client Connected at\n"); - printf("-------------------------------------------------------------------------------\n"); - for (i=0;i Date: Mon, 26 May 2008 04:14:28 +0200 Subject: Allow using IRPC functions on the messaging bus from Python. (This used to be commit 6ecf81ae13dffa05356c1177c617206c120fb7d7) --- source4/scripting/bin/smbstatus | 39 +++++++++++++++++++++++---------------- 1 file changed, 23 insertions(+), 16 deletions(-) (limited to 'source4/scripting/bin') diff --git a/source4/scripting/bin/smbstatus b/source4/scripting/bin/smbstatus index 782e83e4cf..6d852c279c 100755 --- a/source4/scripting/bin/smbstatus +++ b/source4/scripting/bin/smbstatus @@ -15,11 +15,12 @@ sys.path.insert(0, "bin/python") import optparse import samba.getopt as options -import samba.irpc +from samba import messaging, irpc -def show_sessions(): +def show_sessions(conn): """show open sessions""" - sessions = smbsrv_sessions() + conn = open_connection("smb_server") + sessions = conn.smbsrv_information(irpc.SMBSRV_INFO_SESSIONS).next() print "User Client Connected at" print "-------------------------------------------------------------------------------" for session in sessions: @@ -27,37 +28,43 @@ def show_sessions(): print "%-30s %16s %s" % (fulluser, session.client_ip, sys.httptime(session.connect_time)) print "" -def show_tcons(): +def show_tcons(open_connection): """show open tree connects""" - tcons = smbsrv_tcons() + conn = open_connection("smb_server") + tcons = conn.smbsrv_information(irpc.SMBSRV_INFO_TCONS).next() print "Share Client Connected at" print "-------------------------------------------------------------------------------" for tcon in tcons: print "%-30s %16s %s\n" % (tcon.share_name, tcon.client_ip, sys.httptime(tcon.connect_time)) -def show_nbt(): +def show_nbt(open_connection): """show nbtd information""" - stats = nbtd_statistics() - print "NBT server statistics:", + conn = open_connection("nbt_server") + stats = conn.nbtd_information(irpc.NBTD_INFO_STATISTICS).next() + print "NBT server statistics:" for r in stats: - print "\t" + r + ":\t" + stats[r] + "\n" + print "\t" + r + ":\t" + getattr(stats, r) + "\n" print "" parser = optparse.OptionParser("%s [options]" % sys.argv[0]) sambaopts = options.SambaOptions(parser) parser.add_option_group(sambaopts) -parser.add_option("--nbt", type="string", metavar="NBT", - help="show NetBIOS status") +parser.add_option("--messaging-path", type="string", metavar="PATH", + help="messaging path") +parser.add_option("--nbt", help="show NetBIOS status", action="store_true") + +opts, args = parser.parse_args() lp = sambaopts.get_loadparm() print "%s\n\n" % lp.get("server string") +def open_connection(name): + return messaging.ClientConnection(name, messaging_path=opts.messaging_path) + if opts.nbt: - show_nbt() + show_nbt(open_connection) else: - show_sessions() - show_tcons() - -return 0 + show_sessions(open_connection) + show_tcons(open_connection) -- cgit From 4b3641695ba42d0348e8eceadb02430342c1513c Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Mon, 26 May 2008 05:00:45 +0200 Subject: Finish smbstatus in Python. (This used to be commit 988508c2d3269cc88ed38df2fc207a1c0aaccc6b) --- source4/scripting/bin/smbstatus | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) (limited to 'source4/scripting/bin') diff --git a/source4/scripting/bin/smbstatus b/source4/scripting/bin/smbstatus index 6d852c279c..7e58ee1269 100755 --- a/source4/scripting/bin/smbstatus +++ b/source4/scripting/bin/smbstatus @@ -9,13 +9,13 @@ # Released under the GNU GPL version 3 or later # -import sys +import os, sys sys.path.insert(0, "bin/python") import optparse import samba.getopt as options -from samba import messaging, irpc +from samba import irpc, messaging def show_sessions(conn): """show open sessions""" @@ -35,7 +35,7 @@ def show_tcons(open_connection): print "Share Client Connected at" print "-------------------------------------------------------------------------------" for tcon in tcons: - print "%-30s %16s %s\n" % (tcon.share_name, tcon.client_ip, sys.httptime(tcon.connect_time)) + print "%-30s %16s %s" % (tcon.share_name, tcon.client_ip, sys.httptime(tcon.connect_time)) def show_nbt(open_connection): @@ -43,9 +43,14 @@ def show_nbt(open_connection): conn = open_connection("nbt_server") stats = conn.nbtd_information(irpc.NBTD_INFO_STATISTICS).next() print "NBT server statistics:" - for r in stats: - print "\t" + r + ":\t" + getattr(stats, r) + "\n" - print "" + fields = [("total_received", "Total received"), + ("total_sent", "Total sent"), + ("query_count", "Query count"), + ("register_count", "Register count"), + ("release_count", "Release count")] + for (field, description) in fields: + print "\t%s:\t%s" % (description, getattr(stats, field)) + print parser = optparse.OptionParser("%s [options]" % sys.argv[0]) sambaopts = options.SambaOptions(parser) @@ -58,10 +63,12 @@ opts, args = parser.parse_args() lp = sambaopts.get_loadparm() -print "%s\n\n" % lp.get("server string") +print "%s" % lp.get("server string") + +messaging_path = (opts.messaging_path or os.path.join(lp.get("private dir"), "smbd.tmp", "messaging")) def open_connection(name): - return messaging.ClientConnection(name, messaging_path=opts.messaging_path) + return messaging.ClientConnection(name, messaging_path=messaging_path) if opts.nbt: show_nbt(open_connection) -- cgit From 575f1243856f52f87ccb09f1235f1263b7c54b9b Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Mon, 26 May 2008 05:12:31 +0200 Subject: Cope with no server being active. (This used to be commit 893119bb4c9c297966d43d37fe73faa747b7c86e) --- source4/scripting/bin/smbstatus | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) (limited to 'source4/scripting/bin') diff --git a/source4/scripting/bin/smbstatus b/source4/scripting/bin/smbstatus index 7e58ee1269..bbd0e84826 100755 --- a/source4/scripting/bin/smbstatus +++ b/source4/scripting/bin/smbstatus @@ -19,7 +19,7 @@ from samba import irpc, messaging def show_sessions(conn): """show open sessions""" - conn = open_connection("smb_server") + sessions = conn.smbsrv_information(irpc.SMBSRV_INFO_SESSIONS).next() print "User Client Connected at" print "-------------------------------------------------------------------------------" @@ -73,5 +73,11 @@ def open_connection(name): if opts.nbt: show_nbt(open_connection) else: - show_sessions(open_connection) - show_tcons(open_connection) + try: + conn = open_connection("smb_server") + except RuntimeError, (num, msg): + if msg == 'NT_STATUS_OBJECT_NAME_NOT_FOUND': + print "No active connections" + else: + show_sessions(conn) + show_tcons(conn) -- cgit From 976eca077d2ea9b44b4b62ae851ca9cc470e3729 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Sat, 24 May 2008 17:56:49 +0200 Subject: Move some scripts to examples directory since they're not really generically useful. (This used to be commit 4026493e91f8096e5d602cd42f9a83d2d75042db) --- source4/scripting/bin/samba3dump | 4 +- source4/scripting/bin/samr.py | 114 --------------------------------------- source4/scripting/bin/winreg.py | 87 ------------------------------ 3 files changed, 2 insertions(+), 203 deletions(-) delete mode 100755 source4/scripting/bin/samr.py delete mode 100755 source4/scripting/bin/winreg.py (limited to 'source4/scripting/bin') diff --git a/source4/scripting/bin/samba3dump b/source4/scripting/bin/samba3dump index d89667233f..c11f8dbd0d 100755 --- a/source4/scripting/bin/samba3dump +++ b/source4/scripting/bin/samba3dump @@ -14,7 +14,7 @@ sys.path.insert(0, "bin/python") import samba import samba.samba3 -parser = optparse.OptionParser("provision []") +parser = optparse.OptionParser("samba3dump []") parser.add_option("--format", type="choice", metavar="FORMAT", choices=["full", "summary"]) @@ -96,7 +96,7 @@ def print_samba3_secrets(secrets): def print_samba3_regdb(regdb): print_header("Registry") - from registry import str_regtype + from samba.registry import str_regtype for k in regdb.keys(): print "[%s]" % k diff --git a/source4/scripting/bin/samr.py b/source4/scripting/bin/samr.py deleted file mode 100755 index e91b5bc312..0000000000 --- a/source4/scripting/bin/samr.py +++ /dev/null @@ -1,114 +0,0 @@ -#!/usr/bin/python -# -*- coding: utf-8 -*- - -# Unix SMB/CIFS implementation. -# Copyright © Jelmer Vernooij 2008 -# -# Based on samr.js © Andrew Tridgell -# -# 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 3 of the License, or -# (at your option) any later version. -# -# This program 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 General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program. If not, see . -# - -import sys - -sys.path.insert(0, "bin/python") - -from samba.dcerpc import samr, security, lsa - -def FillUserInfo(samr, dom_handle, users, level): - """fill a user array with user information from samrQueryUserInfo""" - for i in range(len(users)): - user_handle = samr.OpenUser(handle, security.SEC_FLAG_MAXIMUM_ALLOWED, users[i].idx) - info = samr.QueryUserInfo(user_handle, level) - info.name = users[i].name - info.idx = users[i].idx - users[i] = info - samr.Close(user_handle) - -def toArray((handle, array, num_entries)): - ret = [] - for x in range(num_entries): - ret.append((array.entries[x].idx, array.entries[x].name)) - return ret - - -def test_Connect(samr): - """test the samr_Connect interface""" - print "Testing samr_Connect" - return samr.Connect2(None, security.SEC_FLAG_MAXIMUM_ALLOWED) - -def test_LookupDomain(samr, handle, domain): - """test the samr_LookupDomain interface""" - print "Testing samr_LookupDomain" - return samr.LookupDomain(handle, domain) - -def test_OpenDomain(samr, handle, sid): - """test the samr_OpenDomain interface""" - print "Testing samr_OpenDomain" - return samr.OpenDomain(handle, security.SEC_FLAG_MAXIMUM_ALLOWED, sid) - -def test_EnumDomainUsers(samr, dom_handle): - """test the samr_EnumDomainUsers interface""" - print "Testing samr_EnumDomainUsers" - users = toArray(samr.EnumDomainUsers(dom_handle, 0, 0, -1)) - print "Found %d users" % len(users) - for idx, user in users: - print "\t%s\t(%d)" % (user, idx) - -def test_EnumDomainGroups(samr, dom_handle): - """test the samr_EnumDomainGroups interface""" - print "Testing samr_EnumDomainGroups" - groups = toArray(samr.EnumDomainGroups(dom_handle, 0, 0)) - print "Found %d groups" % len(groups) - for idx, group in groups: - print "\t%s\t(%d)" % (group, idx) - -def test_domain_ops(samr, dom_handle): - """test domain specific ops""" - test_EnumDomainUsers(samr, dom_handle) - test_EnumDomainGroups(samr, dom_handle) - -def test_EnumDomains(samr, handle): - """test the samr_EnumDomains interface""" - print "Testing samr_EnumDomains" - - domains = toArray(samr.EnumDomains(handle, 0, -1)) - print "Found %d domains" % len(domains) - for idx, domain in domains: - print "\t%s (%d)" % (domain, idx) - for idx, domain in domains: - print "Testing domain %s" % domain - sid = samr.LookupDomain(handle, domain) - dom_handle = test_OpenDomain(samr, handle, sid) - test_domain_ops(samr, dom_handle) - samr.Close(dom_handle) - -if len(sys.argv) != 2: - print "Usage: samr.js " - sys.exit(1) - -binding = sys.argv[1] - -print "Connecting to " + binding -try: - samr = samr.samr(binding) -except Exception, e: - print "Failed to connect to %s: %s" % (binding, e.message) - sys.exit(1) - -handle = test_Connect(samr) -test_EnumDomains(samr, handle) -samr.Close(handle) - -print "All OK" diff --git a/source4/scripting/bin/winreg.py b/source4/scripting/bin/winreg.py deleted file mode 100755 index 19d39e56ab..0000000000 --- a/source4/scripting/bin/winreg.py +++ /dev/null @@ -1,87 +0,0 @@ -#!/usr/bin/python -# -# tool to manipulate a remote registry -# Copyright Andrew Tridgell 2005 -# Copyright Jelmer Vernooij 2007 -# Released under the GNU GPL v3 or later -# - -import sys - -# Find right directory when running from source tree -sys.path.insert(0, "bin/python") - -import winreg -import optparse -import samba.getopt as options - -parser = optparse.OptionParser("%s [path]" % sys.argv[0]) -sambaopts = options.SambaOptions(parser) -parser.add_option_group(sambaopts) -parser.add_option("--createkey", type="string", metavar="KEYNAME", - help="create a key") - -opts, args = parser.parse_args() - -if len(args) < 1: - parser.print_usage() - sys.exit(-1) - -binding = args[0] - -print "Connecting to " + binding -conn = winreg.winreg(binding, sambaopts.get_loadparm()) - -def list_values(key): - (num_values, max_valnamelen, max_valbufsize) = conn.QueryInfoKey(key, winreg.String())[4:8] - for i in range(num_values): - name = winreg.StringBuf() - name.size = max_valnamelen - (name, type, data, _, data_len) = conn.EnumValue(key, i, name, 0, "", max_valbufsize, 0) - print "\ttype=%-30s size=%4d '%s'" % type, len, name - if type in (winreg.REG_SZ, winreg.REG_EXPAND_SZ): - print "\t\t'%s'" % data -# if (v.type == reg.REG_MULTI_SZ) { -# for (j in v.value) { -# printf("\t\t'%s'\n", v.value[j]) -# } -# } -# if (v.type == reg.REG_DWORD || v.type == reg.REG_DWORD_BIG_ENDIAN) { -# printf("\t\t0x%08x (%d)\n", v.value, v.value) -# } -# if (v.type == reg.REG_QWORD) { -# printf("\t\t0x%llx (%lld)\n", v.value, v.value) -# } - -def list_path(key, path): - count = 0 - (num_subkeys, max_subkeylen, max_subkeysize) = conn.QueryInfoKey(key, winreg.String())[1:4] - for i in range(num_subkeys): - name = winreg.StringBuf() - name.size = max_subkeysize - keyclass = winreg.StringBuf() - keyclass.size = max_subkeysize - (name, _, _) = conn.EnumKey(key, i, name, keyclass=keyclass, last_changed_time=None)[0] - subkey = conn.OpenKey(key, name, 0, winreg.KEY_QUERY_VALUE | winreg.KEY_ENUMERATE_SUB_KEYS) - count += list_path(subkey, "%s\\%s" % (path, name)) - list_values(subkey) - return count - -if len(args) > 1: - root = args[1] -else: - root = "HKLM" - -if opts.createkey: - reg.create_key("HKLM\\SOFTWARE", opt.createkey) -else: - print "Listing registry tree '%s'" % root - try: - root_key = getattr(conn, "Open%s" % root)(None, winreg.KEY_QUERY_VALUE | winreg.KEY_ENUMERATE_SUB_KEYS) - except AttributeError: - print "Unknown root key name %s" % root - sys.exit(1) - count = list_path(root_key, root) - if count == 0: - print "No entries found" - sys.exit(1) -- cgit From 57f6663f3a029945fe7e799d4371131d9a20d306 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Sat, 24 May 2008 17:52:58 +0200 Subject: Remove obsolete ejs winreg example. (This used to be commit f1a2d2bc00dac56080b2bd560074ec66d12a3129) --- source4/scripting/bin/winreg | 107 ------------------------------------------- 1 file changed, 107 deletions(-) delete mode 100755 source4/scripting/bin/winreg (limited to 'source4/scripting/bin') diff --git a/source4/scripting/bin/winreg b/source4/scripting/bin/winreg deleted file mode 100755 index 883c6d7ee3..0000000000 --- a/source4/scripting/bin/winreg +++ /dev/null @@ -1,107 +0,0 @@ -#!/bin/sh -exec smbscript "$0" ${1+"$@"} -/* - tool to manipulate a remote registry - Copyright Andrew Tridgell 2005 - Released under the GNU GPL version 3 or later -*/ - -var options = GetOptions(ARGV, - "POPT_AUTOHELP", - "POPT_COMMON_SAMBA", - "POPT_COMMON_CREDENTIALS", - "createkey=s"); -if (options == undefined) { - println("Failed to parse options"); - return -1; -} - -libinclude("base.js"); -libinclude("winreg.js"); - -if (options.ARGV.length < 1) { - println("Usage: winreg.js [path]"); - return -1; -} -var binding = options.ARGV[0]; -reg = winregObj(); - -print("Connecting to " + binding + "\n"); -status = reg.connect(binding); -if (status.is_ok != true) { - print("Failed to connect to " + binding + " - " + status.errstr + "\n"); - return -1; -} - -function list_values(path) { - var list = reg.enum_values(path); - var i; - if (list == undefined) { - return; - } - for (i=0;i 1) { - root = options.ARGV[1]; -} else { - root = ''; -} - -if (options.createkey) { - var ok = reg.create_key("HKLM\\SOFTWARE", options.createkey); - if (!ok) { - println("Failed to create key"); - } -} else { - printf("Listing registry tree '%s'\n", root); - var count = list_path(root); - if (count == 0) { - println("No entries found"); - return 1; - } -} -return 0; -- cgit From 998b0fef1199b3c24939878d202f5e4b71e5b742 Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Mon, 19 May 2008 23:06:42 +0200 Subject: Add "mymachinepw" to fetch our machine password out of secrets.ldb (This used to be commit 4fbe16deb0e06e145f643568a699b80b431d4f42) --- source4/scripting/bin/mymachinepw | 45 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100755 source4/scripting/bin/mymachinepw (limited to 'source4/scripting/bin') diff --git a/source4/scripting/bin/mymachinepw b/source4/scripting/bin/mymachinepw new file mode 100755 index 0000000000..d489dc4693 --- /dev/null +++ b/source4/scripting/bin/mymachinepw @@ -0,0 +1,45 @@ +#!/usr/bin/env python + +# Unix SMB/CIFS implementation. +# Copyright (C) Volker Lendecke 2008 +# +# Extract our own machine pw from secrets.ldb +# +# 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 3 of the License, or +# (at your option) any later version. +# +# This program 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 General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . +# + +import samba.param as param, ldb, sys, getopt + +optlist, args = getopt.getopt(sys.argv[1:], "s:") + +conf = param.LoadParm() +loaded = False + +for o, v in optlist: + if o == "-s": + if not conf.load(v): + raise(v + " not found") + loaded = True + +if not loaded: + conf.load_default() + +secrets = ldb.Ldb() +secrets.connect(conf.get("private dir") + "/secrets.ldb") + +search = "(&(objectclass=primaryDomain)(samaccountname=" + \ + conf.get("netbios name") + "$))" + +msg = secrets.search(expression=search, attrs=['secret']) +print(msg[0]['secret'][0]) -- cgit From 934cfb98809ff0200170ab1fc206af1312226cb0 Mon Sep 17 00:00:00 2001 From: Stefan Metzmacher Date: Sat, 26 Jul 2008 20:38:20 +0200 Subject: mamachinepw: add better error handling metze (This used to be commit 7ac424137f62ceacf44e477f4e3805267013005b) --- source4/scripting/bin/mymachinepw | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) (limited to 'source4/scripting/bin') diff --git a/source4/scripting/bin/mymachinepw b/source4/scripting/bin/mymachinepw index d489dc4693..49a4245a3a 100755 --- a/source4/scripting/bin/mymachinepw +++ b/source4/scripting/bin/mymachinepw @@ -2,6 +2,7 @@ # Unix SMB/CIFS implementation. # Copyright (C) Volker Lendecke 2008 +# Copyright (C) Stefan Metzmacher 2008 # # Extract our own machine pw from secrets.ldb # @@ -29,17 +30,32 @@ loaded = False for o, v in optlist: if o == "-s": if not conf.load(v): - raise(v + " not found") + print(v + " not found") + exit(1) loaded = True if not loaded: conf.load_default() +path=conf.get("private dir") + "/secrets.ldb" +netbios=conf.get("netbios name") + secrets = ldb.Ldb() -secrets.connect(conf.get("private dir") + "/secrets.ldb") +secrets.connect(path) search = "(&(objectclass=primaryDomain)(samaccountname=" + \ - conf.get("netbios name") + "$))" + netbios + "$))" msg = secrets.search(expression=search, attrs=['secret']) -print(msg[0]['secret'][0]) + +if not msg: + error = "Error:\n" + error += "Password for host[" + netbios + "] not found in path[" + path + "].\n" + error += "You may want to pass the smb.conf location via the -s option." + print error + exit(1) + +password=msg[0]['secret'][0]; + +print(password) +exit(0) -- cgit From ee505f36dddfe04a10fdc8fd8a8bd40d5fbfa218 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Wed, 30 Jul 2008 13:29:29 +0200 Subject: Be more pythonic. (This used to be commit 20d40e31942f96ca9d077e57c6dd4c1d38f79b4b) --- source4/scripting/bin/mymachinepw | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) (limited to 'source4/scripting/bin') diff --git a/source4/scripting/bin/mymachinepw b/source4/scripting/bin/mymachinepw index 49a4245a3a..3a843b5947 100755 --- a/source4/scripting/bin/mymachinepw +++ b/source4/scripting/bin/mymachinepw @@ -40,8 +40,7 @@ if not loaded: path=conf.get("private dir") + "/secrets.ldb" netbios=conf.get("netbios name") -secrets = ldb.Ldb() -secrets.connect(path) +secrets = ldb.Ldb(path) search = "(&(objectclass=primaryDomain)(samaccountname=" + \ netbios + "$))" @@ -49,13 +48,12 @@ search = "(&(objectclass=primaryDomain)(samaccountname=" + \ msg = secrets.search(expression=search, attrs=['secret']) if not msg: - error = "Error:\n" - error += "Password for host[" + netbios + "] not found in path[" + path + "].\n" - error += "You may want to pass the smb.conf location via the -s option." - print error + print "Error:" + print "Password for host[%s] not found in path[%s]." % (netbios, path) + print "You may want to pass the smb.conf location via the -s option." exit(1) -password=msg[0]['secret'][0]; +password=msg[0]['secret'][0] print(password) exit(0) -- cgit From faf83916ee62638e3eff60e68b4b7b36be2ddc05 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Tue, 9 Sep 2008 15:55:10 +0200 Subject: Add option for generating coverage data from python tests. (This used to be commit 43c0fdfff02021caef2d8f73d6bfdc4b051a65ef) --- source4/scripting/bin/subunitrun | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'source4/scripting/bin') diff --git a/source4/scripting/bin/subunitrun b/source4/scripting/bin/subunitrun index 6f1086ad37..ee2d1e11da 100755 --- a/source4/scripting/bin/subunitrun +++ b/source4/scripting/bin/subunitrun @@ -36,6 +36,8 @@ parser.add_option_group(credopts) sambaopts = options.SambaOptions(parser) parser.add_option_group(sambaopts) parser.add_option_group(options.VersionOptions(parser)) +parser.add_option("--coverage", metavar="CACHE", type=str, + help="Store coverage data in CACHE") args = parser.parse_args()[1] @@ -45,4 +47,10 @@ samba.tests.cmdline_credentials = credopts.get_credentials(samba.tests.cmdline_l param.cvar.default_config = samba.tests.cmdline_loadparm runner = SubunitTestRunner() +if opts.coverage is not None: + import coverage + coverage.use_cache(True, opts.coverage) + coverage.start() program = TestProgram(module=None, argv=[sys.argv[0]] + args, testRunner=runner) +if opts.coverage: + coverage.stop() -- cgit From fc23663f4b830709b65e03185a78ed917970b2b5 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Fri, 12 Sep 2008 21:28:48 +0200 Subject: Revert "Add option for generating coverage data from python tests." This reverts commit 43c0fdfff02021caef2d8f73d6bfdc4b051a65ef. (This used to be commit 696f30fff249656409f2efcc81b86a421d0c6880) --- source4/scripting/bin/subunitrun | 8 -------- 1 file changed, 8 deletions(-) (limited to 'source4/scripting/bin') diff --git a/source4/scripting/bin/subunitrun b/source4/scripting/bin/subunitrun index ee2d1e11da..6f1086ad37 100755 --- a/source4/scripting/bin/subunitrun +++ b/source4/scripting/bin/subunitrun @@ -36,8 +36,6 @@ parser.add_option_group(credopts) sambaopts = options.SambaOptions(parser) parser.add_option_group(sambaopts) parser.add_option_group(options.VersionOptions(parser)) -parser.add_option("--coverage", metavar="CACHE", type=str, - help="Store coverage data in CACHE") args = parser.parse_args()[1] @@ -47,10 +45,4 @@ samba.tests.cmdline_credentials = credopts.get_credentials(samba.tests.cmdline_l param.cvar.default_config = samba.tests.cmdline_loadparm runner = SubunitTestRunner() -if opts.coverage is not None: - import coverage - coverage.use_cache(True, opts.coverage) - coverage.start() program = TestProgram(module=None, argv=[sys.argv[0]] + args, testRunner=runner) -if opts.coverage: - coverage.stop() -- cgit