summaryrefslogtreecommitdiff
path: root/source/utils
diff options
context:
space:
mode:
authorGerald (Jerry) Carter <jerry@samba.org>2007-10-10 15:28:53 -0500
committerGerald (Jerry) Carter <jerry@samba.org>2007-10-10 15:28:53 -0500
commit65229e966119f0b1537d258854a54105f32ae399 (patch)
treec6be94324703d914228290a8354021c2691f3ebe /source/utils
parent95e77b14b5440a9ced8fdf6dc803b90c9518b8e0 (diff)
downloadsamba-65229e966119f0b1537d258854a54105f32ae399.tar.gz
[GLUE] Rsync SAMBA_3_0 SVN r25598 in order to create the v3-0-test branch.samba-misc-tags/initial-v3-0-test
Diffstat (limited to 'source/utils')
-rw-r--r--source/utils/net.c11
-rw-r--r--source/utils/net.h3
-rw-r--r--source/utils/net_ads.c82
-rw-r--r--source/utils/net_ads_gpo.c73
-rw-r--r--source/utils/net_conf.c1225
-rw-r--r--source/utils/net_domain.c84
-rw-r--r--source/utils/net_groupmap.c2
-rw-r--r--source/utils/net_help.c5
-rw-r--r--source/utils/net_idmap.c6
-rw-r--r--source/utils/net_rpc.c574
-rw-r--r--source/utils/net_rpc_join.c2
-rw-r--r--source/utils/net_rpc_printer.c28
-rw-r--r--source/utils/net_rpc_registry.c815
-rw-r--r--source/utils/net_rpc_rights.c12
-rw-r--r--source/utils/net_rpc_service.c20
-rw-r--r--source/utils/net_sam.c165
-rw-r--r--source/utils/net_status.c86
-rw-r--r--source/utils/net_util.c4
-rw-r--r--source/utils/netlookup.c4
-rw-r--r--source/utils/ntlm_auth.c60
-rw-r--r--source/utils/ntlm_auth_diagnostics.c54
-rw-r--r--source/utils/pdbedit.c9
-rw-r--r--source/utils/smbcacls.c25
-rw-r--r--source/utils/smbcontrol.c385
-rw-r--r--source/utils/smbcquotas.c9
-rw-r--r--source/utils/smbpasswd.c2
-rw-r--r--source/utils/smbtree.c34
-rw-r--r--source/utils/status.c123
-rw-r--r--source/utils/status_profile.c4
29 files changed, 1050 insertions, 2856 deletions
diff --git a/source/utils/net.c b/source/utils/net.c
index 628bd5ec1ed..a030531947a 100644
--- a/source/utils/net.c
+++ b/source/utils/net.c
@@ -85,7 +85,6 @@ int opt_attrs = 0;
int opt_timestamps = 0;
const char *opt_exclude = NULL;
const char *opt_destination = NULL;
-BOOL opt_testmode = False;
BOOL opt_have_ip = False;
struct in_addr opt_dest_ip;
@@ -603,7 +602,7 @@ static int net_getlocalsid(int argc, const char **argv)
name = global_myname();
}
- if(!initialize_password_db(False, NULL)) {
+ if(!initialize_password_db(False)) {
DEBUG(0, ("WARNING: Could not open passdb - local sid may not reflect passdb\n"
"backend knowlege (such as the sid stored in LDAP)\n"));
}
@@ -673,7 +672,7 @@ static int net_getdomainsid(int argc, const char **argv)
DOM_SID domain_sid;
fstring sid_str;
- if(!initialize_password_db(False, NULL)) {
+ if(!initialize_password_db(False)) {
DEBUG(0, ("WARNING: Could not open passdb - domain sid may not reflect passdb\n"
"backend knowlege (such as the sid stored in LDAP)\n"));
}
@@ -872,7 +871,6 @@ static struct functable net_func[] = {
{"STATUS", net_status},
{"USERSHARE", net_usershare},
{"USERSIDLIST", net_usersidlist},
- {"CONF", net_conf},
#ifdef WITH_FAKE_KASERVER
{"AFS", net_afs},
#endif
@@ -914,7 +912,6 @@ static struct functable net_func[] = {
{"machine-pass",'P', POPT_ARG_NONE, &opt_machine_pass},
{"myworkgroup", 'W', POPT_ARG_STRING, &opt_workgroup},
{"verbose", 'v', POPT_ARG_NONE, &opt_verbose},
- {"test", 'T', POPT_ARG_NONE, &opt_testmode},
/* Options for 'net groupmap set' */
{"local", 'L', POPT_ARG_NONE, &opt_localgroup},
{"domain", 'D', POPT_ARG_NONE, &opt_domaingroup},
@@ -1002,6 +999,10 @@ static struct functable net_func[] = {
opt_user_name = getenv("LOGNAME");
}
+ if (!opt_user_name) {
+ opt_user_name = "";
+ }
+
if (!opt_workgroup) {
opt_workgroup = smb_xstrdup(lp_workgroup());
}
diff --git a/source/utils/net.h b/source/utils/net.h
index 3739abdad7e..d037871f82e 100644
--- a/source/utils/net.h
+++ b/source/utils/net.h
@@ -67,8 +67,6 @@ enum netdom_domain_t { ND_TYPE_NT4, ND_TYPE_AD };
/* INCLUDE FILES */
#include "utils/net_proto.h"
-#include "libmsrpc.h"
-
/* MACROS & DEFINES */
@@ -114,7 +112,6 @@ extern int opt_attrs;
extern int opt_timestamps;
extern const char *opt_exclude;
extern const char *opt_destination;
-extern BOOL opt_testmode;
extern BOOL opt_have_ip;
extern struct in_addr opt_dest_ip;
diff --git a/source/utils/net_ads.c b/source/utils/net_ads.c
index 29d7e386d87..75b631c351f 100644
--- a/source/utils/net_ads.c
+++ b/source/utils/net_ads.c
@@ -1190,50 +1190,28 @@ done:
static ADS_STATUS net_precreate_machine_acct( ADS_STRUCT *ads, const char *ou )
{
ADS_STATUS rc = ADS_ERROR(LDAP_SERVER_DOWN);
- char *ou_str = NULL;
- char *dn = NULL;
+ char *dn, *ou_str;
LDAPMessage *res = NULL;
- BOOL moved;
ou_str = ads_ou_string(ads, ou);
- if (asprintf(&dn, "%s,%s", ou_str, ads->config.bind_path) == -1) {
- rc = ADS_ERROR(LDAP_NO_MEMORY);
- goto done;
+ if ((asprintf(&dn, "%s,%s", ou_str, ads->config.bind_path)) == -1) {
+ SAFE_FREE(ou_str);
+ return ADS_ERROR(LDAP_NO_MEMORY);
}
rc = ads_search_dn(ads, &res, dn, NULL);
- if (!ADS_ERR_OK(rc)) {
- d_fprintf(stderr, "The specified OU does not exist.\n");
- goto done;
- }
+ ads_msgfree(ads, res);
+ if (ADS_ERR_OK(rc)) {
/* Attempt to create the machine account and bail if this fails.
Assume that the admin wants exactly what they requested */
rc = ads_create_machine_acct( ads, global_myname(), dn );
- if (ADS_ERR_OK(rc)) {
- DEBUG(1, ("machine account created\n"));
- goto done;
+ if ( rc.error_type == ENUM_ADS_ERROR_LDAP && rc.err.rc == LDAP_ALREADY_EXISTS ) {
+ rc = ADS_SUCCESS;
}
- if ( !(rc.error_type == ENUM_ADS_ERROR_LDAP && rc.err.rc == LDAP_ALREADY_EXISTS) ) {
- DEBUG(1, ("machine account creation failed\n"));
- goto done;
- }
-
- rc = ads_move_machine_acct(ads, global_myname(), dn, &moved);
- if (!ADS_ERR_OK(rc)) {
- DEBUG(1, ("failure to locate/move pre-existing machine account\n"));
- goto done;
}
- if (moved) {
- d_printf("The machine account was moved into the specified OU.\n");
- } else {
- d_printf("The machine account already exists in the specified OU.\n");
- }
-
-done:
- ads_msgfree(ads, res);
SAFE_FREE( ou_str );
SAFE_FREE( dn );
@@ -1369,10 +1347,10 @@ static NTSTATUS net_update_dns_internal(TALLOC_CTX *ctx, ADS_STRUCT *ads,
status = ads_dns_lookup_ns( ctx, root_domain, &nameservers, &ns_count );
if ( !NT_STATUS_IS_OK(status) || (ns_count == 0)) {
- DEBUG(3,("net_ads_join: Failed to find name server for the %s "
+ DEBUG(3,("net_ads_join: Failed to find name server for the %s "
"realm\n", ads->config.realm));
- goto done;
- }
+ goto done;
+ }
dnsdomain = root_domain;
@@ -1450,12 +1428,7 @@ static int net_ads_join_usage(int argc, const char **argv)
d_printf(" The OU string read from top to bottom without RDNs and delimited by a '/'.\n");
d_printf(" E.g. \"createcomputer=Computers/Servers/Unix\"\n");
d_printf(" NB: A backslash '\\' is used as escape at multiple levels and may\n");
- d_printf(" need to be doubled or even quadrupled. It is not used as a separator.\n");
- d_printf(" osName=string Set the operatingSystem attribute during the join.\n");
- d_printf(" osVer=string Set the operatingSystemVersion attribute during the join.\n");
- d_printf(" NB: osName and osVer must be specified together for either to take effect.\n");
- d_printf(" Also, the operatingSystemService attribute is also set when along with\n");
- d_printf(" the two other attributes.\n");
+ d_printf(" need to be doubled or even quadrupled. It is not used as a separator");
return -1;
}
@@ -1555,7 +1528,7 @@ int net_ads_join(int argc, const char **argv)
status = net_precreate_machine_acct( ads, create_in_ou );
if ( !ADS_ERR_OK(status) ) {
d_fprintf( stderr, "Failed to pre-create the machine object "
- "in OU %s.\n", create_in_ou);
+ "in OU %s.\n", argv[0]);
DEBUG(1, ("error calling net_precreate_machine_acct: %s\n",
ads_errstr(status)));
nt_status = ads_ntstatus(status);
@@ -1747,7 +1720,7 @@ static int net_ads_dns_register(int argc, const char **argv)
#endif
if (argc > 0) {
- d_fprintf(stderr, "net ads dns register <name> <ip>\n");
+ d_fprintf(stderr, "net ads dns register\n");
return -1;
}
@@ -1921,6 +1894,12 @@ static int net_ads_printer_info(int argc, const char **argv)
return 0;
}
+void do_drv_upgrade_printer(int msg_type, struct process_id src,
+ void *buf, size_t len, void *private_data)
+{
+ return;
+}
+
static int net_ads_printer_publish(int argc, const char **argv)
{
ADS_STRUCT *ads;
@@ -2418,18 +2397,16 @@ static int net_ads_keytab_usage(int argc, const char **argv)
d_printf(
"net ads keytab <COMMAND>\n"\
"<COMMAND> can be either:\n"\
-" ADD Adds new service principal\n"\
" CREATE Creates a fresh keytab\n"\
+" ADD Adds new service principal\n"\
" FLUSH Flushes out all keytab entries\n"\
" HELP Prints this help message\n"\
-" LIST List the keytab\n"\
-"The ADD and LIST command will take arguments, the other commands\n"\
+"The ADD command will take arguments, the other commands\n"\
"will not take any arguments. The arguments given to ADD\n"\
"should be a list of principals to add. For example, \n"\
" net ads keytab add srv1 srv2\n"\
"will add principals for the services srv1 and srv2 to the\n"\
"system's keytab.\n"\
-"The LIST command takes a keytabname.\n"\
"\n"
);
return -1;
@@ -2478,26 +2455,13 @@ static int net_ads_keytab_create(int argc, const char **argv)
return ret;
}
-static int net_ads_keytab_list(int argc, const char **argv)
-{
- const char *keytab = NULL;
-
- if (argc >= 1) {
- keytab = argv[0];
- }
-
- return ads_keytab_list(keytab);
-}
-
-
int net_ads_keytab(int argc, const char **argv)
{
struct functable func[] = {
- {"ADD", net_ads_keytab_add},
{"CREATE", net_ads_keytab_create},
+ {"ADD", net_ads_keytab_add},
{"FLUSH", net_ads_keytab_flush},
{"HELP", net_ads_keytab_usage},
- {"LIST", net_ads_keytab_list},
{NULL, NULL}
};
diff --git a/source/utils/net_ads_gpo.c b/source/utils/net_ads_gpo.c
index be5406af17d..83cc2fe8fcf 100644
--- a/source/utils/net_ads_gpo.c
+++ b/source/utils/net_ads_gpo.c
@@ -46,8 +46,11 @@ static int net_ads_gpo_refresh(int argc, const char **argv)
TALLOC_CTX *mem_ctx;
ADS_STRUCT *ads;
ADS_STATUS status;
- const char *dn = NULL;
- struct GROUP_POLICY_OBJECT *gpo_list = NULL;
+ const char *attrs[] = { "userAccountControl", NULL };
+ LDAPMessage *res = NULL;
+ const char *filter;
+ char *dn = NULL;
+ struct GROUP_POLICY_OBJECT *gpo_list;
uint32 uac = 0;
uint32 flags = 0;
struct GROUP_POLICY_OBJECT *gpo;
@@ -63,14 +66,35 @@ static int net_ads_gpo_refresh(int argc, const char **argv)
return -1;
}
+ filter = talloc_asprintf(mem_ctx, "(&(objectclass=user)(sAMAccountName=%s))", argv[0]);
+ if (filter == NULL) {
+ goto out;
+ }
+
status = ads_startup(False, &ads);
if (!ADS_ERR_OK(status)) {
goto out;
}
- status = ads_find_samaccount(ads, mem_ctx, argv[0], &uac, &dn);
+ status = ads_do_search_all(ads, ads->config.bind_path,
+ LDAP_SCOPE_SUBTREE,
+ filter, attrs, &res);
+
if (!ADS_ERR_OK(status)) {
- printf("failed to find samaccount for %s\n", argv[0]);
+ goto out;
+ }
+
+ if (ads_count_replies(ads, res) != 1) {
+ printf("no result\n");
+ goto out;
+ }
+
+ dn = ads_get_dn(ads, res);
+ if (dn == NULL) {
+ goto out;
+ }
+
+ if (!ads_pull_uint32(ads, res, "userAccountControl", &uac)) {
goto out;
}
@@ -103,8 +127,8 @@ static int net_ads_gpo_refresh(int argc, const char **argv)
GPO_VERSION_USER(gpo->version),
GPO_VERSION_MACHINE(gpo->version));
- result = gpo_explode_filesyspath(mem_ctx, gpo->file_sys_path,
- &server, &share, &nt_path, &unix_path);
+ result = ads_gpo_explode_filesyspath(ads, mem_ctx, gpo->file_sys_path,
+ &server, &share, &nt_path, &unix_path);
if (!NT_STATUS_IS_OK(result)) {
printf("got: %s\n", nt_errstr(result));
}
@@ -115,6 +139,9 @@ static int net_ads_gpo_refresh(int argc, const char **argv)
}
out:
+ ads_memfree(ads, dn);
+ ads_msgfree(ads, res);
+
ads_destroy(&ads);
talloc_destroy(mem_ctx);
return 0;
@@ -198,7 +225,10 @@ static int net_ads_gpo_apply(int argc, const char **argv)
TALLOC_CTX *mem_ctx;
ADS_STRUCT *ads;
ADS_STATUS status;
- const char *dn = NULL;
+ const char *attrs[] = {"distinguishedName", "userAccountControl", NULL};
+ LDAPMessage *res = NULL;
+ const char *filter;
+ char *dn = NULL;
struct GROUP_POLICY_OBJECT *gpo_list;
uint32 uac = 0;
uint32 flags = 0;
@@ -213,16 +243,38 @@ static int net_ads_gpo_apply(int argc, const char **argv)
goto out;
}
+ filter = talloc_asprintf(mem_ctx, "(&(objectclass=user)(sAMAccountName=%s))", argv[0]);
+ if (filter == NULL) {
+ goto out;
+ }
+
status = ads_startup(False, &ads);
if (!ADS_ERR_OK(status)) {
goto out;
}
- status = ads_find_samaccount(ads, mem_ctx, argv[0], &uac, &dn);
+ status = ads_do_search_all(ads, ads->config.bind_path,
+ LDAP_SCOPE_SUBTREE,
+ filter, attrs, &res);
+
if (!ADS_ERR_OK(status)) {
goto out;
}
+ if (ads_count_replies(ads, res) != 1) {
+ printf("no result\n");
+ goto out;
+ }
+
+ dn = ads_get_dn(ads, res);
+ if (dn == NULL) {
+ goto out;
+ }
+
+ if (!ads_pull_uint32(ads, res, "userAccountControl", &uac)) {
+ goto out;
+ }
+
if (uac & UF_WORKSTATION_TRUST_ACCOUNT) {
flags |= GPO_LIST_FLAG_MACHINE;
}
@@ -237,12 +289,15 @@ static int net_ads_gpo_apply(int argc, const char **argv)
}
/* FIXME: allow to process just a single extension */
- status = gpo_process_gpo_list(ads, mem_ctx, gpo_list, NULL, flags);
+ status = gpo_process_gpo_list(ads, mem_ctx, &gpo_list, NULL, flags);
if (!ADS_ERR_OK(status)) {
goto out;
}
out:
+ ads_memfree(ads, dn);
+ ads_msgfree(ads, res);
+
ads_destroy(&ads);
talloc_destroy(mem_ctx);
return 0;
diff --git a/source/utils/net_conf.c b/source/utils/net_conf.c
deleted file mode 100644
index 61bcb60aaf1..00000000000
--- a/source/utils/net_conf.c
+++ /dev/null
@@ -1,1225 +0,0 @@
-/*
- * Samba Unix/Linux SMB client library
- * Distributed SMB/CIFS Server Management Utility
- * Local configuration interface
- * Copyright (C) Michael Adam 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 2 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, write to the Free Software
- * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
- */
-
-/*
- * This is an interface to the configuration stored inside the
- * samba registry. In the future there might be support for other
- * configuration backends as well.
- */
-
-#include "includes.h"
-#include "utils/net.h"
-
-/*
- * usage functions
- */
-
-static int net_conf_list_usage(int argc, const char **argv)
-{
- d_printf("USAGE: net conf list\n");
- return -1;
-}
-
-static int net_conf_import_usage(int argc, const char**argv)
-{
- d_printf("USAGE: net conf import [--test|-T] <filename> [<servicename>]\n"
- "\t[--test|-T] testmode - do not act, just print "
- "what would be done\n"
- "\t<servicename> only import service <servicename>, "
- "ignore the rest\n");
- return -1;
-}
-
-static int net_conf_listshares_usage(int argc, const char **argv)
-{
- d_printf("USAGE: net conf listshares\n");
- return -1;
-}
-
-static int net_conf_drop_usage(int argc, const char **argv)
-{
- d_printf("USAGE: net conf drop\n");
- return -1;
-}
-
-static int net_conf_showshare_usage(int argc, const char **argv)
-{
- d_printf("USAGE: net conf showshare <sharename>\n");
- return -1;
-}
-
-static int net_conf_addshare_usage(int argc, const char **argv)
-{
- d_printf("USAGE: net conf addshare <sharename> <path> "
- "[writeable={y|N} [guest_ok={y|N} [<comment>]]\n"
- "\t<sharename> the new share name.\n"
- "\t<path> the path on the filesystem to export.\n"
- "\twriteable={y|N} set \"writeable to \"yes\" or "
- "\"no\" (default) on this share.\n"
- "\tguest_ok={y|N} set \"guest ok\" to \"yes\" or "
- "\"no\" (default) on this share.\n"
- "\t<comment> optional comment for the new share.\n");
- return -1;
-}
-
-static int net_conf_delshare_usage(int argc, const char **argv)
-{
- d_printf("USAGE: net conf delshare <sharename>\n");
- return -1;
-}
-
-static int net_conf_setparm_usage(int argc, const char **argv)
-{
- d_printf("USAGE: net conf setparm <section> <param> <value>\n");
- return -1;
-}
-
-static int net_conf_getparm_usage(int argc, const char **argv)
-{
- d_printf("USAGE: net conf getparm <section> <param>\n");
- return -1;
-}
-
-static int net_conf_delparm_usage(int argc, const char **argv)
-{
- d_printf("USAGE: net conf delparm <section> <param>\n");
- return -1;
-}
-
-
-/*
- * Helper functions
- */
-
-static char *format_value(TALLOC_CTX *mem_ctx, struct registry_value *value)
-{
- char *result = NULL;
-
- /* what if mem_ctx = NULL? */
-
- switch (value->type) {
- case REG_DWORD:
- result = talloc_asprintf(mem_ctx, "%d", value->v.dword);
- break;
- case REG_SZ:
- case REG_EXPAND_SZ:
- result = talloc_asprintf(mem_ctx, "%s", value->v.sz.str);
- break;
- case REG_MULTI_SZ: {
- uint32 j;
- for (j = 0; j < value->v.multi_sz.num_strings; j++) {
- result = talloc_asprintf(mem_ctx, "\"%s\" ",
- value->v.multi_sz.strings[j]);
- }
- break;
- }
- case REG_BINARY:
- result = talloc_asprintf(mem_ctx, "binary (%d bytes)",
- (int)value->v.binary.length);
- break;
- default:
- result = talloc_asprintf(mem_ctx, "<unprintable>");
- break;
- }
- return result;
-}
-
-/*
- * add a value to a key.
- */
-static WERROR reg_setvalue_internal(struct registry_key *key,
- const char *valname,
- const char *valstr)
-{
- struct registry_value val;
- WERROR werr = WERR_OK;
- char *subkeyname;
-
- ZERO_STRUCT(val);
-
- val.type = REG_SZ;
- val.v.sz.str = CONST_DISCARD(char *, valstr);
- val.v.sz.len = strlen(valstr) + 1;
-
- if (!lp_parameter_is_valid(valname)) {
- d_fprintf(stderr, "Invalid parameter '%s' given.\n", valname);
- werr = WERR_INVALID_PARAM;
- goto done;
- }
-
- if (registry_smbconf_valname_forbidden(valname)) {
- d_fprintf(stderr, "Parameter '%s' not allowed in registry.\n",
- valname);
- werr = WERR_INVALID_PARAM;
- goto done;
- }
-
- subkeyname = strrchr_m(key->key->name, '\\');
- if ((subkeyname == NULL) || (*(subkeyname +1) == '\0')) {
- d_fprintf(stderr, "Invalid registry key '%s' given as "
- "smbconf section.\n", key->key->name);
- werr = WERR_INVALID_PARAM;
- goto done;
- }
- subkeyname++;
- if (!strequal(subkeyname, GLOBAL_NAME) &&
- lp_parameter_is_global(valname))
- {
- d_fprintf(stderr, "Global paramter '%s' not allowed in "
- "service definition ('%s').\n", valname,
- subkeyname);
- werr = WERR_INVALID_PARAM;
- goto done;
- }
-
- werr = reg_setvalue(key, valname, &val);
- if (!W_ERROR_IS_OK(werr)) {
- d_fprintf(stderr,
- "Error adding value '%s' to "
- "key '%s': %s\n",
- valname, key->key->name, dos_errstr(werr));
- }
-
-done:
- return werr;
-}
-
-/*
- * Open a subkey of KEY_SMBCONF (i.e a service)
- * - variant without error output (q = quiet)-
- */
-static WERROR smbconf_open_path_q(TALLOC_CTX *ctx, const char *subkeyname,
- uint32 desired_access,
- struct registry_key **key)
-{
- WERROR werr = WERR_OK;
- char *path = NULL;
- NT_USER_TOKEN *token;
-
- if (!(token = registry_create_admin_token(ctx))) {
- DEBUG(1, ("Error creating admin token\n"));
- goto done;
- }
-
- if (subkeyname == NULL) {
- path = talloc_strdup(ctx, KEY_SMBCONF);
- }
- else {
- path = talloc_asprintf(ctx, "%s\\%s", KEY_SMBCONF, subkeyname);
- }
-
- werr = reg_open_path(ctx, path, desired_access,
- token, key);
-
-done:
- TALLOC_FREE(path);
- return werr;
-}
-
-/*
- * Open a subkey of KEY_SMBCONF (i.e a service)
- * - variant with error output -
- */
-static WERROR smbconf_open_path(TALLOC_CTX *ctx, const char *subkeyname,
- uint32 desired_access,
- struct registry_key **key)
-{
- WERROR werr = WERR_OK;
-
- werr = smbconf_open_path_q(ctx, subkeyname, desired_access, key);
- if (!W_ERROR_IS_OK(werr)) {
- d_fprintf(stderr, "Error opening registry path '%s\\%s': %s\n",
- KEY_SMBCONF,
- (subkeyname == NULL) ? "" : subkeyname,
- dos_errstr(werr));
- }
-
- return werr;
-}
-
-/*
- * open the base key KEY_SMBCONF
- */
-static WERROR smbconf_open_basepath(TALLOC_CTX *ctx, uint32 desired_access,
- struct registry_key **key)
-{
- return smbconf_open_path(ctx, NULL, desired_access, key);
-}
-
-/*
- * delete a subkey of KEY_SMBCONF
- */
-static WERROR reg_delkey_internal(TALLOC_CTX *ctx, const char *keyname)
-{
- WERROR werr = WERR_OK;
- struct registry_key *key = NULL;
-
- werr = smbconf_open_basepath(ctx, REG_KEY_WRITE, &key);
- if (!W_ERROR_IS_OK(werr)) {
- goto done;
- }
-
- werr = reg_deletekey_recursive(key, key, keyname);
- if (!W_ERROR_IS_OK(werr)) {
- d_fprintf(stderr, "Error deleting registry key %s\\%s: %s\n",
- KEY_SMBCONF, keyname, dos_errstr(werr));
- }
-
-done:
- TALLOC_FREE(key);
- return werr;
-}
-
-/*
- * create a subkey of KEY_SMBCONF
- */
-static WERROR reg_createkey_internal(TALLOC_CTX *ctx,
- const char * subkeyname,
- struct registry_key **newkey)
-{
- WERROR werr = WERR_OK;
- struct registry_key *create_parent = NULL;
- TALLOC_CTX *create_ctx;
- enum winreg_CreateAction action = REG_ACTION_NONE;
-
- /* create a new talloc ctx for creation. it will hold
- * the intermediate parent key (SMBCONF) for creation
- * and will be destroyed when leaving this function... */
- if (!(create_ctx = talloc_new(ctx))) {
- werr = WERR_NOMEM;
- goto done;
- }
-
- werr = smbconf_open_basepath(create_ctx, REG_KEY_WRITE, &create_parent);
- if (!W_ERROR_IS_OK(werr)) {
- goto done;
- }
-
- werr = reg_createkey(ctx, create_parent, subkeyname,
- REG_KEY_WRITE, newkey, &action);
- if (W_ERROR_IS_OK(werr) && (action != REG_CREATED_NEW_KEY)) {
- d_fprintf(stderr, "Key '%s' already exists.\n", subkeyname);
- werr = WERR_ALREADY_EXISTS;
- }
- if (!W_ERROR_IS_OK(werr)) {
- d_fprintf(stderr, "Error creating key %s: %s\n",
- subkeyname, dos_errstr(werr));
- }
-
-done:
- TALLOC_FREE(create_ctx);
- return werr;
-}
-
-/*
- * check if a subkey of KEY_SMBCONF of a given name exists
- */
-static BOOL smbconf_key_exists(TALLOC_CTX *ctx, const char *subkeyname)
-{
- BOOL ret = False;
- WERROR werr = WERR_OK;
- TALLOC_CTX *mem_ctx;
- struct registry_key *key;
-
- if (!(mem_ctx = talloc_new(ctx))) {
- d_fprintf(stderr, "ERROR: Out of memory...!\n");
- goto done;
- }
-
- werr = smbconf_open_path_q(mem_ctx, subkeyname, REG_KEY_READ, &key);
- if (W_ERROR_IS_OK(werr)) {
- ret = True;
- }
-
-done:
- TALLOC_FREE(mem_ctx);
- return ret;
-}
-
-static BOOL smbconf_value_exists(TALLOC_CTX *ctx, struct registry_key *key,
- const char *param)
-{
- BOOL ret = False;
- WERROR werr = WERR_OK;
- struct registry_value *value = NULL;
-
- werr = reg_queryvalue(ctx, key, param, &value);
- if (W_ERROR_IS_OK(werr)) {
- ret = True;
- }
-
- TALLOC_FREE(value);
- return ret;
-}
-
-static WERROR list_values(TALLOC_CTX *ctx, struct registry_key *key)
-{
- WERROR werr = WERR_OK;
- uint32 idx = 0;
- struct registry_value *valvalue = NULL;
- char *valname = NULL;
-
- for (idx = 0;
- W_ERROR_IS_OK(werr = reg_enumvalue(ctx, key, idx, &valname,
- &valvalue));
- idx++)
- {
- d_printf("\t%s = %s\n", valname, format_value(ctx, valvalue));
- }
- if (!W_ERROR_EQUAL(WERR_NO_MORE_ITEMS, werr)) {
- d_fprintf(stderr, "Error enumerating values: %s\n",
- dos_errstr(werr));
- goto done;
- }
- werr = WERR_OK;
-
-done:
- return werr;
-}
-
-static WERROR drop_smbconf_internal(TALLOC_CTX *ctx)
-{
- char *path, *p;
- WERROR werr = WERR_OK;
- NT_USER_TOKEN *token;
- struct registry_key *parent_key = NULL;
- struct registry_key *new_key = NULL;
- TALLOC_CTX* tmp_ctx = NULL;
- enum winreg_CreateAction action;
-
- tmp_ctx = talloc_new(ctx);
- if (tmp_ctx == NULL) {
- werr = WERR_NOMEM;
- goto done;
- }
-
- if (!(token = registry_create_admin_token(tmp_ctx))) {
- /* what is the appropriate error code here? */
- werr = WERR_CAN_NOT_COMPLETE;
- goto done;
- }
-
- path = talloc_strdup(tmp_ctx, KEY_SMBCONF);
- if (path == NULL) {
- d_fprintf(stderr, "ERROR: out of memory!\n");
- werr = WERR_NOMEM;
- goto done;
- }
- p = strrchr(path, '\\');
- *p = '\0';
- werr = reg_open_path(tmp_ctx, path, REG_KEY_WRITE, token, &parent_key);
-
- if (!W_ERROR_IS_OK(werr)) {
- goto done;
- }
-
- werr = reg_deletekey_recursive(tmp_ctx, parent_key, p+1);
-
- if (!W_ERROR_IS_OK(werr)) {
- goto done;
- }
-
- werr = reg_createkey(tmp_ctx, parent_key, p+1, REG_KEY_WRITE,
- &new_key, &action);
-
-done:
- TALLOC_FREE(tmp_ctx);
- return werr;
-}
-
-static char *parm_valstr(TALLOC_CTX *ctx, struct parm_struct *parm,
- struct share_params *share)
-{
- char *valstr = NULL;
- int i = 0;
- void *ptr = parm->ptr;
-
- if (parm->p_class == P_LOCAL && share->service >= 0) {
- ptr = lp_local_ptr(share->service, ptr);
- }
-
- switch (parm->type) {
- case P_CHAR:
- valstr = talloc_asprintf(ctx, "%c", *(char *)ptr);
- break;
- case P_STRING:
- case P_USTRING:
- valstr = talloc_asprintf(ctx, "%s", *(char **)ptr);
- break;
- case P_GSTRING:
- case P_UGSTRING:
- valstr = talloc_asprintf(ctx, "%s", (char *)ptr);
- break;
- case P_BOOL:
- valstr = talloc_asprintf(ctx, "%s", BOOLSTR(*(BOOL *)ptr));
- break;
- case P_BOOLREV:
- valstr = talloc_asprintf(ctx, "%s", BOOLSTR(!*(BOOL *)ptr));
- break;
- case P_ENUM:
- for (i = 0; parm->enum_list[i].name; i++) {
- if (*(int *)ptr == parm->enum_list[i].value)
- {
- valstr = talloc_asprintf(ctx, "%s",
- parm->enum_list[i].name);
- break;
- }
- }
- break;
- case P_OCTAL:
- valstr = talloc_asprintf(ctx, "%s", octal_string(*(int *)ptr));
- break;
- case P_LIST:
- valstr = talloc_strdup(ctx, "");
- if ((char ***)ptr && *(char ***)ptr) {
- char **list = *(char ***)ptr;
- for (; *list; list++) {
- /* surround strings with whitespace
- * in double quotes */
- if (strchr_m(*list, ' '))
- {
- valstr = talloc_asprintf_append(
- valstr, "\"%s\"%s",
- *list,
- ((*(list+1))?", ":""));
- }
- else {
- valstr = talloc_asprintf_append(
- valstr, "%s%s", *list,
- ((*(list+1))?", ":""));
- }
- }
- }
- break;
- case P_INTEGER:
- valstr = talloc_asprintf(ctx, "%d", *(int *)ptr);
- break;
- case P_SEP:
- break;
- default:
- valstr = talloc_asprintf(ctx, "<type unimplemented>\n");
- break;
- }
-
- return valstr;
-}
-
-static int import_process_service(TALLOC_CTX *ctx,
- struct share_params *share)
-{
- int ret = -1;
- struct parm_struct *parm;
- int pnum = 0;
- const char *servicename;
- struct registry_key *key;
- WERROR werr;
- char *valstr = NULL;
- TALLOC_CTX *tmp_ctx = NULL;
-
- tmp_ctx = talloc_new(ctx);
- if (tmp_ctx == NULL) {
- werr = WERR_NOMEM;
- goto done;
- }
-
- servicename = (share->service == GLOBAL_SECTION_SNUM)?
- GLOBAL_NAME : lp_servicename(share->service);
-
- if (opt_testmode) {
- d_printf("[%s]\n", servicename);
- }
- else {
- if (smbconf_key_exists(tmp_ctx, servicename)) {
- werr = reg_delkey_internal(tmp_ctx, servicename);
- if (!W_ERROR_IS_OK(werr)) {
- goto done;
- }
- }
- werr = reg_createkey_internal(tmp_ctx, servicename, &key);
- if (!W_ERROR_IS_OK(werr)) {
- goto done;
- }
- }
-
- while ((parm = lp_next_parameter(share->service, &pnum, 0)))
- {
- if ((share->service < 0 && parm->p_class == P_LOCAL)
- && !(parm->flags & FLAG_GLOBAL))
- continue;
-
- valstr = parm_valstr(tmp_ctx, parm, share);
-
- if (parm->type != P_SEP) {
- if (opt_testmode) {
- d_printf("\t%s = %s\n", parm->label, valstr);
- }
- else {
- werr = reg_setvalue_internal(key, parm->label,
- valstr);
- if (!W_ERROR_IS_OK(werr)) {
- goto done;
- }
- }
- }
- }
-
- if (opt_testmode) {
- d_printf("\n");
- }
-
- ret = 0;
-
-done:
- TALLOC_FREE(tmp_ctx);
- return ret;
-}
-
-/* return True iff there are nondefault globals */
-static BOOL globals_exist(void)
-{
- int i = 0;
- struct parm_struct *parm;
-
- while ((parm = lp_next_parameter(GLOBAL_SECTION_SNUM, &i, 0)) != NULL) {
- if (parm->type != P_SEP) {
- return True;
- }
- }
- return False;
-}
-
-/*
- * the conf functions
- */
-
-int net_conf_list(int argc, const char **argv)
-{
- WERROR werr = WERR_OK;
- int ret = -1;
- TALLOC_CTX *ctx;
- struct registry_key *base_key = NULL;
- struct registry_key *sub_key = NULL;
- uint32 idx_key = 0;
- char *subkey_name = NULL;
-
- ctx = talloc_init("list");
-
- if (argc != 0) {
- net_conf_list_usage(argc, argv);
- goto done;
- }
-
- werr = smbconf_open_basepath(ctx, REG_KEY_READ, &base_key);
- if (!W_ERROR_IS_OK(werr)) {
- goto done;
- }
-
- if (smbconf_key_exists(ctx, GLOBAL_NAME)) {
- werr = reg_openkey(ctx, base_key, GLOBAL_NAME,
- REG_KEY_READ, &sub_key);
- if (!W_ERROR_IS_OK(werr)) {
- d_fprintf(stderr, "Error opening subkey '%s' : %s\n",
- subkey_name, dos_errstr(werr));
- goto done;
- }
- d_printf("[%s]\n", GLOBAL_NAME);
- if (!W_ERROR_IS_OK(list_values(ctx, sub_key))) {
- goto done;
- }
- d_printf("\n");
- }
-
- for (idx_key = 0;
- W_ERROR_IS_OK(werr = reg_enumkey(ctx, base_key, idx_key,
- &subkey_name, NULL));
- idx_key++)
- {
- if (strequal(subkey_name, GLOBAL_NAME)) {
- continue;
- }
- d_printf("[%s]\n", subkey_name);
-
- werr = reg_openkey(ctx, base_key, subkey_name,
- REG_KEY_READ, &sub_key);
- if (!W_ERROR_IS_OK(werr)) {
- d_fprintf(stderr,
- "Error opening subkey '%s': %s\n",
- subkey_name, dos_errstr(werr));
- goto done;
- }
- if (!W_ERROR_IS_OK(list_values(ctx, sub_key))) {
- goto done;
- }
- d_printf("\n");
- }
- if (!W_ERROR_EQUAL(WERR_NO_MORE_ITEMS, werr)) {
- d_fprintf(stderr, "Error enumerating subkeys: %s\n",
- dos_errstr(werr));
- goto done;
- }
-
- ret = 0;
-
-done:
- TALLOC_FREE(ctx);
- return ret;
-}
-
-int net_conf_import(int argc, const char **argv)
-{
- int ret = -1;
- const char *filename = NULL;
- const char *servicename = NULL;
- BOOL service_found = False;
- TALLOC_CTX *ctx;
- struct share_iterator *shares;
- struct share_params *share;
- struct share_params global_share = { GLOBAL_SECTION_SNUM };
-
- ctx = talloc_init("net_conf_import");
-
- switch (argc) {
- case 0:
- default:
- net_conf_import_usage(argc, argv);
- goto done;
- case 2:
- servicename = argv[1];
- case 1:
- filename = argv[0];
- break;
- }
-
- DEBUG(3,("net_conf_import: reading configuration from file %s.\n",
- filename));
-
- if (!lp_load(filename,
- False, /* global_only */
- True, /* save_defaults */
- False, /* add_ipc */
- True)) /* initialize_globals */
- {
- d_fprintf(stderr, "Error parsing configuration file.\n");
- goto done;
- }
-
- if (opt_testmode) {
- d_printf("\nTEST MODE - "
- "would import the following configuration:\n\n");
- }
-
- if (((servicename == NULL) && globals_exist()) ||
- strequal(servicename, GLOBAL_NAME))
- {
- service_found = True;
- if (import_process_service(ctx, &global_share) != 0) {
- goto done;
- }
- }
-
- if (service_found && (servicename != NULL)) {
- ret = 0;
- goto done;
- }
-
- if (!(shares = share_list_all(ctx))) {
- d_fprintf(stderr, "Could not list shares...\n");
- goto done;
- }
- while ((share = next_share(shares)) != NULL) {
- if ((servicename == NULL)
- || strequal(servicename, lp_servicename(share->service)))
- {
- service_found = True;
- if (import_process_service(ctx, share)!= 0) {
- goto done;
- }
- }
- }
-
- if ((servicename != NULL) && !service_found) {
- d_printf("Share %s not found in file %s\n",
- servicename, filename);
- goto done;
-
- }
-
- ret = 0;
-
-done:
- TALLOC_FREE(ctx);
- return ret;
-}
-
-int net_conf_listshares(int argc, const char **argv)
-{
- WERROR werr = WERR_OK;
- int ret = -1;
- struct registry_key *key;
- uint32 idx = 0;
- char *subkey_name = NULL;
- TALLOC_CTX *ctx;
-
- ctx = talloc_init("listshares");
-
- if (argc != 0) {
- net_conf_listshares_usage(argc, argv);
- goto done;
- }
-
- werr = smbconf_open_basepath(ctx, SEC_RIGHTS_ENUM_SUBKEYS, &key);
- if (!W_ERROR_IS_OK(werr)) {
- goto done;
- }
-
- for (idx = 0;
- W_ERROR_IS_OK(werr = reg_enumkey(ctx, key, idx,
- &subkey_name, NULL));
- idx++)
- {
- d_printf("%s\n", subkey_name);
- }
- if (! W_ERROR_EQUAL(WERR_NO_MORE_ITEMS, werr)) {
- d_fprintf(stderr, "Error enumerating subkeys: %s\n",
- dos_errstr(werr));
- goto done;
- }
-
- ret = 0;
-
-done:
- TALLOC_FREE(ctx);
- return ret;
-}
-
-int net_conf_drop(int argc, const char **argv)
-{
- int ret = -1;
- WERROR werr;
-
- if (argc != 0) {
- net_conf_drop_usage(argc, argv);
- goto done;
- }
-
- werr = drop_smbconf_internal(NULL);
- if (!W_ERROR_IS_OK(werr)) {
- d_fprintf(stderr, "Error deleting configuration: %s\n",
- dos_errstr(werr));
- goto done;
- }
-
- ret = 0;
-
-done:
- return ret;
-}
-
-int net_conf_showshare(int argc, const char **argv)
-{
- int ret = -1;
- WERROR werr = WERR_OK;
- struct registry_key *key = NULL;
- TALLOC_CTX *ctx;
-
- ctx = talloc_init("showshare");
-
- if (argc != 1) {
- net_conf_showshare_usage(argc, argv);
- goto done;
- }
-
- werr = smbconf_open_path(ctx, argv[0], REG_KEY_READ, &key);
- if (!W_ERROR_IS_OK(werr)) {
- goto done;
- }
-
- d_printf("[%s]\n", argv[0]);
-
- if (!W_ERROR_IS_OK(list_values(ctx, key))) {
- goto done;
- }
-
- ret = 0;
-
-done:
- TALLOC_FREE(ctx);
- return ret;
-}
-
-int net_conf_addshare(int argc, const char **argv)
-{
- int ret = -1;
- WERROR werr = WERR_OK;
- struct registry_key *newkey = NULL;
- char *sharename = NULL;
- const char *path = NULL;
- const char *comment = NULL;
- const char *guest_ok = "no";
- const char *writeable = "no";
- SMB_STRUCT_STAT sbuf;
-
- switch (argc) {
- case 0:
- case 1:
- default:
- net_conf_addshare_usage(argc, argv);
- goto done;
- case 5:
- comment = argv[4];
- case 4:
- if (!strnequal(argv[3], "guest_ok=", 9)) {
- net_conf_addshare_usage(argc, argv);
- goto done;
- }
- switch (argv[3][9]) {
- case 'y':
- case 'Y':
- guest_ok = "yes";
- break;
- case 'n':
- case 'N':
- guest_ok = "no";
- break;
- default:
- net_conf_addshare_usage(argc, argv);
- goto done;
- }
- case 3:
- if (!strnequal(argv[2], "writeable=", 10)) {
- net_conf_addshare_usage(argc, argv);
- goto done;
- }
- switch (argv[2][10]) {
- case 'y':
- case 'Y':
- writeable = "yes";
- break;
- case 'n':
- case 'N':
- writeable = "no";
- break;
- default:
- net_conf_addshare_usage(argc, argv);
- goto done;
- }
-
- case 2:
- path = argv[1];
- sharename = strdup_lower(argv[0]);
- break;
- }
-
- /*
- * validate arguments
- */
-
- /* validate share name */
-
- if (!validate_net_name(sharename, INVALID_SHARENAME_CHARS,
- strlen(sharename)))
- {
- d_fprintf(stderr, "ERROR: share name %s contains "
- "invalid characters (any of %s)\n",
- sharename, INVALID_SHARENAME_CHARS);
- goto done;
- }
-
- if (getpwnam(sharename)) {
- d_fprintf(stderr, "ERROR: share name %s is already a valid "
- "system user name.\n", sharename);
- goto done;
- }
-
- if (strequal(sharename, GLOBAL_NAME)) {
- d_fprintf(stderr,
- "ERROR: 'global' is not a valid share name.\n");
- goto done;
- }
-
- /* validate path */
-
- if (path[0] != '/') {
- d_fprintf(stderr,
- "Error: path '%s' is not an absolute path.\n",
- path);
- goto done;
- }
-
- if (sys_stat(path, &sbuf) != 0) {
- d_fprintf(stderr,
- "ERROR: cannot stat path '%s' to ensure "
- "this is a directory.\n"
- "Error was '%s'.\n",
- path, strerror(errno));
- goto done;
- }
-
- if (!S_ISDIR(sbuf.st_mode)) {
- d_fprintf(stderr,
- "ERROR: path '%s' is not a directory.\n",
- path);
- goto done;
- }
-
- /*
- * create the share
- */
-
- werr = reg_createkey_internal(NULL, argv[0], &newkey);
- if (!W_ERROR_IS_OK(werr)) {
- goto done;
- }
-
- /* add config params as values */
-
- werr = reg_setvalue_internal(newkey, "path", path);
- if (!W_ERROR_IS_OK(werr))
- goto done;
-
- if (comment != NULL) {
- werr = reg_setvalue_internal(newkey, "comment", comment);
- if (!W_ERROR_IS_OK(werr))
- goto done;
- }
-
- werr = reg_setvalue_internal(newkey, "guest ok", guest_ok);
- if (!W_ERROR_IS_OK(werr))
- goto done;
-
- werr = reg_setvalue_internal(newkey, "writeable", writeable);
- if (!W_ERROR_IS_OK(werr))
- goto done;
-
- ret = 0;
-
-done:
- TALLOC_FREE(newkey);
- SAFE_FREE(sharename);
- return ret;
-}
-
-int net_conf_delshare(int argc, const char **argv)
-{
- int ret = -1;
- const char *sharename = NULL;
-
- if (argc != 1) {
- net_conf_delshare_usage(argc, argv);
- goto done;
- }
- sharename = argv[0];
-
- if (W_ERROR_IS_OK(reg_delkey_internal(NULL, sharename))) {
- ret = 0;
- }
-done:
- return ret;
-}
-
-static int net_conf_setparm(int argc, const char **argv)
-{
- int ret = -1;
- WERROR werr = WERR_OK;
- struct registry_key *key = NULL;
- char *service = NULL;
- char *param = NULL;
- const char *value_str = NULL;
- TALLOC_CTX *ctx;
-
- ctx = talloc_init("setparm");
-
- if (argc != 3) {
- net_conf_setparm_usage(argc, argv);
- goto done;
- }
- service = strdup_lower(argv[0]);
- param = strdup_lower(argv[1]);
- value_str = argv[2];
-
- if (!smbconf_key_exists(ctx, service)) {
- werr = reg_createkey_internal(ctx, service, &key);
- }
- else {
- werr = smbconf_open_path(ctx, service, REG_KEY_READ, &key);
- }
- if (!W_ERROR_IS_OK(werr)) {
- goto done;
- }
-
- werr = reg_setvalue_internal(key, param, value_str);
- if (!W_ERROR_IS_OK(werr)) {
- d_fprintf(stderr, "Error setting value '%s': %s\n",
- param, dos_errstr(werr));
- goto done;
- }
-
-
- ret = 0;
-
-done:
- SAFE_FREE(service);
- TALLOC_FREE(ctx);
- return ret;
-}
-
-static int net_conf_getparm(int argc, const char **argv)
-{
- int ret = -1;
- WERROR werr = WERR_OK;
- struct registry_key *key = NULL;
- char *service = NULL;
- char *param = NULL;
- struct registry_value *value = NULL;
- TALLOC_CTX *ctx;
-
- ctx = talloc_init("getparm");
-
- if (argc != 2) {
- net_conf_getparm_usage(argc, argv);
- goto done;
- }
- service = strdup_lower(argv[0]);
- param = strdup_lower(argv[1]);
-
- if (!smbconf_key_exists(ctx, service)) {
- d_fprintf(stderr,
- "ERROR: given service '%s' does not exist.\n",
- service);
- goto done;
- }
-
- werr = smbconf_open_path(ctx, service, REG_KEY_READ, &key);
- if (!W_ERROR_IS_OK(werr)) {
- goto done;
- }
-
- werr = reg_queryvalue(ctx, key, param, &value);
- if (!W_ERROR_IS_OK(werr)) {
- d_fprintf(stderr, "Error querying value '%s': %s.\n",
- param, dos_errstr(werr));
- goto done;
- }
-
- d_printf("%s\n", format_value(ctx, value));
-
- ret = 0;
-done:
- SAFE_FREE(service);
- SAFE_FREE(param);
- TALLOC_FREE(ctx);
- return ret;
-}
-
-static int net_conf_delparm(int argc, const char **argv)
-{
- int ret = -1;
- WERROR werr = WERR_OK;
- struct registry_key *key = NULL;
- char *service = NULL;
- char *param = NULL;
- TALLOC_CTX *ctx;
-
- ctx = talloc_init("delparm");
-
- if (argc != 2) {
- net_conf_delparm_usage(argc, argv);
- goto done;
- }
- service = strdup_lower(argv[0]);
- param = strdup_lower(argv[1]);
-
- if (!smbconf_key_exists(ctx, service)) {
- d_fprintf(stderr,
- "Error: given service '%s' does not exist.\n",
- service);
- goto done;
- }
-
- werr = smbconf_open_path(ctx, service, REG_KEY_READ, &key);
- if (!W_ERROR_IS_OK(werr)) {
- goto done;
- }
-
- if (!smbconf_value_exists(ctx, key, param)) {
- d_fprintf(stderr,
- "Error: given parameter '%s' is not set.\n",
- param);
- goto done;
- }
- werr = reg_deletevalue(key, param);
- if (!W_ERROR_IS_OK(werr)) {
- d_fprintf(stderr, "Error deleting value '%s': %s.\n",
- param, dos_errstr(werr));
- goto done;
- }
-
- ret = 0;
-
-done:
- return ret;
-}
-
-/*
- * Entry-point for all the CONF functions.
- */
-
-int net_conf(int argc, const char **argv)
-{
- int ret = -1;
- struct functable2 func[] = {
- {"list", net_conf_list,
- "Dump the complete configuration in smb.conf like format."},
- {"import", net_conf_import,
- "Import configuration from file in smb.conf format."},
- {"listshares", net_conf_listshares,
- "List the registry shares."},
- {"drop", net_conf_drop,
- "Delete the complete configuration from registry."},
- {"showshare", net_conf_showshare,
- "Show the definition of a registry share."},
- {"addshare", net_conf_addshare,
- "Create a new registry share."},
- {"delshare", net_conf_delshare,
- "Delete a registry share."},
- {"setparm", net_conf_setparm,
- "Store a parameter."},
- {"getparm", net_conf_getparm,
- "Retrieve the value of a parameter."},
- {"delparm", net_conf_delparm,
- "Delete a parameter."},
- {NULL, NULL, NULL}
- };
-
- if (!registry_init_regdb()) {
- d_fprintf(stderr, "Error initializing the registry!\n");
- goto done;
- }
-
- ret = net_run_function2(argc, argv, "net conf", func);
-
- regdb_close();
-
-done:
- return ret;
-}
-
-/* END */
diff --git a/source/utils/net_domain.c b/source/utils/net_domain.c
index 948aa5c19bb..5b330d8765c 100644
--- a/source/utils/net_domain.c
+++ b/source/utils/net_domain.c
@@ -180,7 +180,7 @@ NTSTATUS netdom_get_domain_sid( TALLOC_CTX *mem_ctx, struct cli_state *cli,
if ( !NT_STATUS_IS_OK(status) )
return status;
- rpccli_lsa_Close(pipe_hnd, mem_ctx, &lsa_pol);
+ rpccli_lsa_close(pipe_hnd, mem_ctx, &lsa_pol);
cli_rpc_pipe_close(pipe_hnd); /* Done with this pipe */
/* Bail out if domain didn't get set. */
@@ -209,14 +209,10 @@ NTSTATUS netdom_join_domain( TALLOC_CTX *mem_ctx, struct cli_state *cli,
uint32 num_rids, *name_types, *user_rids;
uint32 flags = 0x3e8;
uint32 acb_info = ACB_WSTRUST;
- uint32 fields_present;
- uchar pwbuf[532];
+ uchar pwbuf[516];
SAM_USERINFO_CTR ctr;
- SAM_USER_INFO_25 p25;
- const int infolevel = 25;
- struct MD5Context md5ctx;
- uchar md5buffer[16];
- DATA_BLOB digested_session_key;
+ SAM_USER_INFO_24 p24;
+ SAM_USER_INFO_16 p16;
uchar md4_trust_password[16];
/* Open the domain */
@@ -287,49 +283,24 @@ NTSTATUS netdom_join_domain( TALLOC_CTX *mem_ctx, struct cli_state *cli,
status = rpccli_samr_open_user(pipe_hnd, mem_ctx, &domain_pol,
SEC_RIGHTS_MAXIMUM_ALLOWED, user_rid, &user_pol);
- if (!NT_STATUS_IS_OK(status)) {
- return status;
- }
- /* Create a random machine account password and generate the hash */
+ /* Create a random machine account password */
- E_md4hash(clear_pw, md4_trust_password);
+ E_md4hash( clear_pw, md4_trust_password);
encode_pw_buffer(pwbuf, clear_pw, STR_UNICODE);
-
- generate_random_buffer((uint8*)md5buffer, sizeof(md5buffer));
- digested_session_key = data_blob_talloc(mem_ctx, 0, 16);
-
- MD5Init(&md5ctx);
- MD5Update(&md5ctx, md5buffer, sizeof(md5buffer));
- MD5Update(&md5ctx, cli->user_session_key.data, cli->user_session_key.length);
- MD5Final(digested_session_key.data, &md5ctx);
-
- SamOEMhashBlob(pwbuf, sizeof(pwbuf), &digested_session_key);
- memcpy(&pwbuf[516], md5buffer, sizeof(md5buffer));
-
- /* Fill in the additional account flags now */
-
- acb_info |= ACB_PWNOEXP;
- if ( dom_type == ND_TYPE_AD ) {
-#if !defined(ENCTYPE_ARCFOUR_HMAC)
- acb_info |= ACB_USE_DES_KEY_ONLY;
-#endif
- ;;
- }
- /* Set password and account flags on machine account */
+ /* Set password on machine account */
ZERO_STRUCT(ctr);
- ZERO_STRUCT(p25);
+ ZERO_STRUCT(p24);
- fields_present = ACCT_NT_PWD_SET | ACCT_LM_PWD_SET | ACCT_FLAGS;
- init_sam_user_info25P(&p25, fields_present, acb_info, (char *)pwbuf);
+ init_sam_user_info24(&p24, (char *)pwbuf,24);
- ctr.switch_value = infolevel;
- ctr.info.id25 = &p25;
+ ctr.switch_value = 24;
+ ctr.info.id24 = &p24;
- status = rpccli_samr_set_userinfo2(pipe_hnd, mem_ctx, &user_pol,
- infolevel, &cli->user_session_key, &ctr);
+ status = rpccli_samr_set_userinfo(pipe_hnd, mem_ctx, &user_pol,
+ 24, &cli->user_session_key, &ctr);
if ( !NT_STATUS_IS_OK(status) ) {
d_fprintf( stderr, "Failed to set password for machine account (%s)\n",
@@ -337,6 +308,35 @@ NTSTATUS netdom_join_domain( TALLOC_CTX *mem_ctx, struct cli_state *cli,
return status;
}
+
+ /* Why do we have to try to (re-)set the ACB to be the same as what
+ we passed in the samr_create_dom_user() call? When a NT
+ workstation is joined to a domain by an administrator the
+ acb_info is set to 0x80. For a normal user with "Add
+ workstations to the domain" rights the acb_info is 0x84. I'm
+ not sure whether it is supposed to make a difference or not. NT
+ seems to cope with either value so don't bomb out if the set
+ userinfo2 level 0x10 fails. -tpot */
+
+ ZERO_STRUCT(ctr);
+ ctr.switch_value = 16;
+ ctr.info.id16 = &p16;
+
+ /* Fill in the additional account flags now */
+
+ acb_info |= ACB_PWNOEXP;
+ if ( dom_type == ND_TYPE_AD ) {
+#if !defined(ENCTYPE_ARCFOUR_HMAC)
+ acb_info |= ACB_USE_DES_KEY_ONLY;
+#endif
+ ;;
+ }
+
+ init_sam_user_info16(&p16, acb_info);
+
+ status = rpccli_samr_set_userinfo2(pipe_hnd, mem_ctx, &user_pol, 16,
+ &cli->user_session_key, &ctr);
+
rpccli_samr_close(pipe_hnd, mem_ctx, &user_pol);
cli_rpc_pipe_close(pipe_hnd); /* Done with this pipe */
diff --git a/source/utils/net_groupmap.c b/source/utils/net_groupmap.c
index bb30a31c0b9..ad1a141cfc5 100644
--- a/source/utils/net_groupmap.c
+++ b/source/utils/net_groupmap.c
@@ -725,7 +725,7 @@ static int net_groupmap_listmem(int argc, const char **argv)
printf("%s\n", sid_string_static(&(members[i])));
}
- TALLOC_FREE(members);
+ SAFE_FREE(members);
return 0;
}
diff --git a/source/utils/net_help.c b/source/utils/net_help.c
index a293822c29c..369fc095f21 100644
--- a/source/utils/net_help.c
+++ b/source/utils/net_help.c
@@ -234,9 +234,8 @@ static int net_usage(int argc, const char **argv)
" net changesecretpw\tto change the machine password in the local secrets database only\n"\
" \tthis requires the -f flag as a safety barrier\n"\
" net status\t\tShow server status\n"\
- " net usersidlist\tto get a list of all users with their SIDs\n"
- " net usershare\t\tto add, delete and list locally user-modifiable shares\n"
- " net conf\t\tto view and edit samba's registry based configuration\n"
+ " net usersidlist\tto get a list of all users with their SIDs\n"
+ " net usershare\t\tto add, delete and list locally user-modifiable shares\n"
"\n"\
" net ads <command>\tto run ADS commands\n"\
" net rap <command>\tto run RAP (pre-RPC) commands\n"\
diff --git a/source/utils/net_idmap.c b/source/utils/net_idmap.c
index d4d2c931b84..1f70dafcfe8 100644
--- a/source/utils/net_idmap.c
+++ b/source/utils/net_idmap.c
@@ -35,17 +35,17 @@ static int net_idmap_dump_one_entry(TDB_CONTEXT *tdb,
TDB_DATA data,
void *unused)
{
- if (strcmp((char *)key.dptr, "USER HWM") == 0) {
+ if (strcmp(key.dptr, "USER HWM") == 0) {
printf("USER HWM %d\n", IVAL(data.dptr,0));
return 0;
}
- if (strcmp((char *)key.dptr, "GROUP HWM") == 0) {
+ if (strcmp(key.dptr, "GROUP HWM") == 0) {
printf("GROUP HWM %d\n", IVAL(data.dptr,0));
return 0;
}
- if (strncmp((char *)key.dptr, "S-", 2) != 0)
+ if (strncmp(key.dptr, "S-", 2) != 0)
return 0;
printf("%s %s\n", data.dptr, key.dptr);
diff --git a/source/utils/net_rpc.c b/source/utils/net_rpc.c
index 3c722d2760b..fee994b7519 100644
--- a/source/utils/net_rpc.c
+++ b/source/utils/net_rpc.c
@@ -5,7 +5,6 @@
Copyright (C) 2002 Jim McDonough (jmcd@us.ibm.com)
Copyright (C) 2004 Guenther Deschner (gd@samba.org)
Copyright (C) 2005 Jeremy Allison (jra@samba.org)
- Copyright (C) 2006 Jelmer Vernooij (jelmer@samba.org)
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
@@ -82,7 +81,7 @@ NTSTATUS net_get_remote_domain_sid(struct cli_state *cli, TALLOC_CTX *mem_ctx,
return result;
}
- rpccli_lsa_Close(lsa_pipe, mem_ctx, &pol);
+ rpccli_lsa_close(lsa_pipe, mem_ctx, &pol);
cli_rpc_pipe_close(lsa_pipe);
return NT_STATUS_OK;
@@ -2030,14 +2029,14 @@ static NTSTATUS get_sid_from_name(struct cli_state *cli,
}
result = rpccli_lsa_lookup_names(pipe_hnd, mem_ctx, &lsa_pol, 1,
- &name, NULL, 1, &sids, &types);
+ &name, NULL, &sids, &types);
if (NT_STATUS_IS_OK(result)) {
sid_copy(sid, &sids[0]);
*type = types[0];
}
- rpccli_lsa_Close(pipe_hnd, mem_ctx, &lsa_pol);
+ rpccli_lsa_close(pipe_hnd, mem_ctx, &lsa_pol);
done:
if (pipe_hnd) {
@@ -3014,16 +3013,13 @@ static NTSTATUS rpc_share_add_internals(const DOM_SID *domain_sid,
TALLOC_CTX *mem_ctx,int argc,
const char **argv)
{
- NTSTATUS result;
+ WERROR result;
char *sharename;
char *path;
uint32 type = STYPE_DISKTREE; /* only allow disk shares to be added */
uint32 num_users=0, perms=0;
char *password=NULL; /* don't allow a share password */
uint32 level = 2;
- uint32 parm_error;
- union srvsvc_NetShareInfo info;
- struct srvsvc_NetShareInfo2 info2;
if ((sharename = talloc_strdup(mem_ctx, argv[0])) == NULL) {
return NT_STATUS_NO_MEMORY;
@@ -3034,20 +3030,11 @@ static NTSTATUS rpc_share_add_internals(const DOM_SID *domain_sid,
return NT_STATUS_UNSUCCESSFUL;
*path++ = '\0';
- info.info2 = &info2;
-
- info2.type = type;
- info2.comment = opt_comment;
- info2.permissions = perms;
- info2.max_users = opt_maxusers;
- info2.current_users = num_users;
- info2.path = path;
- info2.password = password;
- info2.name = sharename;
-
- result = rpccli_srvsvc_NetShareAdd(pipe_hnd, mem_ctx, NULL, level,
- info, &parm_error);
- return result;
+ result = rpccli_srvsvc_net_share_add(pipe_hnd, mem_ctx, sharename, type,
+ opt_comment, perms, opt_maxusers,
+ num_users, path, password,
+ level, NULL);
+ return werror_to_ntstatus(result);
}
static int rpc_share_add(int argc, const char **argv)
@@ -3084,7 +3071,10 @@ static NTSTATUS rpc_share_del_internals(const DOM_SID *domain_sid,
int argc,
const char **argv)
{
- return rpccli_srvsvc_NetShareDel(pipe_hnd, mem_ctx, NULL, argv[0], 0);
+ WERROR result;
+
+ result = rpccli_srvsvc_net_share_del(pipe_hnd, mem_ctx, argv[0]);
+ return W_ERROR_IS_OK(result) ? NT_STATUS_OK : NT_STATUS_UNSUCCESSFUL;
}
/**
@@ -3111,83 +3101,169 @@ static int rpc_share_delete(int argc, const char **argv)
/**
* Formatted print of share info
*
- * @param info1 pointer to struct srvsvc_NetShareInfo1 to format
+ * @param info1 pointer to SRV_SHARE_INFO_1 to format
**/
-static void display_share_info_1(struct srvsvc_NetShareInfo1 *info1)
+static void display_share_info_1(SRV_SHARE_INFO_1 *info1)
{
+ fstring netname = "", remark = "";
+
+ rpcstr_pull_unistr2_fstring(netname, &info1->info_1_str.uni_netname);
+ rpcstr_pull_unistr2_fstring(remark, &info1->info_1_str.uni_remark);
+
if (opt_long_list_entries) {
d_printf("%-12s %-8.8s %-50s\n",
- info1->name, share_type[info1->type & ~(STYPE_TEMPORARY|STYPE_HIDDEN)],
- info1->comment ? info1->comment : "");
+ netname, share_type[info1->info_1.type & ~(STYPE_TEMPORARY|STYPE_HIDDEN)], remark);
} else {
- d_printf("%s\n", info1->name);
+ d_printf("%s\n", netname);
}
}
-static NTSTATUS get_share_info(struct rpc_pipe_client *pipe_hnd,
+static WERROR get_share_info(struct rpc_pipe_client *pipe_hnd,
TALLOC_CTX *mem_ctx,
uint32 level,
int argc,
const char **argv,
- union srvsvc_NetShareCtr *ctr,
- uint32 *numentries)
+ SRV_SHARE_INFO_CTR *ctr)
{
- union srvsvc_NetShareInfo info;
- NTSTATUS status;
-
- switch(level) {
- case 1:
- if (!(ctr->ctr1 = TALLOC_ZERO_P(
- mem_ctx, struct srvsvc_NetShareCtr1))) {
- return NT_STATUS_NO_MEMORY;
- }
- break;
- case 502:
- if (!(ctr->ctr502 = TALLOC_ZERO_P(
- mem_ctx, struct srvsvc_NetShareCtr502))) {
- return NT_STATUS_NO_MEMORY;
- }
- break;
- default:
- return NT_STATUS_INVALID_LEVEL;
- break;
- }
+ WERROR result;
+ SRV_SHARE_INFO info;
/* no specific share requested, enumerate all */
if (argc == 0) {
- uint32 hnd = 0;
- return rpccli_srvsvc_NetShareEnum(pipe_hnd, mem_ctx, NULL,
- &level, ctr, 0xffffffff,
- numentries, &hnd);
+ ENUM_HND hnd;
+ uint32 preferred_len = 0xffffffff;
+
+ init_enum_hnd(&hnd, 0);
+
+ return rpccli_srvsvc_net_share_enum(pipe_hnd, mem_ctx, level, ctr,
+ preferred_len, &hnd);
}
/* request just one share */
- status = rpccli_srvsvc_NetShareGetInfo(pipe_hnd, mem_ctx, NULL,
- argv[0], level, &info);
- if (!NT_STATUS_IS_OK(status)) {
- return status;
- }
+ result = rpccli_srvsvc_net_share_get_info(pipe_hnd, mem_ctx, argv[0], level, &info);
+
+ if (!W_ERROR_IS_OK(result))
+ goto done;
- *numentries = 1;
+ /* construct ctr */
+ ZERO_STRUCTP(ctr);
- switch(level) {
+ ctr->info_level = ctr->switch_value = level;
+ ctr->ptr_share_info = ctr->ptr_entries = 1;
+ ctr->num_entries = ctr->num_entries2 = 1;
+
+ switch (level) {
case 1:
- ctr->ctr1->count = 1;
- ctr->ctr1->array = info.info1;
- break;
+ {
+ char *s;
+ SRV_SHARE_INFO_1 *info1;
+
+ ctr->share.info1 = TALLOC_ARRAY(mem_ctx, SRV_SHARE_INFO_1, 1);
+ if (ctr->share.info1 == NULL) {
+ result = WERR_NOMEM;
+ goto done;
+ }
+ info1 = ctr->share.info1;
+
+ memset(ctr->share.info1, 0, sizeof(SRV_SHARE_INFO_1));
+
+ /* Copy pointer crap */
+
+ memcpy(&info1->info_1, &info.share.info1.info_1, sizeof(SH_INFO_1));
+
+ /* Duplicate strings */
+
+ s = unistr2_tdup(mem_ctx, &info.share.info1.info_1_str.uni_netname);
+ if (s)
+ init_unistr2(&info1->info_1_str.uni_netname, s, UNI_STR_TERMINATE);
+
+ s = unistr2_tdup(mem_ctx, &info.share.info1.info_1_str.uni_remark);
+ if (s)
+ init_unistr2(&info1->info_1_str.uni_remark, s, UNI_STR_TERMINATE);
+ }
+ case 2:
+ {
+ char *s;
+ SRV_SHARE_INFO_2 *info2;
+
+ ctr->share.info2 = TALLOC_ARRAY(mem_ctx, SRV_SHARE_INFO_2, 1);
+ if (ctr->share.info2 == NULL) {
+ result = WERR_NOMEM;
+ goto done;
+ }
+ info2 = ctr->share.info2;
+
+ memset(ctr->share.info2, 0, sizeof(SRV_SHARE_INFO_2));
+
+ /* Copy pointer crap */
+
+ memcpy(&info2->info_2, &info.share.info2.info_2, sizeof(SH_INFO_2));
+
+ /* Duplicate strings */
+
+ s = unistr2_tdup(mem_ctx, &info.share.info2.info_2_str.uni_netname);
+ if (s)
+ init_unistr2(&info2->info_2_str.uni_netname, s, UNI_STR_TERMINATE);
+
+ s = unistr2_tdup(mem_ctx, &info.share.info2.info_2_str.uni_remark);
+ if (s)
+ init_unistr2(&info2->info_2_str.uni_remark, s, UNI_STR_TERMINATE);
+
+ s = unistr2_tdup(mem_ctx, &info.share.info2.info_2_str.uni_path);
+ if (s)
+ init_unistr2(&info2->info_2_str.uni_path, s, UNI_STR_TERMINATE);
+
+ s = unistr2_tdup(mem_ctx, &info.share.info2.info_2_str.uni_passwd);
+ if (s)
+ init_unistr2(&info2->info_2_str.uni_passwd, s, UNI_STR_TERMINATE);
+ }
case 502:
- ctr->ctr501->count = 1;
- ctr->ctr502->array = info.info502;
- break;
- default:
- return NT_STATUS_INTERNAL_ERROR;
- break;
+ {
+ char *s;
+ SRV_SHARE_INFO_502 *info502;
+
+ ctr->share.info502 = TALLOC_ARRAY(mem_ctx, SRV_SHARE_INFO_502, 1);
+ if (ctr->share.info502 == NULL) {
+ result = WERR_NOMEM;
+ goto done;
+ }
+ info502 = ctr->share.info502;
+
+ memset(ctr->share.info502, 0, sizeof(SRV_SHARE_INFO_502));
+
+ /* Copy pointer crap */
+
+ memcpy(&info502->info_502, &info.share.info502.info_502, sizeof(SH_INFO_502));
+
+ /* Duplicate strings */
+
+ s = unistr2_tdup(mem_ctx, &info.share.info502.info_502_str.uni_netname);
+ if (s)
+ init_unistr2(&info502->info_502_str.uni_netname, s, UNI_STR_TERMINATE);
+
+ s = unistr2_tdup(mem_ctx, &info.share.info502.info_502_str.uni_remark);
+ if (s)
+ init_unistr2(&info502->info_502_str.uni_remark, s, UNI_STR_TERMINATE);
+
+ s = unistr2_tdup(mem_ctx, &info.share.info502.info_502_str.uni_path);
+ if (s)
+ init_unistr2(&info502->info_502_str.uni_path, s, UNI_STR_TERMINATE);
+
+ s = unistr2_tdup(mem_ctx, &info.share.info502.info_502_str.uni_passwd);
+ if (s)
+ init_unistr2(&info502->info_502_str.uni_passwd, s, UNI_STR_TERMINATE);
+
+ info502->info_502_str.sd = dup_sec_desc(mem_ctx, info.share.info502.info_502_str.sd);
+
}
- return NT_STATUS_OK;
+ } /* switch */
+
+done:
+ return result;
}
/**
@@ -3214,14 +3290,12 @@ static NTSTATUS rpc_share_list_internals(const DOM_SID *domain_sid,
int argc,
const char **argv)
{
- union srvsvc_NetShareCtr ctr;
- NTSTATUS result;
+ SRV_SHARE_INFO_CTR ctr;
+ WERROR result;
uint32 i, level = 1;
- uint32 numentries;
- result = get_share_info(pipe_hnd, mem_ctx, level, argc, argv, &ctr,
- &numentries);
- if (!NT_STATUS_IS_OK(result))
+ result = get_share_info(pipe_hnd, mem_ctx, level, argc, argv, &ctr);
+ if (!W_ERROR_IS_OK(result))
goto done;
/* Display results */
@@ -3232,10 +3306,10 @@ static NTSTATUS rpc_share_list_internals(const DOM_SID *domain_sid,
"\nShare name Type Description\n"\
"---------- ---- -----------\n");
}
- for (i = 0; i < numentries; i++)
- display_share_info_1(&ctr.ctr1->array[i]);
+ for (i = 0; i < ctr.num_entries; i++)
+ display_share_info_1(&ctr.share.info1[i]);
done:
- return NT_STATUS_IS_OK(result) ? NT_STATUS_OK : NT_STATUS_UNSUCCESSFUL;
+ return W_ERROR_IS_OK(result) ? NT_STATUS_OK : NT_STATUS_UNSUCCESSFUL;
}
/***
@@ -3262,7 +3336,7 @@ static BOOL check_share_availability(struct cli_state *cli, const char *netname)
return True;
}
-static BOOL check_share_sanity(struct cli_state *cli, const char *netname, uint32 type)
+static BOOL check_share_sanity(struct cli_state *cli, fstring netname, uint32 type)
{
/* only support disk shares */
if (! ( type == STYPE_DISKTREE || type == (STYPE_DISKTREE | STYPE_HIDDEN)) ) {
@@ -3308,18 +3382,18 @@ static NTSTATUS rpc_share_migrate_shares_internals(const DOM_SID *domain_sid,
int argc,
const char **argv)
{
- NTSTATUS result;
+ WERROR result;
NTSTATUS nt_status = NT_STATUS_UNSUCCESSFUL;
- union srvsvc_NetShareCtr ctr_src;
+ SRV_SHARE_INFO_CTR ctr_src;
+ uint32 type = STYPE_DISKTREE; /* only allow disk shares to be added */
+ char *password = NULL; /* don't allow a share password */
uint32 i;
struct rpc_pipe_client *srvsvc_pipe = NULL;
struct cli_state *cli_dst = NULL;
uint32 level = 502; /* includes secdesc */
- uint32 numentries;
- result = get_share_info(pipe_hnd, mem_ctx, level, argc, argv, &ctr_src,
- &numentries);
- if (!NT_STATUS_IS_OK(result))
+ result = get_share_info(pipe_hnd, mem_ctx, level, argc, argv, &ctr_src);
+ if (!W_ERROR_IS_OK(result))
goto done;
/* connect destination PI_SRVSVC */
@@ -3328,37 +3402,41 @@ static NTSTATUS rpc_share_migrate_shares_internals(const DOM_SID *domain_sid,
return nt_status;
- for (i = 0; i < numentries; i++) {
- uint32 parm_error = 0;
- union srvsvc_NetShareInfo info;
+ for (i = 0; i < ctr_src.num_entries; i++) {
+ fstring netname = "", remark = "", path = "";
/* reset error-code */
nt_status = NT_STATUS_UNSUCCESSFUL;
- if (!check_share_sanity(cli, ctr_src.ctr502->array[i].name,
- ctr_src.ctr502->array[i].type))
-
+ rpcstr_pull_unistr2_fstring(
+ netname, &ctr_src.share.info502[i].info_502_str.uni_netname);
+ rpcstr_pull_unistr2_fstring(
+ remark, &ctr_src.share.info502[i].info_502_str.uni_remark);
+ rpcstr_pull_unistr2_fstring(
+ path, &ctr_src.share.info502[i].info_502_str.uni_path);
+
+ if (!check_share_sanity(cli, netname, ctr_src.share.info502[i].info_502.type))
continue;
/* finally add the share on the dst server */
printf("migrating: [%s], path: %s, comment: %s, without share-ACLs\n",
- ctr_src.ctr502->array[i].name,
- ctr_src.ctr502->array[i].path,
- ctr_src.ctr502->array[i].comment);
-
- info.info502 = &ctr_src.ctr502->array[i];
-
- result = rpccli_srvsvc_NetShareAdd(srvsvc_pipe, mem_ctx, NULL,
- 502, info, &parm_error);
+ netname, path, remark);
+
+ result = rpccli_srvsvc_net_share_add(srvsvc_pipe, mem_ctx, netname, type, remark,
+ ctr_src.share.info502[i].info_502.perms,
+ ctr_src.share.info502[i].info_502.max_uses,
+ ctr_src.share.info502[i].info_502.num_uses,
+ path, password, level,
+ NULL);
- if (NT_STATUS_EQUAL(result, NT_STATUS_OBJECT_NAME_COLLISION)) {
- printf(" [%s] does already exist\n", ctr_src.ctr502->array[i].name);
+ if (W_ERROR_V(result) == W_ERROR_V(WERR_ALREADY_EXISTS)) {
+ printf(" [%s] does already exist\n", netname);
continue;
}
- if (!NT_STATUS_IS_OK(result)) {
- printf("cannot add share: %s\n", nt_errstr(result));
+ if (!W_ERROR_IS_OK(result)) {
+ printf("cannot add share: %s\n", dos_errstr(result));
goto done;
}
@@ -3588,9 +3666,9 @@ static NTSTATUS rpc_share_migrate_files_internals(const DOM_SID *domain_sid,
int argc,
const char **argv)
{
- NTSTATUS result;
+ WERROR result;
NTSTATUS nt_status = NT_STATUS_UNSUCCESSFUL;
- union srvsvc_NetShareCtr ctr_src;
+ SRV_SHARE_INFO_CTR ctr_src;
uint32 i;
uint32 level = 502;
struct copy_clistate cp_clistate;
@@ -3598,24 +3676,27 @@ static NTSTATUS rpc_share_migrate_files_internals(const DOM_SID *domain_sid,
BOOL got_dst_share = False;
pstring mask = "\\*";
char *dst = NULL;
- uint32 numentries;
dst = SMB_STRDUP(opt_destination?opt_destination:"127.0.0.1");
- result = get_share_info(pipe_hnd, mem_ctx, level, argc, argv, &ctr_src,
- &numentries);
+ result = get_share_info(pipe_hnd, mem_ctx, level, argc, argv, &ctr_src);
- if (!NT_STATUS_IS_OK(result))
+ if (!W_ERROR_IS_OK(result))
goto done;
- for (i = 0; i < numentries; i++) {
- if (!check_share_sanity(cli, ctr_src.ctr502->array[i].name,
- ctr_src.ctr502->array[i].type))
+ for (i = 0; i < ctr_src.num_entries; i++) {
+
+ fstring netname = "";
+
+ rpcstr_pull_unistr2_fstring(
+ netname, &ctr_src.share.info502[i].info_502_str.uni_netname);
+
+ if (!check_share_sanity(cli, netname, ctr_src.share.info502[i].info_502.type))
continue;
/* one might not want to mirror whole discs :) */
- if (strequal(ctr_src.ctr502->array[i].name, "print$") || ctr_src.ctr502->array[i].name[1] == '$') {
- d_printf("skipping [%s]: builtin/hidden share\n", ctr_src.ctr502->array[i].name);
+ if (strequal(netname, "print$") || netname[1] == '$') {
+ d_printf("skipping [%s]: builtin/hidden share\n", netname);
continue;
}
@@ -3629,7 +3710,7 @@ static NTSTATUS rpc_share_migrate_files_internals(const DOM_SID *domain_sid,
break;
}
printf(" [%s] files and directories %s ACLs, %s DOS Attributes %s\n",
- ctr_src.ctr502->array[i].name,
+ netname,
opt_acls ? "including" : "without",
opt_attrs ? "including" : "without",
opt_timestamps ? "(preserving timestamps)" : "");
@@ -3643,7 +3724,7 @@ static NTSTATUS rpc_share_migrate_files_internals(const DOM_SID *domain_sid,
/* open share source */
nt_status = connect_to_service(&cp_clistate.cli_share_src,
&cli->dest_ip, cli->desthost,
- ctr_src.ctr502->array[i].name, "A:");
+ netname, "A:");
if (!NT_STATUS_IS_OK(nt_status))
goto done;
@@ -3652,22 +3733,21 @@ static NTSTATUS rpc_share_migrate_files_internals(const DOM_SID *domain_sid,
if (net_mode_share == NET_MODE_SHARE_MIGRATE) {
/* open share destination */
nt_status = connect_to_service(&cp_clistate.cli_share_dst,
- NULL, dst, ctr_src.ctr502->array[i].name, "A:");
+ NULL, dst, netname, "A:");
if (!NT_STATUS_IS_OK(nt_status))
goto done;
got_dst_share = True;
}
- if (!copy_top_level_perms(&cp_clistate, ctr_src.ctr502->array[i].name)) {
- d_fprintf(stderr, "Could not handle the top level directory permissions for the share: %s\n", ctr_src.ctr502->array[i].name);
+ if (!copy_top_level_perms(&cp_clistate, netname)) {
+ d_fprintf(stderr, "Could not handle the top level directory permissions for the share: %s\n", netname);
nt_status = NT_STATUS_UNSUCCESSFUL;
goto done;
}
if (!sync_files(&cp_clistate, mask)) {
- d_fprintf(stderr, "could not handle files for share: %s\n",
- ctr_src.ctr502->array[i].name);
+ d_fprintf(stderr, "could not handle files for share: %s\n", netname);
nt_status = NT_STATUS_UNSUCCESSFUL;
goto done;
}
@@ -3724,21 +3804,18 @@ static NTSTATUS rpc_share_migrate_security_internals(const DOM_SID *domain_sid,
int argc,
const char **argv)
{
- NTSTATUS result;
+ WERROR result;
NTSTATUS nt_status = NT_STATUS_UNSUCCESSFUL;
- union srvsvc_NetShareCtr ctr_src;
- union srvsvc_NetShareInfo info;
+ SRV_SHARE_INFO_CTR ctr_src;
+ SRV_SHARE_INFO info;
uint32 i;
struct rpc_pipe_client *srvsvc_pipe = NULL;
struct cli_state *cli_dst = NULL;
uint32 level = 502; /* includes secdesc */
- uint32 numentries;
- uint32 parm_error = 0;
- result = get_share_info(pipe_hnd, mem_ctx, level, argc, argv, &ctr_src,
- &numentries);
+ result = get_share_info(pipe_hnd, mem_ctx, level, argc, argv, &ctr_src);
- if (!NT_STATUS_IS_OK(result))
+ if (!W_ERROR_IS_OK(result))
goto done;
/* connect destination PI_SRVSVC */
@@ -3747,31 +3824,42 @@ static NTSTATUS rpc_share_migrate_security_internals(const DOM_SID *domain_sid,
return nt_status;
- for (i = 0; i < numentries; i++) {
+ for (i = 0; i < ctr_src.num_entries; i++) {
+
+ fstring netname = "", remark = "", path = "";
/* reset error-code */
nt_status = NT_STATUS_UNSUCCESSFUL;
- if (!check_share_sanity(cli, ctr_src.ctr502->array[i].name, ctr_src.ctr502->array[i].type))
+ rpcstr_pull_unistr2_fstring(
+ netname, &ctr_src.share.info502[i].info_502_str.uni_netname);
+ rpcstr_pull_unistr2_fstring(
+ remark, &ctr_src.share.info502[i].info_502_str.uni_remark);
+ rpcstr_pull_unistr2_fstring(
+ path, &ctr_src.share.info502[i].info_502_str.uni_path);
+
+ if (!check_share_sanity(cli, netname, ctr_src.share.info502[i].info_502.type))
continue;
printf("migrating: [%s], path: %s, comment: %s, including share-ACLs\n",
- ctr_src.ctr502->array[i].name,
- ctr_src.ctr502->array[i].path,
- ctr_src.ctr502->array[i].comment);
+ netname, path, remark);
if (opt_verbose)
- display_sec_desc(ctr_src.ctr502->array[i].sd);
+ display_sec_desc(ctr_src.share.info502[i].info_502_str.sd);
/* init info */
ZERO_STRUCT(info);
+ info.switch_value = level;
+ info.ptr_share_ctr = 1;
+
+ /* FIXME: shouldn't we be able to just set the security descriptor ? */
+ info.share.info502 = ctr_src.share.info502[i];
+
/* finally modify the share on the dst server */
- result = rpccli_srvsvc_NetShareSetInfo(
- srvsvc_pipe, mem_ctx, NULL, argv[0], level, info,
- &parm_error);
+ result = rpccli_srvsvc_net_share_set_info(srvsvc_pipe, mem_ctx, netname, level, &info);
- if (!NT_STATUS_IS_OK(result)) {
- printf("cannot set share-acl: %s\n", nt_errstr(result));
+ if (!W_ERROR_IS_OK(result)) {
+ printf("cannot set share-acl: %s\n", dos_errstr(result));
goto done;
}
@@ -3995,7 +4083,7 @@ static NTSTATUS rpc_aliaslist_dump(const DOM_SID *domain_sid,
for (i=0; i<num_server_aliases; i++) {
char **names;
char **domains;
- enum lsa_SidType *types;
+ uint32 *types;
int j;
struct full_alias *alias = &server_aliases[i];
@@ -4029,7 +4117,7 @@ static NTSTATUS rpc_aliaslist_dump(const DOM_SID *domain_sid,
DEBUG(1, ("\n"));
}
- rpccli_lsa_Close(pipe_hnd, mem_ctx, &lsa_pol);
+ rpccli_lsa_close(pipe_hnd, mem_ctx, &lsa_pol);
return NT_STATUS_OK;
}
@@ -4074,11 +4162,7 @@ static void init_user_token(NT_USER_TOKEN *token, DOM_SID *user_sid)
{
token->num_sids = 4;
- if (!(token->user_sids = SMB_MALLOC_ARRAY(DOM_SID, 4))) {
- d_fprintf(stderr, "malloc failed\n");
- token->num_sids = 0;
- return;
- }
+ token->user_sids = SMB_MALLOC_ARRAY(DOM_SID, 4);
token->user_sids[0] = *user_sid;
sid_copy(&token->user_sids[1], &global_sid_World);
@@ -4405,20 +4489,20 @@ static void show_userlist(struct rpc_pipe_client *pipe_hnd,
SEC_DESC *root_sd = NULL;
struct cli_state *cli = pipe_hnd->cli;
int i;
- union srvsvc_NetShareInfo info;
- NTSTATUS result;
+ SRV_SHARE_INFO info;
+ WERROR result;
uint16 cnum;
- result = rpccli_srvsvc_NetShareGetInfo(pipe_hnd, mem_ctx, NULL, netname,
+ result = rpccli_srvsvc_net_share_get_info(pipe_hnd, mem_ctx, netname,
502, &info);
- if (!NT_STATUS_IS_OK(result)) {
+ if (!W_ERROR_IS_OK(result)) {
DEBUG(1, ("Coult not query secdesc for share %s\n",
netname));
return;
}
- share_sd = info.info502->sd;
+ share_sd = info.share.info502.info_502_str.sd;
if (share_sd == NULL) {
DEBUG(1, ("Got no secdesc for share %s\n",
netname));
@@ -4532,7 +4616,7 @@ static NTSTATUS rpc_share_allowedusers_internals(const DOM_SID *domain_sid,
{
int ret;
BOOL r;
- uint32 hnd;
+ ENUM_HND hnd;
uint32 i;
FILE *f;
@@ -4570,7 +4654,8 @@ static NTSTATUS rpc_share_allowedusers_internals(const DOM_SID *domain_sid,
for (i=0; i<num_tokens; i++)
collect_alias_memberships(&tokens[i].token);
- hnd = 0;
+ init_enum_hnd(&hnd, 0);
+
share_list.num_shares = 0;
share_list.shares = NULL;
@@ -4701,10 +4786,7 @@ static NTSTATUS rpc_sh_share_add(TALLOC_CTX *mem_ctx,
struct rpc_pipe_client *pipe_hnd,
int argc, const char **argv)
{
- union srvsvc_NetShareInfo info;
- struct srvsvc_NetShareInfo2 info2;
- NTSTATUS result;
- uint32 parm_error = 0;
+ WERROR result;
if ((argc < 2) || (argc > 3)) {
d_fprintf(stderr, "usage: %s <share> <path> [comment]\n",
@@ -4712,15 +4794,12 @@ static NTSTATUS rpc_sh_share_add(TALLOC_CTX *mem_ctx,
return NT_STATUS_INVALID_PARAMETER;
}
- info.info2 = &info2;
- info2.name = argv[0];
- info2.type = STYPE_DISKTREE;
- info2.comment = (argc == 3) ? argv[2] : "";
-
- result = rpccli_srvsvc_NetShareAdd(
- pipe_hnd, mem_ctx, NULL, 2, info, &parm_error);
+ result = rpccli_srvsvc_net_share_add(
+ pipe_hnd, mem_ctx, argv[0], STYPE_DISKTREE,
+ (argc == 3) ? argv[2] : "",
+ 0, 0, 0, argv[1], NULL, 2, NULL);
- return result;
+ return werror_to_ntstatus(result);
}
static NTSTATUS rpc_sh_share_delete(TALLOC_CTX *mem_ctx,
@@ -4728,15 +4807,15 @@ static NTSTATUS rpc_sh_share_delete(TALLOC_CTX *mem_ctx,
struct rpc_pipe_client *pipe_hnd,
int argc, const char **argv)
{
- NTSTATUS result;
+ WERROR result;
if (argc != 1) {
d_fprintf(stderr, "usage: %s <share>\n", ctx->whoami);
return NT_STATUS_INVALID_PARAMETER;
}
- result = rpccli_srvsvc_NetShareDel(pipe_hnd, mem_ctx, NULL, argv[0], 0);
- return result;
+ result = rpccli_srvsvc_net_share_del(pipe_hnd, mem_ctx, argv[0]);
+ return werror_to_ntstatus(result);
}
static NTSTATUS rpc_sh_share_info(TALLOC_CTX *mem_ctx,
@@ -4744,27 +4823,37 @@ static NTSTATUS rpc_sh_share_info(TALLOC_CTX *mem_ctx,
struct rpc_pipe_client *pipe_hnd,
int argc, const char **argv)
{
- union srvsvc_NetShareInfo info;
- NTSTATUS result;
+ SRV_SHARE_INFO info;
+ SRV_SHARE_INFO_2 *info2 = &info.share.info2;
+ WERROR result;
if (argc != 1) {
d_fprintf(stderr, "usage: %s <share>\n", ctx->whoami);
return NT_STATUS_INVALID_PARAMETER;
}
- result = rpccli_srvsvc_NetShareGetInfo(
- pipe_hnd, mem_ctx, NULL, argv[0], 2, &info);
- if (!NT_STATUS_IS_OK(result)) {
+ result = rpccli_srvsvc_net_share_get_info(
+ pipe_hnd, mem_ctx, argv[0], 2, &info);
+ if (!W_ERROR_IS_OK(result)) {
goto done;
}
- d_printf("Name: %s\n", info.info2->name);
- d_printf("Comment: %s\n", info.info2->comment);
- d_printf("Path: %s\n", info.info2->path);
- d_printf("Password: %s\n", info.info2->password);
+ d_printf("Name: %s\n",
+ rpcstr_pull_unistr2_talloc(mem_ctx,
+ &info2->info_2_str.uni_netname));
+ d_printf("Comment: %s\n",
+ rpcstr_pull_unistr2_talloc(mem_ctx,
+ &info2->info_2_str.uni_remark));
+
+ d_printf("Path: %s\n",
+ rpcstr_pull_unistr2_talloc(mem_ctx,
+ &info2->info_2_str.uni_path));
+ d_printf("Password: %s\n",
+ rpcstr_pull_unistr2_talloc(mem_ctx,
+ &info2->info_2_str.uni_passwd));
done:
- return result;
+ return werror_to_ntstatus(result);
}
struct rpc_sh_cmd *net_rpc_share_cmds(TALLOC_CTX *mem_ctx,
@@ -4820,9 +4909,9 @@ static NTSTATUS rpc_file_close_internals(const DOM_SID *domain_sid,
int argc,
const char **argv)
{
- NTSTATUS result;
- result = rpccli_srvsvc_NetFileClose(pipe_hnd, mem_ctx, NULL, atoi(argv[0]));
- return NT_STATUS_IS_OK(result) ? NT_STATUS_OK : NT_STATUS_UNSUCCESSFUL;
+ WERROR result;
+ result = rpccli_srvsvc_net_file_close(pipe_hnd, mem_ctx, atoi(argv[0]));
+ return W_ERROR_IS_OK(result) ? NT_STATUS_OK : NT_STATUS_UNSUCCESSFUL;
}
/**
@@ -4853,10 +4942,15 @@ static int rpc_file_close(int argc, const char **argv)
* @param str3 strings for FILE_INFO_3
**/
-static void display_file_info_3( struct srvsvc_NetFileInfo3 *info3 )
+static void display_file_info_3( FILE_INFO_3 *info3 )
{
+ fstring user = "", path = "";
+
+ rpcstr_pull_unistr2_fstring(user, info3->user);
+ rpcstr_pull_unistr2_fstring(path, info3->path);
+
d_printf("%-7.1d %-20.20s 0x%-4.2x %-6.1d %s\n",
- info3->fid, info3->user, info3->permissions, info3->num_locks, info3->path);
+ info3->id, user, info3->perms, info3->num_locks, path);
}
/**
@@ -4883,25 +4977,22 @@ static NTSTATUS rpc_file_list_internals(const DOM_SID *domain_sid,
int argc,
const char **argv)
{
- union srvsvc_NetFileCtr ctr;
- NTSTATUS result;
- uint32 hnd;
+ SRV_FILE_INFO_CTR ctr;
+ WERROR result;
+ ENUM_HND hnd;
uint32 preferred_len = 0xffffffff, i;
const char *username=NULL;
- uint32 level = 3;
- uint32 numentries;
- hnd = 0;
+ init_enum_hnd(&hnd, 0);
/* if argc > 0, must be user command */
if (argc > 0)
username = smb_xstrdup(argv[0]);
- result = rpccli_srvsvc_NetFileEnum(pipe_hnd, mem_ctx, NULL, NULL,
- username, &level, &ctr,
- preferred_len, &numentries, &hnd);
+ result = rpccli_srvsvc_net_file_enum(pipe_hnd,
+ mem_ctx, 3, username, &ctr, preferred_len, &hnd);
- if (!NT_STATUS_IS_OK(result))
+ if (!W_ERROR_IS_OK(result))
goto done;
/* Display results */
@@ -4910,10 +5001,10 @@ static NTSTATUS rpc_file_list_internals(const DOM_SID *domain_sid,
"\nEnumerating open files on remote server:\n\n"\
"\nFileId Opened by Perms Locks Path"\
"\n------ --------- ----- ----- ---- \n");
- for (i = 0; i < numentries; i++)
- display_file_info_3(&ctr.ctr3->array[i]);
+ for (i = 0; i < ctr.num_entries; i++)
+ display_file_info_3(&ctr.file.info3[i]);
done:
- return NT_STATUS_IS_OK(result) ? NT_STATUS_OK : NT_STATUS_UNSUCCESSFUL;
+ return W_ERROR_IS_OK(result) ? NT_STATUS_OK : NT_STATUS_UNSUCCESSFUL;
}
/**
@@ -4990,7 +5081,7 @@ static NTSTATUS rpc_shutdown_abort_internals(const DOM_SID *domain_sid,
{
NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
- result = rpccli_initshutdown_Abort(pipe_hnd, mem_ctx, NULL);
+ result = rpccli_shutdown_abort(pipe_hnd, mem_ctx);
if (NT_STATUS_IS_OK(result)) {
d_printf("\nShutdown successfully aborted\n");
@@ -5027,7 +5118,7 @@ static NTSTATUS rpc_reg_shutdown_abort_internals(const DOM_SID *domain_sid,
{
NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
- result = rpccli_winreg_AbortSystemShutdown(pipe_hnd, mem_ctx, NULL);
+ result = werror_to_ntstatus(rpccli_reg_abort_shutdown(pipe_hnd, mem_ctx));
if (NT_STATUS_IS_OK(result)) {
d_printf("\nShutdown successfully aborted\n");
@@ -5050,7 +5141,7 @@ static NTSTATUS rpc_reg_shutdown_abort_internals(const DOM_SID *domain_sid,
static int rpc_shutdown_abort(int argc, const char **argv)
{
- int rc = run_rpc_command(NULL, PI_INITSHUTDOWN, 0,
+ int rc = run_rpc_command(NULL, PI_SHUTDOWN, 0,
rpc_shutdown_abort_internals,
argc, argv);
@@ -5091,8 +5182,6 @@ static NTSTATUS rpc_init_shutdown_internals(const DOM_SID *domain_sid,
NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
const char *msg = "This machine will be shutdown shortly";
uint32 timeout = 20;
- struct initshutdown_String msg_string;
- struct initshutdown_String_sub s;
if (opt_comment) {
msg = opt_comment;
@@ -5101,12 +5190,9 @@ static NTSTATUS rpc_init_shutdown_internals(const DOM_SID *domain_sid,
timeout = opt_timeout;
}
- s.name = msg;
- msg_string.name = &s;
-
/* create an entry */
- result = rpccli_initshutdown_Init(pipe_hnd, mem_ctx, NULL,
- &msg_string, timeout, opt_force, opt_reboot);
+ result = rpccli_shutdown_init(pipe_hnd, mem_ctx, msg, timeout, opt_reboot,
+ opt_force);
if (NT_STATUS_IS_OK(result)) {
d_printf("\nShutdown of remote machine succeeded\n");
@@ -5141,37 +5227,55 @@ static NTSTATUS rpc_reg_shutdown_internals(const DOM_SID *domain_sid,
int argc,
const char **argv)
{
+ WERROR result;
const char *msg = "This machine will be shutdown shortly";
uint32 timeout = 20;
- struct initshutdown_String msg_string;
- struct initshutdown_String_sub s;
- NTSTATUS result;
+#if 0
+ poptContext pc;
+ int rc;
+
+ struct poptOption long_options[] = {
+ {"message", 'm', POPT_ARG_STRING, &msg},
+ {"timeout", 't', POPT_ARG_INT, &timeout},
+ {"reboot", 'r', POPT_ARG_NONE, &reboot},
+ {"force", 'f', POPT_ARG_NONE, &force},
+ { 0, 0, 0, 0}
+ };
+
+ pc = poptGetContext(NULL, argc, (const char **) argv, long_options,
+ POPT_CONTEXT_KEEP_FIRST);
+ rc = poptGetNextOpt(pc);
+
+ if (rc < -1) {
+ /* an error occurred during option processing */
+ DEBUG(0, ("%s: %s\n",
+ poptBadOption(pc, POPT_BADOPTION_NOALIAS),
+ poptStrerror(rc)));
+ return NT_STATUS_INVALID_PARAMETER;
+ }
+#endif
if (opt_comment) {
msg = opt_comment;
}
- s.name = msg;
- msg_string.name = &s;
-
if (opt_timeout) {
timeout = opt_timeout;
}
/* create an entry */
- result = rpccli_winreg_InitiateSystemShutdown(pipe_hnd, mem_ctx, NULL,
- &msg_string, timeout, opt_force, opt_reboot);
+ result = rpccli_reg_shutdown(pipe_hnd, mem_ctx, msg, timeout, opt_reboot, opt_force);
- if (NT_STATUS_IS_OK(result)) {
+ if (W_ERROR_IS_OK(result)) {
d_printf("\nShutdown of remote machine succeeded\n");
} else {
d_fprintf(stderr, "\nShutdown of remote machine failed\n");
- if ( W_ERROR_EQUAL(ntstatus_to_werror(result),WERR_MACHINE_LOCKED) )
+ if (W_ERROR_EQUAL(result,WERR_MACHINE_LOCKED))
d_fprintf(stderr, "\nMachine locked, use -f switch to force\n");
else
- d_fprintf(stderr, "\nresult was: %s\n", nt_errstr(result));
+ d_fprintf(stderr, "\nresult was: %s\n", dos_errstr(result));
}
- return result;
+ return werror_to_ntstatus(result);
}
/**
@@ -5186,7 +5290,7 @@ static NTSTATUS rpc_reg_shutdown_internals(const DOM_SID *domain_sid,
static int rpc_shutdown(int argc, const char **argv)
{
- int rc = run_rpc_command(NULL, PI_INITSHUTDOWN, 0,
+ int rc = run_rpc_command(NULL, PI_SHUTDOWN, 0,
rpc_init_shutdown_internals,
argc, argv);
@@ -5620,7 +5724,9 @@ static int rpc_trustdom_establish(int argc, const char **argv)
* Store the password in secrets db
*/
- if (!pdb_set_trusteddom_pw(domain_name, opt_password, domain_sid)) {
+ if (!secrets_store_trusted_domain_password(domain_name,
+ opt_password,
+ domain_sid)) {
DEBUG(0, ("Storing password for trusted domain failed.\n"));
cli_shutdown(cli);
talloc_destroy(mem_ctx);
@@ -5631,7 +5737,7 @@ static int rpc_trustdom_establish(int argc, const char **argv)
* Close the pipes and clean up
*/
- nt_status = rpccli_lsa_Close(pipe_hnd, mem_ctx, &connect_hnd);
+ nt_status = rpccli_lsa_close(pipe_hnd, mem_ctx, &connect_hnd);
if (NT_STATUS_IS_ERR(nt_status)) {
DEBUG(0, ("Couldn't close LSA pipe. Error was %s\n",
nt_errstr(nt_status)));
@@ -5660,7 +5766,6 @@ static int rpc_trustdom_establish(int argc, const char **argv)
static int rpc_trustdom_revoke(int argc, const char **argv)
{
char* domain_name;
- int rc = -1;
if (argc < 1) return -1;
@@ -5669,16 +5774,13 @@ static int rpc_trustdom_revoke(int argc, const char **argv)
strupper_m(domain_name);
/* delete password of the trust */
- if (!pdb_del_trusteddom_pw(domain_name)) {
+ if (!trusted_domain_password_delete(domain_name)) {
DEBUG(0, ("Failed to revoke relationship to the trusted domain %s\n",
domain_name));
- goto done;
+ return -1;
};
- rc = 0;
-done:
- SAFE_FREE(domain_name);
- return rc;
+ return 0;
}
/**
@@ -5764,7 +5866,9 @@ static NTSTATUS vampire_trusted_domain(struct rpc_pipe_client *pipe_hnd,
goto done;
}
- if (!pdb_set_trusteddom_pw(trusted_dom_name, cleartextpwd, &dom_sid)) {
+ if (!secrets_store_trusted_domain_password(trusted_dom_name,
+ cleartextpwd,
+ &dom_sid)) {
DEBUG(0, ("Storing password for trusted domain failed.\n"));
nt_status = NT_STATUS_UNSUCCESSFUL;
goto done;
@@ -5902,7 +6006,7 @@ static int rpc_trustdom_vampire(int argc, const char **argv)
} while (NT_STATUS_EQUAL(nt_status, STATUS_MORE_ENTRIES));
/* close this connection before doing next one */
- nt_status = rpccli_lsa_Close(pipe_hnd, mem_ctx, &connect_hnd);
+ nt_status = rpccli_lsa_close(pipe_hnd, mem_ctx, &connect_hnd);
if (NT_STATUS_IS_ERR(nt_status)) {
DEBUG(0, ("Couldn't properly close lsa policy handle. Error was %s\n",
nt_errstr(nt_status)));
@@ -6036,7 +6140,7 @@ static int rpc_trustdom_list(int argc, const char **argv)
} while (NT_STATUS_EQUAL(nt_status, STATUS_MORE_ENTRIES));
/* close this connection before doing next one */
- nt_status = rpccli_lsa_Close(pipe_hnd, mem_ctx, &connect_hnd);
+ nt_status = rpccli_lsa_close(pipe_hnd, mem_ctx, &connect_hnd);
if (NT_STATUS_IS_ERR(nt_status)) {
DEBUG(0, ("Couldn't properly close lsa policy handle. Error was %s\n",
nt_errstr(nt_status)));
diff --git a/source/utils/net_rpc_join.c b/source/utils/net_rpc_join.c
index ba3c6190126..d23bd767519 100644
--- a/source/utils/net_rpc_join.c
+++ b/source/utils/net_rpc_join.c
@@ -193,7 +193,7 @@ int net_rpc_join_newstyle(int argc, const char **argv)
5, &domain, &domain_sid),
"error querying info policy");
- rpccli_lsa_Close(pipe_hnd, mem_ctx, &lsa_pol);
+ rpccli_lsa_close(pipe_hnd, mem_ctx, &lsa_pol);
cli_rpc_pipe_close(pipe_hnd); /* Done with this pipe */
/* Bail out if domain didn't get set. */
diff --git a/source/utils/net_rpc_printer.c b/source/utils/net_rpc_printer.c
index 6f9d52ddec9..1f277338521 100644
--- a/source/utils/net_rpc_printer.c
+++ b/source/utils/net_rpc_printer.c
@@ -129,22 +129,18 @@ static void display_reg_value(const char *subkey, REGISTRY_VALUE value)
break;
case REG_MULTI_SZ: {
- uint32 i, num_values;
- char **values;
-
- if (!W_ERROR_IS_OK(reg_pull_multi_sz(NULL, value.data_p,
- value.size, &num_values,
- &values))) {
- d_printf("reg_pull_multi_sz failed\n");
- break;
+ uint16 *curstr = (uint16 *) value.data_p;
+ uint8 *start = value.data_p;
+ d_printf("\t[%s:%s]: REG_MULTI_SZ:\n", subkey, value.valuename);
+ while ((*curstr != 0) &&
+ ((uint8 *) curstr < start + value.size)) {
+ rpcstr_pull(text, curstr, sizeof(text), -1,
+ STR_TERMINATE);
+ d_printf("%s\n", text);
+ curstr += strlen(text) + 1;
}
-
- for (i=0; i<num_values; i++) {
- d_printf("%s\n", values[i]);
- }
- TALLOC_FREE(values);
- break;
}
+ break;
default:
d_printf("\t%s: unknown type %d\n", value.valuename, value.type);
@@ -2170,7 +2166,7 @@ NTSTATUS rpc_printer_migrate_settings_internals(const DOM_SID *domain_sid,
if (ctr_enum.printers_2[i].devmode != NULL) {
/* copy devmode (info level 2) */
- ctr_dst.printers_2->devmode = (DEVICEMODE *)
+ ctr_dst.printers_2->devmode =
TALLOC_MEMDUP(mem_ctx,
ctr_enum.printers_2[i].devmode,
sizeof(DEVICEMODE));
@@ -2332,7 +2328,7 @@ NTSTATUS rpc_printer_migrate_settings_internals(const DOM_SID *domain_sid,
value.type = REG_SZ;
value.size = data.uni_str_len * 2;
if (value.size) {
- value.data_p = (uint8 *)TALLOC_MEMDUP(mem_ctx, data.buffer, value.size);
+ value.data_p = TALLOC_MEMDUP(mem_ctx, data.buffer, value.size);
} else {
value.data_p = NULL;
}
diff --git a/source/utils/net_rpc_registry.c b/source/utils/net_rpc_registry.c
index b439f50ee44..873cb7b4597 100644
--- a/source/utils/net_rpc_registry.c
+++ b/source/utils/net_rpc_registry.c
@@ -1,8 +1,7 @@
/*
Samba Unix/Linux SMB client library
Distributed SMB/CIFS Server Management Utility
-
- Copyright (C) Gerald (Jerry) Carter 2005-2006
+ Copyright (C) Gerald (Jerry) Carter 2005
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
@@ -23,547 +22,63 @@
#include "regfio.h"
#include "reg_objects.h"
-static BOOL reg_hive_key(const char *fullname, uint32 *reg_type,
- const char **key_name)
-{
- const char *sep;
- ptrdiff_t len;
-
- sep = strchr_m(fullname, '\\');
-
- if (sep != NULL) {
- len = sep - fullname;
- *key_name = sep+1;
- }
- else {
- len = strlen(fullname);
- *key_name = "";
- }
-
- if (strnequal(fullname, "HKLM", len) ||
- strnequal(fullname, "HKEY_LOCAL_MACHINE", len))
- (*reg_type) = HKEY_LOCAL_MACHINE;
- else if (strnequal(fullname, "HKCR", len) ||
- strnequal(fullname, "HKEY_CLASSES_ROOT", len))
- (*reg_type) = HKEY_CLASSES_ROOT;
- else if (strnequal(fullname, "HKU", len) ||
- strnequal(fullname, "HKEY_USERS", len))
- (*reg_type) = HKEY_USERS;
- else if (strnequal(fullname, "HKPD", len) ||
- strnequal(fullname, "HKEY_PERFORMANCE_DATA", len))
- (*reg_type) = HKEY_PERFORMANCE_DATA;
- else {
- DEBUG(10,("reg_hive_key: unrecognised hive key %s\n",
- fullname));
- return False;
- }
-
- return True;
-}
-
-static NTSTATUS registry_openkey(TALLOC_CTX *mem_ctx,
- struct rpc_pipe_client *pipe_hnd,
- const char *name, uint32 access_mask,
- struct policy_handle *hive_hnd,
- struct policy_handle *key_hnd)
-{
- uint32 hive;
- NTSTATUS status;
- struct winreg_String key;
-
- if (!reg_hive_key(name, &hive, &key.name)) {
- return NT_STATUS_INVALID_PARAMETER;
- }
-
- status = rpccli_winreg_Connect(pipe_hnd, mem_ctx, hive, access_mask,
- hive_hnd);
- if (!(NT_STATUS_IS_OK(status))) {
- return status;
- }
-
- status = rpccli_winreg_OpenKey(pipe_hnd, mem_ctx, hive_hnd, key, 0,
- access_mask, key_hnd);
- if (!(NT_STATUS_IS_OK(status))) {
- rpccli_winreg_CloseKey(pipe_hnd, mem_ctx, hive_hnd);
- return status;
- }
-
- return NT_STATUS_OK;
-}
-
-static NTSTATUS registry_enumkeys(TALLOC_CTX *ctx,
- struct rpc_pipe_client *pipe_hnd,
- struct policy_handle *key_hnd,
- uint32 *pnum_keys, char ***pnames,
- char ***pclasses, NTTIME ***pmodtimes)
-{
- TALLOC_CTX *mem_ctx;
- NTSTATUS status;
- uint32 num_subkeys, max_subkeylen, max_classlen;
- uint32 num_values, max_valnamelen, max_valbufsize;
- uint32 i;
- NTTIME last_changed_time;
- uint32 secdescsize;
- struct winreg_String classname;
- char **names, **classes;
- NTTIME **modtimes;
-
- if (!(mem_ctx = talloc_new(ctx))) {
- return NT_STATUS_NO_MEMORY;
- }
-
- ZERO_STRUCT(classname);
- status = rpccli_winreg_QueryInfoKey(
- pipe_hnd, mem_ctx, key_hnd, &classname, &num_subkeys,
- &max_subkeylen, &max_classlen, &num_values, &max_valnamelen,
- &max_valbufsize, &secdescsize, &last_changed_time );
-
- if (!NT_STATUS_IS_OK(status)) {
- goto error;
- }
-
- if (num_subkeys == 0) {
- *pnum_keys = 0;
- TALLOC_FREE(mem_ctx);
- return NT_STATUS_OK;
- }
-
- if ((!(names = TALLOC_ZERO_ARRAY(mem_ctx, char *, num_subkeys))) ||
- (!(classes = TALLOC_ZERO_ARRAY(mem_ctx, char *, num_subkeys))) ||
- (!(modtimes = TALLOC_ZERO_ARRAY(mem_ctx, NTTIME *,
- num_subkeys)))) {
- status = NT_STATUS_NO_MEMORY;
- goto error;
- }
-
- for (i=0; i<num_subkeys; i++) {
- char c, n;
- struct winreg_StringBuf class_buf;
- struct winreg_StringBuf name_buf;
- NTTIME modtime;
-
- c = '\0';
- class_buf.name = &c;
- class_buf.size = max_classlen+2;
-
- n = '\0';
- name_buf.name = &n;
- name_buf.size = max_subkeylen+2;
-
- ZERO_STRUCT(modtime);
-
- status = rpccli_winreg_EnumKey(pipe_hnd, mem_ctx, key_hnd,
- i, &name_buf, &class_buf,
- &modtime);
-
- if (W_ERROR_EQUAL(ntstatus_to_werror(status),
- WERR_NO_MORE_ITEMS) ) {
- status = NT_STATUS_OK;
- break;
- }
- if (!NT_STATUS_IS_OK(status)) {
- goto error;
- }
-
- classes[i] = NULL;
-
- if (class_buf.name &&
- (!(classes[i] = talloc_strdup(classes, class_buf.name)))) {
- status = NT_STATUS_NO_MEMORY;
- goto error;
- }
-
- if (!(names[i] = talloc_strdup(names, name_buf.name))) {
- status = NT_STATUS_NO_MEMORY;
- goto error;
- }
-
- if ((!(modtimes[i] = (NTTIME *)talloc_memdup(
- modtimes, &modtime, sizeof(modtime))))) {
- status = NT_STATUS_NO_MEMORY;
- goto error;
- }
- }
-
- *pnum_keys = num_subkeys;
-
- if (pnames) {
- *pnames = talloc_move(ctx, &names);
- }
- if (pclasses) {
- *pclasses = talloc_move(ctx, &classes);
- }
- if (pmodtimes) {
- *pmodtimes = talloc_move(ctx, &modtimes);
- }
-
- status = NT_STATUS_OK;
-
- error:
- TALLOC_FREE(mem_ctx);
- return status;
-}
-
-static NTSTATUS registry_enumvalues(TALLOC_CTX *ctx,
- struct rpc_pipe_client *pipe_hnd,
- struct policy_handle *key_hnd,
- uint32 *pnum_values, char ***pvalnames,
- struct registry_value ***pvalues)
-{
- TALLOC_CTX *mem_ctx;
- NTSTATUS status;
- uint32 num_subkeys, max_subkeylen, max_classlen;
- uint32 num_values, max_valnamelen, max_valbufsize;
- uint32 i;
- NTTIME last_changed_time;
- uint32 secdescsize;
- struct winreg_String classname;
- struct registry_value **values;
- char **names;
-
- if (!(mem_ctx = talloc_new(ctx))) {
- return NT_STATUS_NO_MEMORY;
- }
-
- ZERO_STRUCT(classname);
- status = rpccli_winreg_QueryInfoKey(
- pipe_hnd, mem_ctx, key_hnd, &classname, &num_subkeys,
- &max_subkeylen, &max_classlen, &num_values, &max_valnamelen,
- &max_valbufsize, &secdescsize, &last_changed_time );
-
- if (!NT_STATUS_IS_OK(status)) {
- goto error;
- }
-
- if (num_values == 0) {
- *pnum_values = 0;
- TALLOC_FREE(mem_ctx);
- return NT_STATUS_OK;
- }
-
- if ((!(names = TALLOC_ARRAY(mem_ctx, char *, num_values))) ||
- (!(values = TALLOC_ARRAY(mem_ctx, struct registry_value *,
- num_values)))) {
- status = NT_STATUS_NO_MEMORY;
- goto error;
- }
-
- for (i=0; i<num_values; i++) {
- enum winreg_Type type = REG_NONE;
- uint8 *data = NULL;
- uint32 data_size;
- uint32 value_length;
-
- char n;
- struct winreg_ValNameBuf name_buf;
- WERROR err;
-
- n = '\0';
- name_buf.name = &n;
- name_buf.size = max_valnamelen + 2;
-
- data_size = max_valbufsize;
- data = (uint8 *)TALLOC(mem_ctx, data_size);
- value_length = 0;
-
- status = rpccli_winreg_EnumValue(pipe_hnd, mem_ctx, key_hnd,
- i, &name_buf, &type,
- data, &data_size,
- &value_length );
-
- if ( W_ERROR_EQUAL(ntstatus_to_werror(status),
- WERR_NO_MORE_ITEMS) ) {
- status = NT_STATUS_OK;
- break;
- }
-
- if (!(NT_STATUS_IS_OK(status))) {
- goto error;
- }
-
- if (name_buf.name == NULL) {
- status = NT_STATUS_INVALID_PARAMETER;
- goto error;
- }
-
- if (!(names[i] = talloc_strdup(names, name_buf.name))) {
- status = NT_STATUS_NO_MEMORY;
- goto error;
- }
-
- err = registry_pull_value(values, &values[i], type, data,
- data_size, value_length);
- if (!W_ERROR_IS_OK(err)) {
- status = werror_to_ntstatus(err);
- goto error;
- }
- }
-
- *pnum_values = num_values;
-
- if (pvalnames) {
- *pvalnames = talloc_move(ctx, &names);
- }
- if (pvalues) {
- *pvalues = talloc_move(ctx, &values);
- }
-
- status = NT_STATUS_OK;
-
- error:
- TALLOC_FREE(mem_ctx);
- return status;
-}
-
-static NTSTATUS registry_setvalue(TALLOC_CTX *mem_ctx,
- struct rpc_pipe_client *pipe_hnd,
- struct policy_handle *key_hnd,
- const char *name,
- const struct registry_value *value)
-{
- struct winreg_String name_string;
- DATA_BLOB blob;
- NTSTATUS result;
- WERROR err;
-
- err = registry_push_value(mem_ctx, value, &blob);
- if (!W_ERROR_IS_OK(err)) {
- return werror_to_ntstatus(err);
- }
-
- name_string.name = name;
- result = rpccli_winreg_SetValue(pipe_hnd, blob.data, key_hnd,
- name_string, value->type,
- blob.data, blob.length);
- TALLOC_FREE(blob.data);
- return result;
-}
-
-static NTSTATUS rpc_registry_setvalue_internal(const DOM_SID *domain_sid,
- const char *domain_name,
- struct cli_state *cli,
- struct rpc_pipe_client *pipe_hnd,
- TALLOC_CTX *mem_ctx,
- int argc,
- const char **argv )
-{
- struct policy_handle hive_hnd, key_hnd;
- NTSTATUS status;
- struct registry_value value;
-
- status = registry_openkey(mem_ctx, pipe_hnd, argv[0], REG_KEY_WRITE,
- &hive_hnd, &key_hnd);
- if (!NT_STATUS_IS_OK(status)) {
- d_fprintf(stderr, "registry_openkey failed: %s\n",
- nt_errstr(status));
- return status;
- }
-
- if (!strequal(argv[2], "multi_sz") && (argc != 4)) {
- d_fprintf(stderr, "Too many args for type %s\n", argv[2]);
- return NT_STATUS_NOT_IMPLEMENTED;
- }
-
- if (strequal(argv[2], "dword")) {
- value.type = REG_DWORD;
- value.v.dword = strtoul(argv[3], NULL, 10);
- }
- else if (strequal(argv[2], "sz")) {
- value.type = REG_SZ;
- value.v.sz.len = strlen(argv[3])+1;
- value.v.sz.str = CONST_DISCARD(char *, argv[3]);
- }
- else {
- d_fprintf(stderr, "type \"%s\" not implemented\n", argv[2]);
- status = NT_STATUS_NOT_IMPLEMENTED;
- goto error;
- }
-
- status = registry_setvalue(mem_ctx, pipe_hnd, &key_hnd,
- argv[1], &value);
-
- if (!NT_STATUS_IS_OK(status)) {
- d_fprintf(stderr, "registry_setvalue failed: %s\n",
- nt_errstr(status));
- }
-
- error:
- rpccli_winreg_CloseKey(pipe_hnd, mem_ctx, &key_hnd);
- rpccli_winreg_CloseKey(pipe_hnd, mem_ctx, &hive_hnd);
-
- return NT_STATUS_OK;
-}
-
-static int rpc_registry_setvalue( int argc, const char **argv )
-{
- if (argc < 4) {
- d_fprintf(stderr, "usage: net rpc registry setvalue <key> "
- "<valuename> <type> [<val>]+\n");
- return -1;
- }
-
- return run_rpc_command( NULL, PI_WINREG, 0,
- rpc_registry_setvalue_internal, argc, argv );
-}
-
-static NTSTATUS rpc_registry_deletevalue_internal(const DOM_SID *domain_sid,
- const char *domain_name,
- struct cli_state *cli,
- struct rpc_pipe_client *pipe_hnd,
- TALLOC_CTX *mem_ctx,
- int argc,
- const char **argv )
-{
- struct policy_handle hive_hnd, key_hnd;
- NTSTATUS status;
- struct winreg_String valuename;
-
- status = registry_openkey(mem_ctx, pipe_hnd, argv[0], REG_KEY_WRITE,
- &hive_hnd, &key_hnd);
- if (!NT_STATUS_IS_OK(status)) {
- d_fprintf(stderr, "registry_openkey failed: %s\n",
- nt_errstr(status));
- return status;
- }
-
- valuename.name = argv[1];
-
- status = rpccli_winreg_DeleteValue(pipe_hnd, mem_ctx, &key_hnd,
- valuename);
-
- if (!NT_STATUS_IS_OK(status)) {
- d_fprintf(stderr, "registry_deletevalue failed: %s\n",
- nt_errstr(status));
- }
-
- rpccli_winreg_CloseKey(pipe_hnd, mem_ctx, &key_hnd);
- rpccli_winreg_CloseKey(pipe_hnd, mem_ctx, &hive_hnd);
-
- return NT_STATUS_OK;
-}
-
-static int rpc_registry_deletevalue( int argc, const char **argv )
-{
- if (argc != 2) {
- d_fprintf(stderr, "usage: net rpc registry deletevalue <key> "
- "<valuename>\n");
- return -1;
- }
-
- return run_rpc_command( NULL, PI_WINREG, 0,
- rpc_registry_deletevalue_internal, argc, argv );
-}
-
-static NTSTATUS rpc_registry_createkey_internal(const DOM_SID *domain_sid,
- const char *domain_name,
- struct cli_state *cli,
- struct rpc_pipe_client *pipe_hnd,
- TALLOC_CTX *mem_ctx,
- int argc,
- const char **argv )
-{
- uint32 hive;
- struct policy_handle hive_hnd, key_hnd;
- struct winreg_String key, keyclass;
- enum winreg_CreateAction action;
- NTSTATUS status;
-
- if (!reg_hive_key(argv[0], &hive, &key.name)) {
- return NT_STATUS_INVALID_PARAMETER;
- }
-
- status = rpccli_winreg_Connect(pipe_hnd, mem_ctx, hive,
- REG_KEY_READ|REG_KEY_WRITE,
- &hive_hnd);
- if (!(NT_STATUS_IS_OK(status))) {
- return status;
- }
-
- action = REG_ACTION_NONE;
- keyclass.name = "";
-
- status = rpccli_winreg_CreateKey(pipe_hnd, mem_ctx, &hive_hnd, key,
- keyclass, 0, REG_KEY_READ, NULL,
- &key_hnd, &action);
- if (!NT_STATUS_IS_OK(status)) {
- d_fprintf(stderr, "createkey returned %s\n",
- nt_errstr(status));
- rpccli_winreg_CloseKey(pipe_hnd, mem_ctx, &hive_hnd);
- return status;
- }
-
- switch (action) {
- case REG_ACTION_NONE:
- d_printf("createkey did nothing -- huh?\n");
- break;
- case REG_CREATED_NEW_KEY:
- d_printf("createkey created %s\n", argv[0]);
- break;
- case REG_OPENED_EXISTING_KEY:
- d_printf("createkey opened existing %s\n", argv[0]);
- break;
- }
-
- rpccli_winreg_CloseKey(pipe_hnd, mem_ctx, &key_hnd);
- rpccli_winreg_CloseKey(pipe_hnd, mem_ctx, &hive_hnd);
-
- return status;
-}
-
-static int rpc_registry_createkey( int argc, const char **argv )
-{
- if (argc != 1) {
- d_fprintf(stderr, "usage: net rpc registry createkey <key>\n");
- return -1;
- }
-
- return run_rpc_command( NULL, PI_WINREG, 0,
- rpc_registry_createkey_internal, argc, argv );
-}
+/********************************************************************
+********************************************************************/
-static NTSTATUS rpc_registry_deletekey_internal(const DOM_SID *domain_sid,
- const char *domain_name,
- struct cli_state *cli,
- struct rpc_pipe_client *pipe_hnd,
- TALLOC_CTX *mem_ctx,
- int argc,
- const char **argv )
+char* dump_regval_type( uint32 type )
{
- uint32 hive;
- struct policy_handle hive_hnd;
- struct winreg_String key;
- NTSTATUS status;
-
- if (!reg_hive_key(argv[0], &hive, &key.name)) {
- return NT_STATUS_INVALID_PARAMETER;
- }
-
- status = rpccli_winreg_Connect(pipe_hnd, mem_ctx, hive, REG_KEY_WRITE,
- &hive_hnd);
- if (!(NT_STATUS_IS_OK(status))) {
- return status;
- }
-
- status = rpccli_winreg_DeleteKey(pipe_hnd, mem_ctx, &hive_hnd, key);
- rpccli_winreg_CloseKey(pipe_hnd, mem_ctx, &hive_hnd);
-
- if (!NT_STATUS_IS_OK(status)) {
- d_fprintf(stderr, "deletekey returned %s\n",
- nt_errstr(status));
+ static fstring string;
+
+ switch (type) {
+ case REG_SZ:
+ fstrcpy( string, "REG_SZ" );
+ break;
+ case REG_MULTI_SZ:
+ fstrcpy( string, "REG_MULTI_SZ" );
+ break;
+ case REG_EXPAND_SZ:
+ fstrcpy( string, "REG_EXPAND_SZ" );
+ break;
+ case REG_DWORD:
+ fstrcpy( string, "REG_DWORD" );
+ break;
+ case REG_BINARY:
+ fstrcpy( string, "REG_BINARY" );
+ break;
+ default:
+ fstr_sprintf( string, "UNKNOWN [%d]", type );
}
-
- return status;
+
+ return string;
}
+/********************************************************************
+********************************************************************/
-static int rpc_registry_deletekey( int argc, const char **argv )
+void dump_regval_buffer( uint32 type, REGVAL_BUFFER *buffer )
{
- if (argc != 1) {
- d_fprintf(stderr, "usage: net rpc registry deletekey <key>\n");
- return -1;
+ pstring string;
+ uint32 value;
+
+ switch (type) {
+ case REG_SZ:
+ rpcstr_pull( string, buffer->buffer, sizeof(string), -1, STR_TERMINATE );
+ d_printf("%s\n", string);
+ break;
+ case REG_MULTI_SZ:
+ d_printf("\n");
+ break;
+ case REG_DWORD:
+ value = IVAL( buffer->buffer, 0 );
+ d_printf( "0x%x\n", value );
+ break;
+ case REG_BINARY:
+ d_printf("\n");
+ break;
+
+
+ default:
+ d_printf( "\tUnknown type [%d]\n", type );
}
-
- return run_rpc_command( NULL, PI_WINREG, 0,
- rpc_registry_deletekey_internal, argc, argv );
}
/********************************************************************
@@ -577,90 +92,104 @@ static NTSTATUS rpc_registry_enumerate_internal(const DOM_SID *domain_sid,
int argc,
const char **argv )
{
+ WERROR result = WERR_GENERAL_FAILURE;
+ uint32 hive;
+ pstring subpath;
POLICY_HND pol_hive, pol_key;
- NTSTATUS status;
- uint32 num_subkeys = 0;
- uint32 num_values = 0;
- char **names = NULL, **classes = NULL;
- NTTIME **modtimes = NULL;
- uint32 i;
- struct registry_value **values = NULL;
+ uint32 idx;
if (argc != 1 ) {
d_printf("Usage: net rpc enumerate <path> [recurse]\n");
d_printf("Example: net rpc enumerate 'HKLM\\Software\\Samba'\n");
return NT_STATUS_OK;
}
-
- status = registry_openkey(mem_ctx, pipe_hnd, argv[0], REG_KEY_READ,
- &pol_hive, &pol_key);
- if (!NT_STATUS_IS_OK(status)) {
- d_fprintf(stderr, "registry_openkey failed: %s\n",
- nt_errstr(status));
- return status;
+
+ if ( !reg_split_hive( argv[0], &hive, subpath ) ) {
+ d_fprintf(stderr, "invalid registry path\n");
+ return NT_STATUS_OK;
}
-
- status = registry_enumkeys(mem_ctx, pipe_hnd, &pol_key, &num_subkeys,
- &names, &classes, &modtimes);
- if (!NT_STATUS_IS_OK(status)) {
- d_fprintf(stderr, "enumerating keys failed: %s\n",
- nt_errstr(status));
- return status;
+
+ /* open the top level hive and then the registry key */
+
+ result = rpccli_reg_connect(pipe_hnd, mem_ctx, hive, MAXIMUM_ALLOWED_ACCESS, &pol_hive );
+ if ( !W_ERROR_IS_OK(result) ) {
+ d_fprintf(stderr, "Unable to connect to remote registry\n");
+ return werror_to_ntstatus(result);
}
-
- for (i=0; i<num_subkeys; i++) {
- d_printf("Keyname = %s\n", names[i]);
- d_printf("Modtime = %s\n", modtimes[i]
- ? http_timestring(nt_time_to_unix(*modtimes[i]))
- : "None");
- d_printf("\n" );
+
+ if ( strlen( subpath ) != 0 ) {
+ result = rpccli_reg_open_entry(pipe_hnd, mem_ctx, &pol_hive, subpath, MAXIMUM_ALLOWED_ACCESS, &pol_key );
+ if ( !W_ERROR_IS_OK(result) ) {
+ d_fprintf(stderr, "Unable to open [%s]\n", argv[0]);
+ return werror_to_ntstatus(result);
+ }
}
+
+ /* get the subkeys */
+
+ result = WERR_OK;
+ idx = 0;
+ while ( W_ERROR_IS_OK(result) ) {
+ time_t modtime;
+ fstring keyname, classname;
+
+ result = rpccli_reg_enum_key(pipe_hnd, mem_ctx, &pol_key, idx,
+ keyname, classname, &modtime );
+
+ if ( W_ERROR_EQUAL(result, WERR_NO_MORE_ITEMS) ) {
+ result = WERR_OK;
+ break;
+ }
+
+ d_printf("Keyname = %s\n", keyname );
+ d_printf("Classname = %s\n", classname );
+ d_printf("Modtime = %s\n", http_timestring(modtime) );
+ d_printf("\n" );
- status = registry_enumvalues(mem_ctx, pipe_hnd, &pol_key, &num_values,
- &names, &values);
- if (!NT_STATUS_IS_OK(status)) {
- d_fprintf(stderr, "enumerating values failed: %s\n",
- nt_errstr(status));
- return status;
+ idx++;
}
- for (i=0; i<num_values; i++) {
- struct registry_value *v = values[i];
- d_printf("Valuename = %s\n", names[i]);
- d_printf("Type = %s\n",
- reg_type_lookup(v->type));
- switch(v->type) {
- case REG_DWORD:
- d_printf("Value = %d\n", v->v.dword);
- break;
- case REG_SZ:
- case REG_EXPAND_SZ:
- d_printf("Value = \"%s\"\n", v->v.sz.str);
- break;
- case REG_MULTI_SZ: {
- uint32 j;
- for (j = 0; j < v->v.multi_sz.num_strings; j++) {
- d_printf("Value[%3.3d] = \"%s\"\n", j,
- v->v.multi_sz.strings[j]);
- }
- break;
- }
- case REG_BINARY:
- d_printf("Value = %d bytes\n",
- (int)v->v.binary.length);
- break;
- default:
- d_printf("Value = <unprintable>\n");
+ if ( !W_ERROR_IS_OK(result) )
+ goto out;
+
+ /* get the values */
+
+ result = WERR_OK;
+ idx = 0;
+ while ( W_ERROR_IS_OK(result) ) {
+ uint32 type;
+ fstring name;
+ REGVAL_BUFFER value;
+
+ fstrcpy( name, "" );
+ ZERO_STRUCT( value );
+
+ result = rpccli_reg_enum_val(pipe_hnd, mem_ctx, &pol_key, idx,
+ name, &type, &value );
+
+ if ( W_ERROR_EQUAL(result, WERR_NO_MORE_ITEMS) ) {
+ result = WERR_OK;
break;
}
- d_printf("\n");
- }
+ d_printf("Valuename = %s\n", name );
+ d_printf("Type = %s\n", dump_regval_type(type) );
+ d_printf("Data = " );
+ dump_regval_buffer( type, &value );
+ d_printf("\n" );
- rpccli_winreg_CloseKey(pipe_hnd, mem_ctx, &pol_key );
- rpccli_winreg_CloseKey(pipe_hnd, mem_ctx, &pol_hive );
+ idx++;
+ }
+
+
+out:
+ /* cleanup */
+
+ if ( strlen( subpath ) != 0 )
+ rpccli_reg_close(pipe_hnd, mem_ctx, &pol_key );
+ rpccli_reg_close(pipe_hnd, mem_ctx, &pol_hive );
- return status;
+ return werror_to_ntstatus(result);
}
/********************************************************************
@@ -684,35 +213,46 @@ static NTSTATUS rpc_registry_save_internal(const DOM_SID *domain_sid,
const char **argv )
{
WERROR result = WERR_GENERAL_FAILURE;
+ uint32 hive;
+ pstring subpath;
POLICY_HND pol_hive, pol_key;
- NTSTATUS status = NT_STATUS_UNSUCCESSFUL;
- struct winreg_String filename;
if (argc != 2 ) {
d_printf("Usage: net rpc backup <path> <file> \n");
return NT_STATUS_OK;
}
- status = registry_openkey(mem_ctx, pipe_hnd, argv[0], REG_KEY_ALL,
- &pol_hive, &pol_key);
- if (!NT_STATUS_IS_OK(status)) {
- d_fprintf(stderr, "registry_openkey failed: %s\n",
- nt_errstr(status));
- return status;
+ if ( !reg_split_hive( argv[0], &hive, subpath ) ) {
+ d_fprintf(stderr, "invalid registry path\n");
+ return NT_STATUS_OK;
}
-
- filename.name = argv[1];
- status = rpccli_winreg_SaveKey( pipe_hnd, mem_ctx, &pol_key, &filename, NULL );
+
+ /* open the top level hive and then the registry key */
+
+ result = rpccli_reg_connect(pipe_hnd, mem_ctx, hive, MAXIMUM_ALLOWED_ACCESS, &pol_hive );
+ if ( !W_ERROR_IS_OK(result) ) {
+ d_fprintf(stderr, "Unable to connect to remote registry\n");
+ return werror_to_ntstatus(result);
+ }
+
+ result = rpccli_reg_open_entry(pipe_hnd, mem_ctx, &pol_hive, subpath, MAXIMUM_ALLOWED_ACCESS, &pol_key );
+ if ( !W_ERROR_IS_OK(result) ) {
+ d_fprintf(stderr, "Unable to open [%s]\n", argv[0]);
+ return werror_to_ntstatus(result);
+ }
+
+ result = rpccli_reg_save_key(pipe_hnd, mem_ctx, &pol_key, argv[1] );
if ( !W_ERROR_IS_OK(result) ) {
d_fprintf(stderr, "Unable to save [%s] to %s:%s\n", argv[0], cli->desthost, argv[1]);
}
+
/* cleanup */
- rpccli_winreg_CloseKey(pipe_hnd, mem_ctx, &pol_key );
- rpccli_winreg_CloseKey(pipe_hnd, mem_ctx, &pol_hive );
+ rpccli_reg_close(pipe_hnd, mem_ctx, &pol_key );
+ rpccli_reg_close(pipe_hnd, mem_ctx, &pol_hive );
- return status;
+ return werror_to_ntstatus(result);
}
/********************************************************************
@@ -739,7 +279,7 @@ static void dump_values( REGF_NK_REC *nk )
for ( i=0; i<nk->num_values; i++ ) {
d_printf( "\"%s\" = ", nk->values[i].valuename ? nk->values[i].valuename : "(default)" );
- d_printf( "(%s) ", reg_type_lookup( nk->values[i].type ) );
+ d_printf( "(%s) ", dump_regval_type( nk->values[i].type ) );
data_size = nk->values[i].data_size & ~VK_DATA_IN_OFFSET;
switch ( nk->values[i].type ) {
@@ -949,27 +489,30 @@ out:
/********************************************************************
********************************************************************/
+static int net_help_registry( int argc, const char **argv )
+{
+ d_printf("net rpc registry enumerate <path> [recurse] Enumerate the subkeya and values for a given registry path\n");
+ d_printf("net rpc registry save <path> <file> Backup a registry tree to a file on the server\n");
+ d_printf("net rpc registry dump <file> Dump the contents of a registry file to stdout\n");
+
+ return -1;
+}
+
+/********************************************************************
+********************************************************************/
+
int net_rpc_registry(int argc, const char **argv)
{
- struct functable2 func[] = {
- { "enumerate", rpc_registry_enumerate,
- "Enumerate registry keys and values" },
- { "createkey", rpc_registry_createkey,
- "Create a new registry key" },
- { "deletekey", rpc_registry_deletekey,
- "Delete a registry key" },
- { "setvalue", rpc_registry_setvalue,
- "Set a new registry value" },
- { "deletevalue", rpc_registry_deletevalue,
- "Delete a registry value" },
- { "save", rpc_registry_save,
- "Save a registry file" },
- { "dump", rpc_registry_dump,
- "Dump a registry file" },
- { "copy", rpc_registry_copy,
- "Copy a registry file" },
- {NULL, NULL, NULL}
+ struct functable func[] = {
+ {"enumerate", rpc_registry_enumerate},
+ {"save", rpc_registry_save},
+ {"dump", rpc_registry_dump},
+ {"copy", rpc_registry_copy},
+ {NULL, NULL}
};
- return net_run_function2(argc, argv, "net rpc registry", func);
+ if ( argc )
+ return net_run_function( argc, argv, func, net_help_registry );
+
+ return net_help_registry( argc, argv );
}
diff --git a/source/utils/net_rpc_rights.c b/source/utils/net_rpc_rights.c
index 4189f20658a..11c4991e7d7 100644
--- a/source/utils/net_rpc_rights.c
+++ b/source/utils/net_rpc_rights.c
@@ -48,7 +48,7 @@ static NTSTATUS sid_to_name(struct rpc_pipe_client *pipe_hnd,
fstrcpy( name, names[0] );
}
- rpccli_lsa_Close(pipe_hnd, mem_ctx, &pol);
+ rpccli_lsa_close(pipe_hnd, mem_ctx, &pol);
return result;
}
@@ -76,12 +76,12 @@ static NTSTATUS name_to_sid(struct rpc_pipe_client *pipe_hnd,
return result;
result = rpccli_lsa_lookup_names(pipe_hnd, mem_ctx, &pol, 1, &name,
- NULL, 1, &sids, &sid_types);
+ NULL, &sids, &sid_types);
if ( NT_STATUS_IS_OK(result) )
sid_copy( sid, &sids[0] );
- rpccli_lsa_Close(pipe_hnd, mem_ctx, &pol);
+ rpccli_lsa_close(pipe_hnd, mem_ctx, &pol);
return result;
}
@@ -391,7 +391,7 @@ static NTSTATUS rpc_rights_list_internal(const DOM_SID *domain_sid,
result = enum_privileges_for_user(pipe_hnd, mem_ctx, &pol, &sid );
done:
- rpccli_lsa_Close(pipe_hnd, mem_ctx, &pol);
+ rpccli_lsa_close(pipe_hnd, mem_ctx, &pol);
return result;
}
@@ -442,7 +442,7 @@ static NTSTATUS rpc_rights_grant_internal(const DOM_SID *domain_sid,
argv[0], nt_errstr(result));
}
- rpccli_lsa_Close(pipe_hnd, mem_ctx, &dom_pol);
+ rpccli_lsa_close(pipe_hnd, mem_ctx, &dom_pol);
return result;
}
@@ -493,7 +493,7 @@ done:
argv[0], nt_errstr(result));
}
- rpccli_lsa_Close(pipe_hnd, mem_ctx, &dom_pol);
+ rpccli_lsa_close(pipe_hnd, mem_ctx, &dom_pol);
return result;
}
diff --git a/source/utils/net_rpc_service.c b/source/utils/net_rpc_service.c
index c0b1fe3515f..58a5b27f400 100644
--- a/source/utils/net_rpc_service.c
+++ b/source/utils/net_rpc_service.c
@@ -49,7 +49,7 @@ static WERROR query_service_state(struct rpc_pipe_client *pipe_hnd,
*state = service_status.state;
}
- rpccli_svcctl_CloseServiceHandle(pipe_hnd, mem_ctx, &hService);
+ rpccli_svcctl_close_service(pipe_hnd, mem_ctx, &hService );
return result;
}
@@ -131,7 +131,7 @@ static WERROR control_service(struct rpc_pipe_client *pipe_hnd,
d_printf("%s service is %s.\n", service, svc_status_string(state));
done:
- rpccli_svcctl_CloseServiceHandle(pipe_hnd, mem_ctx, &hService);
+ rpccli_svcctl_close_service(pipe_hnd, mem_ctx, &hService );
return result;
}
@@ -185,7 +185,7 @@ static NTSTATUS rpc_service_list_internal(const DOM_SID *domain_sid,
}
done:
- rpccli_svcctl_CloseServiceHandle(pipe_hnd, mem_ctx, &hSCM);
+ rpccli_svcctl_close_service(pipe_hnd, mem_ctx, &hSCM );
return werror_to_ntstatus(result);
}
@@ -286,8 +286,8 @@ static NTSTATUS rpc_service_status_internal(const DOM_SID *domain_sid,
}
done:
- rpccli_svcctl_CloseServiceHandle(pipe_hnd, mem_ctx, &hService);
- rpccli_svcctl_CloseServiceHandle(pipe_hnd, mem_ctx, &hSCM);
+ rpccli_svcctl_close_service(pipe_hnd, mem_ctx, &hService );
+ rpccli_svcctl_close_service(pipe_hnd, mem_ctx, &hSCM );
return werror_to_ntstatus(result);
}
@@ -325,7 +325,7 @@ static NTSTATUS rpc_service_stop_internal(const DOM_SID *domain_sid,
result = control_service(pipe_hnd, mem_ctx, &hSCM, servicename,
SVCCTL_CONTROL_STOP, SVCCTL_STOPPED );
- rpccli_svcctl_CloseServiceHandle(pipe_hnd, mem_ctx, &hSCM);
+ rpccli_svcctl_close_service(pipe_hnd, mem_ctx, &hSCM );
return werror_to_ntstatus(result);
}
@@ -363,7 +363,7 @@ static NTSTATUS rpc_service_pause_internal(const DOM_SID *domain_sid,
result = control_service(pipe_hnd, mem_ctx, &hSCM, servicename,
SVCCTL_CONTROL_PAUSE, SVCCTL_PAUSED );
- rpccli_svcctl_CloseServiceHandle(pipe_hnd, mem_ctx, &hSCM);
+ rpccli_svcctl_close_service(pipe_hnd, mem_ctx, &hSCM );
return werror_to_ntstatus(result);
}
@@ -401,7 +401,7 @@ static NTSTATUS rpc_service_resume_internal(const DOM_SID *domain_sid,
result = control_service(pipe_hnd, mem_ctx, &hSCM, servicename,
SVCCTL_CONTROL_CONTINUE, SVCCTL_RUNNING );
- rpccli_svcctl_CloseServiceHandle(pipe_hnd, mem_ctx, &hSCM);
+ rpccli_svcctl_close_service(pipe_hnd, mem_ctx, &hSCM );
return werror_to_ntstatus(result);
}
@@ -463,8 +463,8 @@ static NTSTATUS rpc_service_start_internal(const DOM_SID *domain_sid,
d_fprintf(stderr, "Failed to start service: %s [%s]\n", servicename, dos_errstr(result) );
done:
- rpccli_svcctl_CloseServiceHandle(pipe_hnd, mem_ctx, &hService);
- rpccli_svcctl_CloseServiceHandle(pipe_hnd, mem_ctx, &hSCM);
+ rpccli_svcctl_close_service(pipe_hnd, mem_ctx, &hService );
+ rpccli_svcctl_close_service(pipe_hnd, mem_ctx, &hSCM );
return werror_to_ntstatus(result);
}
diff --git a/source/utils/net_sam.c b/source/utils/net_sam.c
index 851c3e86dee..bf397803bc5 100644
--- a/source/utils/net_sam.c
+++ b/source/utils/net_sam.c
@@ -507,61 +507,6 @@ static int net_sam_policy(int argc, const char **argv)
* Map a unix group to a domain group
*/
-static NTSTATUS map_unix_group(const struct group *grp, GROUP_MAP *pmap)
-{
- NTSTATUS status;
- GROUP_MAP map;
- const char *grpname, *dom, *name;
- uint32 rid;
-
- if (pdb_getgrgid(&map, grp->gr_gid)) {
- return NT_STATUS_GROUP_EXISTS;
- }
-
- map.gid = grp->gr_gid;
- grpname = grp->gr_name;
-
- if (lookup_name(tmp_talloc_ctx(), grpname, LOOKUP_NAME_ISOLATED,
- &dom, &name, NULL, NULL)) {
-
- const char *tmp = talloc_asprintf(
- tmp_talloc_ctx(), "Unix Group %s", grp->gr_name);
-
- DEBUG(5, ("%s exists as %s\\%s, retrying as \"%s\"\n",
- grpname, dom, name, tmp));
- grpname = tmp;
- }
-
- if (lookup_name(tmp_talloc_ctx(), grpname, LOOKUP_NAME_ISOLATED,
- NULL, NULL, NULL, NULL)) {
- DEBUG(3, ("\"%s\" exists, can't map it\n", grp->gr_name));
- return NT_STATUS_GROUP_EXISTS;
- }
-
- fstrcpy(map.nt_name, grpname);
-
- if (pdb_rid_algorithm()) {
- rid = algorithmic_pdb_gid_to_group_rid( grp->gr_gid );
- } else {
- if (!pdb_new_rid(&rid)) {
- DEBUG(3, ("Could not get a new RID for %s\n",
- grp->gr_name));
- return NT_STATUS_ACCESS_DENIED;
- }
- }
-
- sid_compose(&map.sid, get_global_sam_sid(), rid);
- map.sid_name_use = SID_NAME_DOM_GRP;
- fstrcpy(map.comment, talloc_asprintf(tmp_talloc_ctx(), "Unix Group %s",
- grp->gr_name));
-
- status = pdb_add_group_mapping_entry(&map);
- if (NT_STATUS_IS_OK(status)) {
- *pmap = map;
- }
- return status;
-}
-
static int net_sam_mapunixgroup(int argc, const char **argv)
{
NTSTATUS status;
@@ -594,67 +539,6 @@ static int net_sam_mapunixgroup(int argc, const char **argv)
}
/*
- * Remove a group mapping
- */
-
-static NTSTATUS unmap_unix_group(const struct group *grp, GROUP_MAP *pmap)
-{
- NTSTATUS status;
- GROUP_MAP map;
- const char *grpname;
- DOM_SID dom_sid;
-
- map.gid = grp->gr_gid;
- grpname = grp->gr_name;
-
- if (!lookup_name(tmp_talloc_ctx(), grpname, LOOKUP_NAME_ISOLATED,
- NULL, NULL, NULL, NULL)) {
- DEBUG(3, ("\"%s\" does not exist, can't unmap it\n", grp->gr_name));
- return NT_STATUS_NO_SUCH_GROUP;
- }
-
- fstrcpy(map.nt_name, grpname);
-
- if (!pdb_gid_to_sid(map.gid, &dom_sid)) {
- return NT_STATUS_UNSUCCESSFUL;
- }
-
- status = pdb_delete_group_mapping_entry(dom_sid);
-
- return status;
-}
-
-static int net_sam_unmapunixgroup(int argc, const char **argv)
-{
- NTSTATUS status;
- GROUP_MAP map;
- struct group *grp;
-
- if (argc != 1) {
- d_fprintf(stderr, "usage: net sam unmapunixgroup <name>\n");
- return -1;
- }
-
- grp = getgrnam(argv[0]);
- if (grp == NULL) {
- d_fprintf(stderr, "Could not find mapping for group %s.\n", argv[0]);
- return -1;
- }
-
- status = unmap_unix_group(grp, &map);
-
- if (!NT_STATUS_IS_OK(status)) {
- d_fprintf(stderr, "Unmapping group %s failed with %s.\n",
- argv[0], nt_errstr(status));
- return -1;
- }
-
- d_printf("Unmapped unix group %s.\n", argv[0]);
-
- return 0;
-}
-
-/*
* Create a local group
*/
@@ -688,47 +572,6 @@ static int net_sam_createlocalgroup(int argc, const char **argv)
}
/*
- * Delete a local group
- */
-
-static int net_sam_deletelocalgroup(int argc, const char **argv)
-{
- DOM_SID sid;
- enum lsa_SidType type;
- const char *dom, *name;
- NTSTATUS status;
-
- if (argc != 1) {
- d_fprintf(stderr, "usage: net sam deletelocalgroup <name>\n");
- return -1;
- }
-
- if (!lookup_name(tmp_talloc_ctx(), argv[0], LOOKUP_NAME_ISOLATED,
- &dom, &name, &sid, &type)) {
- d_fprintf(stderr, "Could not find %s.\n", argv[0]);
- return -1;
- }
-
- if (type != SID_NAME_ALIAS) {
- d_fprintf(stderr, "%s is a %s, not a local group.\n", argv[0],
- sid_type_lookup(type));
- return -1;
- }
-
- status = pdb_delete_alias(&sid);
-
- if (!NT_STATUS_IS_OK(status)) {
- d_fprintf(stderr, "Deleting local group %s failed with %s\n",
- argv[0], nt_errstr(status));
- return -1;
- }
-
- d_printf("Deleted local group %s.\n", argv[0]);
-
- return 0;
-}
-
-/*
* Create a local group
*/
@@ -958,8 +801,6 @@ static int net_sam_listmem(int argc, const char **argv)
sid_string_static(&members[i]));
}
}
-
- TALLOC_FREE(members);
} else {
d_fprintf(stderr, "Can only list local group members so far.\n"
"%s is a %s\n", argv[0], sid_type_lookup(grouptype));
@@ -1149,7 +990,7 @@ static int net_sam_provision(int argc, const char **argv)
goto failed;
}
- if (!NT_STATUS_IS_OK(smbldap_init(tc, NULL, ldap_uri, &ls))) {
+ if (!NT_STATUS_IS_OK(smbldap_init(tc, ldap_uri, &ls))) {
d_fprintf(stderr, "Unable to connect to the LDAP server.\n");
goto failed;
}
@@ -1500,12 +1341,8 @@ int net_sam(int argc, const char **argv)
"Create a new BUILTIN group" },
{ "createlocalgroup", net_sam_createlocalgroup,
"Create a new local group" },
- { "deletelocalgroup", net_sam_deletelocalgroup,
- "Delete an existing local group" },
{ "mapunixgroup", net_sam_mapunixgroup,
"Map a unix group to a domain group" },
- { "unmapunixgroup", net_sam_unmapunixgroup,
- "Remove a group mapping of an unix group to a domain group" },
{ "addmem", net_sam_addmem,
"Add a member to a group" },
{ "delmem", net_sam_delmem,
diff --git a/source/utils/net_status.c b/source/utils/net_status.c
index 80fba51b37a..354111f6092 100644
--- a/source/utils/net_status.c
+++ b/source/utils/net_status.c
@@ -31,18 +31,18 @@ static int show_session(TDB_CONTEXT *tdb, TDB_DATA kbuf, TDB_DATA dbuf,
memcpy(&sessionid, dbuf.dptr, sizeof(sessionid));
- if (!process_exists(sessionid.pid)) {
+ if (!process_exists_by_pid(sessionid.pid)) {
return 0;
}
if (*parseable) {
- d_printf("%s\\%s\\%s\\%s\\%s\n",
- procid_str_static(&sessionid.pid), uidtoname(sessionid.uid),
+ d_printf("%d\\%s\\%s\\%s\\%s\n",
+ (int)sessionid.pid, uidtoname(sessionid.uid),
gidtoname(sessionid.gid),
sessionid.remote_machine, sessionid.hostname);
} else {
- d_printf("%7s %-12s %-12s %-12s (%s)\n",
- procid_str_static(&sessionid.pid), uidtoname(sessionid.uid),
+ d_printf("%5d %-12s %-12s %-12s (%s)\n",
+ (int)sessionid.pid, uidtoname(sessionid.uid),
gidtoname(sessionid.gid),
sessionid.remote_machine, sessionid.hostname);
}
@@ -84,22 +84,27 @@ static int net_status_sessions(int argc, const char **argv)
return 0;
}
-static int show_share(struct db_record *rec,
- const struct connections_key *key,
- const struct connections_data *crec,
+static int show_share(TDB_CONTEXT *tdb, TDB_DATA kbuf, TDB_DATA dbuf,
void *state)
{
- if (crec->cnum == -1)
+ struct connections_data crec;
+
+ if (dbuf.dsize != sizeof(crec))
return 0;
- if (!process_exists(crec->pid)) {
+ memcpy(&crec, dbuf.dptr, sizeof(crec));
+
+ if (crec.cnum == -1)
+ return 0;
+
+ if (!process_exists(crec.pid)) {
return 0;
}
d_printf("%-10.10s %s %-12s %s",
- crec->servicename, procid_str_static(&crec->pid),
- crec->machine,
- time_to_asc(crec->start));
+ crec.servicename,procid_str_static(&crec.pid),
+ crec.machine,
+ time_to_asc(crec.start));
return 0;
}
@@ -120,7 +125,7 @@ static int collect_pid(TDB_CONTEXT *tdb, TDB_DATA kbuf, TDB_DATA dbuf,
memcpy(&sessionid, dbuf.dptr, sizeof(sessionid));
- if (!process_exists(sessionid.pid))
+ if (!process_exists_by_pid(sessionid.pid))
return 0;
ids->num_entries += 1;
@@ -134,37 +139,41 @@ static int collect_pid(TDB_CONTEXT *tdb, TDB_DATA kbuf, TDB_DATA dbuf,
return 0;
}
-static int show_share_parseable(struct db_record *rec,
- const struct connections_key *key,
- const struct connections_data *crec,
+static int show_share_parseable(TDB_CONTEXT *tdb, TDB_DATA kbuf, TDB_DATA dbuf,
void *state)
{
struct sessionids *ids = (struct sessionids *)state;
+ struct connections_data crec;
int i;
BOOL guest = True;
- if (crec->cnum == -1)
+ if (dbuf.dsize != sizeof(crec))
+ return 0;
+
+ memcpy(&crec, dbuf.dptr, sizeof(crec));
+
+ if (crec.cnum == -1)
return 0;
- if (!process_exists(crec->pid)) {
+ if (!process_exists(crec.pid)) {
return 0;
}
for (i=0; i<ids->num_entries; i++) {
- struct server_id id = ids->entries[i].pid;
- if (procid_equal(&id, &crec->pid)) {
+ struct process_id id = pid_to_procid(ids->entries[i].pid);
+ if (procid_equal(&id, &crec.pid)) {
guest = False;
break;
}
}
d_printf("%s\\%s\\%s\\%s\\%s\\%s\\%s",
- crec->servicename,procid_str_static(&crec->pid),
+ crec.servicename,procid_str_static(&crec.pid),
guest ? "" : uidtoname(ids->entries[i].uid),
guest ? "" : gidtoname(ids->entries[i].gid),
- crec->machine,
+ crec.machine,
guest ? "" : ids->entries[i].hostname,
- time_to_asc(crec->start));
+ time_to_asc(crec.start));
return 0;
}
@@ -188,7 +197,18 @@ static int net_status_shares_parseable(int argc, const char **argv)
tdb_traverse(tdb, collect_pid, &ids);
tdb_close(tdb);
- connections_forall(show_share_parseable, &ids);
+ tdb = tdb_open_log(lock_path("connections.tdb"), 0,
+ TDB_DEFAULT, O_RDONLY, 0);
+
+ if (tdb == NULL) {
+ d_fprintf(stderr, "%s not initialised\n", lock_path("connections.tdb"));
+ d_fprintf(stderr, "This is normal if no SMB client has ever "
+ "connected to your server.\n");
+ return -1;
+ }
+
+ tdb_traverse(tdb, show_share_parseable, &ids);
+ tdb_close(tdb);
SAFE_FREE(ids.entries);
@@ -197,6 +217,8 @@ static int net_status_shares_parseable(int argc, const char **argv)
static int net_status_shares(int argc, const char **argv)
{
+ TDB_CONTEXT *tdb;
+
if (argc == 0) {
d_printf("\nService pid machine "
@@ -204,7 +226,19 @@ static int net_status_shares(int argc, const char **argv)
d_printf("-------------------------------------"
"------------------\n");
- connections_forall(show_share, NULL);
+ tdb = tdb_open_log(lock_path("connections.tdb"), 0,
+ TDB_DEFAULT, O_RDONLY, 0);
+
+ if (tdb == NULL) {
+ d_fprintf(stderr, "%s not initialised\n",
+ lock_path("connections.tdb"));
+ d_fprintf(stderr, "This is normal if no SMB client has "
+ "ever connected to your server.\n");
+ return -1;
+ }
+
+ tdb_traverse(tdb, show_share, NULL);
+ tdb_close(tdb);
return 0;
}
diff --git a/source/utils/net_util.c b/source/utils/net_util.c
index be12b0f8661..be39a754656 100644
--- a/source/utils/net_util.c
+++ b/source/utils/net_util.c
@@ -59,7 +59,7 @@ NTSTATUS net_rpc_lookup_name(TALLOC_CTX *mem_ctx, struct cli_state *cli,
}
result = rpccli_lsa_lookup_names(lsa_pipe, mem_ctx, &pol, 1,
- &name, &dom_names, 1, &sids, &types);
+ &name, &dom_names, &sids, &types);
if (!NT_STATUS_IS_OK(result)) {
/* This can happen easily, don't log an error */
@@ -81,7 +81,7 @@ NTSTATUS net_rpc_lookup_name(TALLOC_CTX *mem_ctx, struct cli_state *cli,
done:
if (is_valid_policy_hnd(&pol)) {
- rpccli_lsa_Close(lsa_pipe, mem_ctx, &pol);
+ rpccli_lsa_close(lsa_pipe, mem_ctx, &pol);
}
cli_rpc_pipe_close(lsa_pipe);
diff --git a/source/utils/netlookup.c b/source/utils/netlookup.c
index 82e1b8af801..33b6c4bb257 100644
--- a/source/utils/netlookup.c
+++ b/source/utils/netlookup.c
@@ -206,8 +206,8 @@ NTSTATUS net_lookup_sid_from_name(TALLOC_CTX *ctx, const char *full_name, DOM_SI
&csp->pol,
1,
&full_name,
- NULL, 1,
- &sids, &types);
+ NULL, &sids,
+ &types);
if (!NT_STATUS_IS_OK(nt_status)) {
return nt_status;
diff --git a/source/utils/ntlm_auth.c b/source/utils/ntlm_auth.c
index a2b41660b58..1f0a915574d 100644
--- a/source/utils/ntlm_auth.c
+++ b/source/utils/ntlm_auth.c
@@ -704,7 +704,7 @@ static void manage_squid_ntlmssp_request(enum stdio_helper_mode stdio_helper_mod
}
request = base64_decode_data_blob(buf + 3);
} else {
- request = data_blob_null;
+ request = data_blob(NULL, 0);
}
if ((strncmp(buf, "PW ", 3) == 0)) {
@@ -761,7 +761,7 @@ static void manage_squid_ntlmssp_request(enum stdio_helper_mode stdio_helper_mod
}
DEBUG(10, ("got NTLMSSP packet:\n"));
- dump_data(10, request.data, request.length);
+ dump_data(10, (const char *)request.data, request.length);
nt_status = ntlmssp_update(ntlmssp_state, request, &reply);
@@ -832,7 +832,7 @@ static void manage_client_ntlmssp_request(enum stdio_helper_mode stdio_helper_mo
}
request = base64_decode_data_blob(buf + 3);
} else {
- request = data_blob_null;
+ request = data_blob(NULL, 0);
}
if (strncmp(buf, "PW ", 3) == 0) {
@@ -854,7 +854,7 @@ static void manage_client_ntlmssp_request(enum stdio_helper_mode stdio_helper_mo
if (!ntlmssp_state && use_cached_creds) {
/* check whether credentials are usable. */
- DATA_BLOB empty_blob = data_blob_null;
+ DATA_BLOB empty_blob = data_blob(NULL, 0);
nt_status = do_ccache_ntlm_auth(empty_blob, empty_blob, NULL);
if (!NT_STATUS_EQUAL(nt_status, NT_STATUS_MORE_PROCESSING_REQUIRED)) {
@@ -910,11 +910,11 @@ static void manage_client_ntlmssp_request(enum stdio_helper_mode stdio_helper_mo
}
ntlmssp_want_feature_list(ntlmssp_state, want_feature_list);
first = True;
- initial_message = data_blob_null;
+ initial_message = data_blob(NULL, 0);
}
DEBUG(10, ("got NTLMSSP packet:\n"));
- dump_data(10, request.data, request.length);
+ dump_data(10, (const char *)request.data, request.length);
if (use_cached_creds && !opt_password && !first) {
nt_status = do_ccache_ntlm_auth(initial_message, request, &reply);
@@ -1135,12 +1135,12 @@ static void manage_gss_spnego_request(enum stdio_helper_mode stdio_helper_mode,
}
DEBUG(10, ("got NTLMSSP packet:\n"));
- dump_data(10, request.negTokenInit.mechToken.data,
+ dump_data(10, (const char *)request.negTokenInit.mechToken.data,
request.negTokenInit.mechToken.length);
response.type = SPNEGO_NEG_TOKEN_TARG;
response.negTokenTarg.supportedMech = SMB_STRDUP(OID_NTLMSSP);
- response.negTokenTarg.mechListMIC = data_blob_null;
+ response.negTokenTarg.mechListMIC = data_blob(NULL, 0);
status = ntlmssp_update(ntlmssp_state,
request.negTokenInit.mechToken,
@@ -1163,13 +1163,13 @@ static void manage_gss_spnego_request(enum stdio_helper_mode stdio_helper_mode,
response.type = SPNEGO_NEG_TOKEN_TARG;
response.negTokenTarg.supportedMech = SMB_STRDUP(OID_KERBEROS5_OLD);
- response.negTokenTarg.mechListMIC = data_blob_null;
- response.negTokenTarg.responseToken = data_blob_null;
+ response.negTokenTarg.mechListMIC = data_blob(NULL, 0);
+ response.negTokenTarg.responseToken = data_blob(NULL, 0);
status = ads_verify_ticket(mem_ctx, lp_realm(), 0,
&request.negTokenInit.mechToken,
&principal, NULL, &ap_rep,
- &session_key, True);
+ &session_key);
talloc_destroy(mem_ctx);
@@ -1222,7 +1222,7 @@ static void manage_gss_spnego_request(enum stdio_helper_mode stdio_helper_mode,
response.type = SPNEGO_NEG_TOKEN_TARG;
response.negTokenTarg.supportedMech = SMB_STRDUP(OID_NTLMSSP);
- response.negTokenTarg.mechListMIC = data_blob_null;
+ response.negTokenTarg.mechListMIC = data_blob(NULL, 0);
if (NT_STATUS_IS_OK(status)) {
user = SMB_STRDUP(ntlmssp_state->user);
@@ -1276,7 +1276,7 @@ static NTLMSSP_STATE *client_ntlmssp_state = NULL;
static BOOL manage_client_ntlmssp_init(SPNEGO_DATA spnego)
{
NTSTATUS status;
- DATA_BLOB null_blob = data_blob_null;
+ DATA_BLOB null_blob = data_blob(NULL, 0);
DATA_BLOB to_server;
char *to_server_base64;
const char *my_mechs[] = {OID_NTLMSSP, NULL};
@@ -1337,7 +1337,7 @@ static BOOL manage_client_ntlmssp_init(SPNEGO_DATA spnego)
static void manage_client_ntlmssp_targ(SPNEGO_DATA spnego)
{
NTSTATUS status;
- DATA_BLOB null_blob = data_blob_null;
+ DATA_BLOB null_blob = data_blob(NULL, 0);
DATA_BLOB request;
DATA_BLOB to_server;
char *to_server_base64;
@@ -1398,7 +1398,7 @@ static BOOL manage_client_krb5_init(SPNEGO_DATA spnego)
{
char *principal;
DATA_BLOB tkt, to_server;
- DATA_BLOB session_key_krb5 = data_blob_null;
+ DATA_BLOB session_key_krb5 = data_blob(NULL, 0);
SPNEGO_DATA reply;
char *reply_base64;
int retval;
@@ -1462,7 +1462,7 @@ static BOOL manage_client_krb5_init(SPNEGO_DATA spnego)
reply.negTokenInit.mechTypes = my_mechs;
reply.negTokenInit.reqFlags = 0;
reply.negTokenInit.mechToken = tkt;
- reply.negTokenInit.mechListMIC = data_blob_null;
+ reply.negTokenInit.mechListMIC = data_blob(NULL, 0);
len = write_spnego_data(&to_server, &reply);
data_blob_free(&tkt);
@@ -1751,9 +1751,9 @@ static void manage_ntlm_server_1_request(enum stdio_helper_mode stdio_helper_mod
}
}
/* clear out the state */
- challenge = data_blob_null;
- nt_response = data_blob_null;
- lm_response = data_blob_null;
+ challenge = data_blob(NULL, 0);
+ nt_response = data_blob(NULL, 0);
+ lm_response = data_blob(NULL, 0);
SAFE_FREE(full_username);
SAFE_FREE(username);
SAFE_FREE(domain);
@@ -1800,7 +1800,7 @@ static void manage_ntlm_server_1_request(enum stdio_helper_mode stdio_helper_mod
x_fprintf(x_stdout, "Error: hex decode of %s failed! (got %d bytes, expected 8)\n.\n",
parameter,
(int)challenge.length);
- challenge = data_blob_null;
+ challenge = data_blob(NULL, 0);
}
} else if (strequal(request, "NT-Response")) {
nt_response = strhex_to_data_blob(NULL, parameter);
@@ -1808,7 +1808,7 @@ static void manage_ntlm_server_1_request(enum stdio_helper_mode stdio_helper_mod
x_fprintf(x_stdout, "Error: hex decode of %s failed! (only got %d bytes, needed at least 24)\n.\n",
parameter,
(int)nt_response.length);
- nt_response = data_blob_null;
+ nt_response = data_blob(NULL, 0);
}
} else if (strequal(request, "LANMAN-Response")) {
lm_response = strhex_to_data_blob(NULL, parameter);
@@ -1816,7 +1816,7 @@ static void manage_ntlm_server_1_request(enum stdio_helper_mode stdio_helper_mod
x_fprintf(x_stdout, "Error: hex decode of %s failed! (got %d bytes, expected 24)\n.\n",
parameter,
(int)lm_response.length);
- lm_response = data_blob_null;
+ lm_response = data_blob(NULL, 0);
}
} else if (strequal(request, "Password")) {
plaintext_password = smb_xstrdup(parameter);
@@ -1950,10 +1950,10 @@ static void manage_ntlm_change_password_1_request(enum stdio_helper_mode helper_
SAFE_FREE(error_string);
}
/* clear out the state */
- new_nt_pswd = data_blob_null;
- old_nt_hash_enc = data_blob_null;
- new_lm_pswd = data_blob_null;
- old_nt_hash_enc = data_blob_null;
+ new_nt_pswd = data_blob(NULL, 0);
+ old_nt_hash_enc = data_blob(NULL, 0);
+ new_lm_pswd = data_blob(NULL, 0);
+ old_nt_hash_enc = data_blob(NULL, 0);
SAFE_FREE(full_username);
SAFE_FREE(username);
SAFE_FREE(domain);
@@ -1999,7 +1999,7 @@ static void manage_ntlm_change_password_1_request(enum stdio_helper_mode helper_
"(got %d bytes, expected 516)\n.\n",
parameter,
(int)new_nt_pswd.length);
- new_nt_pswd = data_blob_null;
+ new_nt_pswd = data_blob(NULL, 0);
}
} else if (strequal(request, "old-nt-hash-blob")) {
old_nt_hash_enc = strhex_to_data_blob(NULL, parameter);
@@ -2008,7 +2008,7 @@ static void manage_ntlm_change_password_1_request(enum stdio_helper_mode helper_
"(got %d bytes, expected 16)\n.\n",
parameter,
(int)old_nt_hash_enc.length);
- old_nt_hash_enc = data_blob_null;
+ old_nt_hash_enc = data_blob(NULL, 0);
}
} else if (strequal(request, "new-lm-password-blob")) {
new_lm_pswd = strhex_to_data_blob(NULL, parameter);
@@ -2017,7 +2017,7 @@ static void manage_ntlm_change_password_1_request(enum stdio_helper_mode helper_
"(got %d bytes, expected 516)\n.\n",
parameter,
(int)new_lm_pswd.length);
- new_lm_pswd = data_blob_null;
+ new_lm_pswd = data_blob(NULL, 0);
}
}
else if (strequal(request, "old-lm-hash-blob")) {
@@ -2028,7 +2028,7 @@ static void manage_ntlm_change_password_1_request(enum stdio_helper_mode helper_
"(got %d bytes, expected 16)\n.\n",
parameter,
(int)old_lm_hash_enc.length);
- old_lm_hash_enc = data_blob_null;
+ old_lm_hash_enc = data_blob(NULL, 0);
}
} else if (strequal(request, "nt-domain")) {
domain = smb_xstrdup(parameter);
diff --git a/source/utils/ntlm_auth_diagnostics.c b/source/utils/ntlm_auth_diagnostics.c
index a4e0d6b1ba9..f7997de711e 100644
--- a/source/utils/ntlm_auth_diagnostics.c
+++ b/source/utils/ntlm_auth_diagnostics.c
@@ -116,9 +116,9 @@ static BOOL test_lm_ntlm_broken(enum ntlm_break break_which)
sizeof(lm_key)) != 0) {
DEBUG(1, ("LM Key does not match expectations!\n"));
DEBUG(1, ("lm_key:\n"));
- dump_data(1, lm_key, 8);
+ dump_data(1, (const char *)lm_key, 8);
DEBUG(1, ("expected:\n"));
- dump_data(1, lm_hash, 8);
+ dump_data(1, (const char *)lm_hash, 8);
pass = False;
}
@@ -127,9 +127,9 @@ static BOOL test_lm_ntlm_broken(enum ntlm_break break_which)
8) != 0) {
DEBUG(1, ("NT Session Key does not match expectations (should be LM hash)!\n"));
DEBUG(1, ("user_session_key:\n"));
- dump_data(1, user_session_key, sizeof(user_session_key));
+ dump_data(1, (const char *)user_session_key, sizeof(user_session_key));
DEBUG(1, ("expected:\n"));
- dump_data(1, lm_hash, sizeof(lm_hash));
+ dump_data(1, (const char *)lm_hash, sizeof(lm_hash));
pass = False;
}
} else {
@@ -137,9 +137,9 @@ static BOOL test_lm_ntlm_broken(enum ntlm_break break_which)
sizeof(user_session_key)) != 0) {
DEBUG(1, ("NT Session Key does not match expectations!\n"));
DEBUG(1, ("user_session_key:\n"));
- dump_data(1, user_session_key, 16);
+ dump_data(1, (const char *)user_session_key, 16);
DEBUG(1, ("expected:\n"));
- dump_data(1, session_key.data, session_key.length);
+ dump_data(1, (const char *)session_key.data, session_key.length);
pass = False;
}
}
@@ -215,17 +215,17 @@ static BOOL test_ntlm_in_lm(void)
sizeof(lm_key)) != 0) {
DEBUG(1, ("LM Key does not match expectations!\n"));
DEBUG(1, ("lm_key:\n"));
- dump_data(1, lm_key, 8);
+ dump_data(1, (const char *)lm_key, 8);
DEBUG(1, ("expected:\n"));
- dump_data(1, lm_hash, 8);
+ dump_data(1, (const char *)lm_hash, 8);
pass = False;
}
if (memcmp(lm_hash, user_session_key, 8) != 0) {
DEBUG(1, ("Session Key (first 8 lm hash) does not match expectations!\n"));
DEBUG(1, ("user_session_key:\n"));
- dump_data(1, user_session_key, 16);
+ dump_data(1, (const char *)user_session_key, 16);
DEBUG(1, ("expected:\n"));
- dump_data(1, lm_hash, 8);
+ dump_data(1, (const char *)lm_hash, 8);
pass = False;
}
return pass;
@@ -243,10 +243,10 @@ static BOOL test_ntlm_in_both(void)
DATA_BLOB nt_response = data_blob(NULL, 24);
DATA_BLOB session_key = data_blob(NULL, 16);
- uint8 lm_key[8];
- uint8 lm_hash[16];
- uint8 user_session_key[16];
- uint8 nt_hash[16];
+ char lm_key[8];
+ char lm_hash[16];
+ char user_session_key[16];
+ char nt_hash[16];
DATA_BLOB chall = get_challenge();
char *error_string;
@@ -257,10 +257,10 @@ static BOOL test_ntlm_in_both(void)
flags |= WBFLAG_PAM_USER_SESSION_KEY;
SMBNTencrypt(opt_password,chall.data,nt_response.data);
- E_md4hash(opt_password, nt_hash);
- SMBsesskeygen_ntv1(nt_hash, NULL, session_key.data);
+ E_md4hash(opt_password, (unsigned char *)nt_hash);
+ SMBsesskeygen_ntv1((const unsigned char *)nt_hash, NULL, session_key.data);
- E_deshash(opt_password, lm_hash);
+ E_deshash(opt_password, (unsigned char *)lm_hash);
nt_status = contact_winbind_auth_crap(opt_username, opt_domain,
opt_workstation,
@@ -268,8 +268,8 @@ static BOOL test_ntlm_in_both(void)
&nt_response,
&nt_response,
flags,
- lm_key,
- user_session_key,
+ (unsigned char *)lm_key,
+ (unsigned char *)user_session_key,
&error_string, NULL);
data_blob_free(&nt_response);
@@ -297,7 +297,7 @@ static BOOL test_ntlm_in_both(void)
DEBUG(1, ("user_session_key:\n"));
dump_data(1, user_session_key, 16);
DEBUG(1, ("expected:\n"));
- dump_data(1, session_key.data, session_key.length);
+ dump_data(1, (const char *)session_key.data, session_key.length);
pass = False;
}
@@ -314,9 +314,9 @@ static BOOL test_lmv2_ntlmv2_broken(enum ntlm_break break_which)
BOOL pass = True;
NTSTATUS nt_status;
uint32 flags = 0;
- DATA_BLOB ntlmv2_response = data_blob_null;
- DATA_BLOB lmv2_response = data_blob_null;
- DATA_BLOB ntlmv2_session_key = data_blob_null;
+ DATA_BLOB ntlmv2_response = data_blob(NULL, 0);
+ DATA_BLOB lmv2_response = data_blob(NULL, 0);
+ DATA_BLOB ntlmv2_session_key = data_blob(NULL, 0);
DATA_BLOB names_blob = NTLMv2_generate_names_blob(get_winbind_netbios_name(), get_winbind_domain());
uchar user_session_key[16];
@@ -378,9 +378,9 @@ static BOOL test_lmv2_ntlmv2_broken(enum ntlm_break break_which)
sizeof(user_session_key)) != 0) {
DEBUG(1, ("USER (NTLMv2) Session Key does not match expectations!\n"));
DEBUG(1, ("user_session_key:\n"));
- dump_data(1, user_session_key, 16);
+ dump_data(1, (const char *)user_session_key, 16);
DEBUG(1, ("expected:\n"));
- dump_data(1, ntlmv2_session_key.data, ntlmv2_session_key.length);
+ dump_data(1, (const char *)ntlmv2_session_key.data, ntlmv2_session_key.length);
pass = False;
}
return pass;
@@ -442,8 +442,8 @@ static BOOL test_plaintext(enum ntlm_break break_which)
{
NTSTATUS nt_status;
uint32 flags = 0;
- DATA_BLOB nt_response = data_blob_null;
- DATA_BLOB lm_response = data_blob_null;
+ DATA_BLOB nt_response = data_blob(NULL, 0);
+ DATA_BLOB lm_response = data_blob(NULL, 0);
char *password;
smb_ucs2_t *nt_response_ucs2;
diff --git a/source/utils/pdbedit.c b/source/utils/pdbedit.c
index 5dff7e5a93f..82e5934165a 100644
--- a/source/utils/pdbedit.c
+++ b/source/utils/pdbedit.c
@@ -758,7 +758,6 @@ int main (int argc, char **argv)
static char *pwd_time_format = NULL;
static BOOL pw_from_stdin = False;
struct pdb_methods *bin, *bout, *bdef;
- char *configfile = NULL;
poptContext pc;
struct poptOption long_options[] = {
POPT_AUTOHELP
@@ -816,9 +815,6 @@ int main (int argc, char **argv)
case 'C':
account_policy_value_set = True;
break;
- case 's':
- configfile = optarg;
- break;
}
}
@@ -827,13 +823,12 @@ int main (int argc, char **argv)
if (user_name == NULL)
user_name = poptGetArg(pc);
- if (!lp_load(configfile?configfile:dyn_CONFIGFILE,
- True,False,False,True)) {
+ if (!lp_load(dyn_CONFIGFILE,True,False,False,True)) {
fprintf(stderr, "Can't load %s - run testparm to debug it\n", dyn_CONFIGFILE);
exit(1);
}
- if(!initialize_password_db(False, NULL))
+ if(!initialize_password_db(False))
exit(1);
if (!init_names())
diff --git a/source/utils/smbcacls.c b/source/utils/smbcacls.c
index 4a742510900..82cae037207 100644
--- a/source/utils/smbcacls.c
+++ b/source/utils/smbcacls.c
@@ -145,7 +145,7 @@ static BOOL StringToSid(DOM_SID *sid, const char *str)
if (!cacls_open_policy_hnd() ||
!NT_STATUS_IS_OK(rpccli_lsa_lookup_names(global_pipe_hnd, global_hack_cli->mem_ctx,
- &pol, 1, &str, NULL, 1, &sids,
+ &pol, 1, &str, NULL, &sids,
&types))) {
result = False;
goto done;
@@ -381,7 +381,7 @@ static SEC_DESC *sec_desc_parse(char *str)
fstring tok;
SEC_DESC *ret = NULL;
size_t sd_size;
- DOM_SID *grp_sid=NULL, *owner_sid=NULL;
+ DOM_SID *group_sid=NULL, *owner_sid=NULL;
SEC_ACL *dacl=NULL;
int revision=1;
@@ -407,13 +407,13 @@ static SEC_DESC *sec_desc_parse(char *str)
}
if (strncmp(tok,"GROUP:", 6) == 0) {
- if (grp_sid) {
+ if (group_sid) {
printf("Only specify group once\n");
goto done;
}
- grp_sid = SMB_CALLOC_ARRAY(DOM_SID, 1);
- if (!grp_sid ||
- !StringToSid(grp_sid, tok+6)) {
+ group_sid = SMB_CALLOC_ARRAY(DOM_SID, 1);
+ if (!group_sid ||
+ !StringToSid(group_sid, tok+6)) {
printf("Failed to parse group sid\n");
goto done;
}
@@ -436,11 +436,11 @@ static SEC_DESC *sec_desc_parse(char *str)
goto done;
}
- ret = make_sec_desc(ctx,revision, SEC_DESC_SELF_RELATIVE, owner_sid, grp_sid,
+ ret = make_sec_desc(ctx,revision, SEC_DESC_SELF_RELATIVE, owner_sid, group_sid,
NULL, dacl, &sd_size);
done:
- SAFE_FREE(grp_sid);
+ SAFE_FREE(group_sid);
SAFE_FREE(owner_sid);
return ret;
@@ -738,7 +738,7 @@ static int cacl_set(struct cli_state *cli, char *filename,
and W2K. JRA.
*/
- sd = make_sec_desc(ctx,old->revision, old->type, old->owner_sid, old->grp_sid,
+ sd = make_sec_desc(ctx,old->revision, old->type, old->owner_sid, old->group_sid,
NULL, old->dacl, &sd_size);
fnum = cli_nt_create(cli, filename, WRITE_DAC_ACCESS|WRITE_OWNER_ACCESS);
@@ -902,8 +902,11 @@ static struct cli_state *connect_one(const char *share)
fstrcpy(server,path+2);
share = strchr_m(server,'\\');
if (!share) {
- printf("Invalid argument: %s\n", share);
- return -1;
+ share = strchr_m(server,'/');
+ if (!share) {
+ printf("Invalid argument: %s\n", share);
+ return -1;
+ }
}
*share = 0;
diff --git a/source/utils/smbcontrol.c b/source/utils/smbcontrol.c
index 83ccce7057f..060079a5735 100644
--- a/source/utils/smbcontrol.c
+++ b/source/utils/smbcontrol.c
@@ -47,29 +47,42 @@ static int num_replies; /* Used by message callback fns */
/* Send a message to a destination pid. Zero means broadcast smbd. */
-static BOOL send_message(struct messaging_context *msg_ctx,
- struct server_id pid, int msg_type,
- const void *buf, int len)
+static BOOL send_message(struct process_id pid, int msg_type,
+ const void *buf, int len,
+ BOOL duplicates)
{
+ TDB_CONTEXT *tdb;
BOOL ret;
int n_sent = 0;
+ if (!message_init())
+ return False;
+
if (procid_to_pid(&pid) != 0)
- return NT_STATUS_IS_OK(
- messaging_send_buf(msg_ctx, pid, msg_type,
- (uint8 *)buf, len));
+ return NT_STATUS_IS_OK(message_send_pid(pid, msg_type, buf, len,
+ duplicates));
- ret = message_send_all(msg_ctx, msg_type, buf, len, &n_sent);
+ tdb = tdb_open_log(lock_path("connections.tdb"), 0,
+ TDB_DEFAULT, O_RDWR, 0);
+ if (!tdb) {
+ fprintf(stderr,"Failed to open connections database"
+ ": %s\n", strerror(errno));
+ return False;
+ }
+
+ ret = message_send_all(tdb,msg_type, buf, len, duplicates,
+ &n_sent);
DEBUG(10,("smbcontrol/send_message: broadcast message to "
"%d processes\n", n_sent));
+ tdb_close(tdb);
+
return ret;
}
/* Wait for one or more reply messages */
-static void wait_replies(struct messaging_context *msg_ctx,
- BOOL multiple_replies)
+static void wait_replies(BOOL multiple_replies)
{
time_t start_time = time(NULL);
@@ -77,8 +90,7 @@ static void wait_replies(struct messaging_context *msg_ctx,
busy-wait here as there is no nicer way to do it. */
do {
- message_dispatch(msg_ctx);
- event_loop_once(messaging_event_context(msg_ctx));
+ message_dispatch();
if (num_replies > 0 && !multiple_replies)
break;
sleep(1);
@@ -87,33 +99,26 @@ static void wait_replies(struct messaging_context *msg_ctx,
/* Message handler callback that displays the PID and a string on stdout */
-static void print_pid_string_cb(struct messaging_context *msg,
- void *private_data,
- uint32_t msg_type,
- struct server_id pid,
- DATA_BLOB *data)
+static void print_pid_string_cb(int msg_type, struct process_id pid, void *buf,
+ size_t len, void *private_data)
{
printf("PID %u: %.*s", (unsigned int)procid_to_pid(&pid),
- (int)data->length, (const char *)data->data);
+ (int)len, (const char *)buf);
num_replies++;
}
/* Message handler callback that displays a string on stdout */
-static void print_string_cb(struct messaging_context *msg,
- void *private_data,
- uint32_t msg_type,
- struct server_id pid,
- DATA_BLOB *data)
+static void print_string_cb(int msg_type, struct process_id pid,
+ void *buf, size_t len, void *private_data)
{
- printf("%.*s", (int)data->length, (const char *)data->data);
+ printf("%.*s", (int)len, (const char *)buf);
num_replies++;
}
/* Send no message. Useful for testing. */
-static BOOL do_noop(struct messaging_context *msg_ctx,
- const struct server_id pid,
+static BOOL do_noop(const struct process_id pid,
const int argc, const char **argv)
{
if (argc != 1) {
@@ -128,8 +133,7 @@ static BOOL do_noop(struct messaging_context *msg_ctx,
/* Send a debug string */
-static BOOL do_debug(struct messaging_context *msg_ctx,
- const struct server_id pid,
+static BOOL do_debug(const struct process_id pid,
const int argc, const char **argv)
{
if (argc != 2) {
@@ -138,8 +142,8 @@ static BOOL do_debug(struct messaging_context *msg_ctx,
return False;
}
- return send_message(msg_ctx, pid, MSG_DEBUG, argv[1],
- strlen(argv[1]) + 1);
+ return send_message(
+ pid, MSG_DEBUG, argv[1], strlen(argv[1]) + 1, False);
}
#if defined(HAVE_LIBUNWIND_PTRACE) && defined(HAVE_LINUX_PTRACE)
@@ -243,18 +247,21 @@ cleanup:
ptrace(PTRACE_DETACH, pid, NULL, NULL);
}
-static int stack_trace_connection(struct db_record *rec,
- const struct connections_key *key,
- const struct connections_data *crec,
- void *priv)
+static int stack_trace_connection(TDB_CONTEXT * tdb, TDB_DATA key,
+ TDB_DATA data, void * priv)
{
- print_stack_trace(procid_to_pid(&conn->pid), (int *)priv);
+ struct connections_data conn;
+
+ if (data.dsize != sizeof(conn))
+ return 0;
+
+ memcpy(&conn, data.dptr, sizeof(conn));
+ print_stack_trace(procid_to_pid(&conn.pid), (int *)priv);
return 0;
}
-static BOOL do_daemon_stack_trace(struct messaging_context *msg_ctx,
- const struct server_id pid,
+static BOOL do_daemon_stack_trace(const struct process_id pid,
const int argc, const char **argv)
{
fprintf(stderr,
@@ -279,7 +286,19 @@ static BOOL do_daemon_stack_trace(struct messaging_context *msg_ctx,
*/
print_stack_trace(dest, &count);
} else {
- connections_forall(stack_trace_connection, &count);
+ TDB_CONTEXT * tdb;
+
+ tdb = tdb_open_log(lock_path("connections.tdb"), 0,
+ TDB_DEFAULT, O_RDONLY, 0);
+ if (!tdb) {
+ fprintf(stderr,
+ "Failed to open connections database: %s\n",
+ strerror(errno));
+ return False;
+ }
+
+ tdb_traverse(tdb, stack_trace_connection, &count);
+ tdb_close(tdb);
}
return True;
@@ -287,8 +306,7 @@ static BOOL do_daemon_stack_trace(struct messaging_context *msg_ctx,
#else /* defined(HAVE_LIBUNWIND_PTRACE) && defined(HAVE_LINUX_PTRACE) */
-static BOOL do_daemon_stack_trace(struct messaging_context *msg_ctx,
- const struct server_id pid,
+static BOOL do_daemon_stack_trace(const struct process_id pid,
const int argc, const char **argv)
{
fprintf(stderr,
@@ -300,8 +318,7 @@ static BOOL do_daemon_stack_trace(struct messaging_context *msg_ctx,
/* Inject a fault (fatal signal) into a running smbd */
-static BOOL do_inject_fault(struct messaging_context *msg_ctx,
- const struct server_id pid,
+static BOOL do_inject_fault(const struct process_id pid,
const int argc, const char **argv)
{
if (argc != 2) {
@@ -334,16 +351,15 @@ static BOOL do_inject_fault(struct messaging_context *msg_ctx,
return False;
}
- return send_message(msg_ctx, pid, MSG_SMB_INJECT_FAULT,
- &sig, sizeof(int));
+ return send_message(pid, MSG_SMB_INJECT_FAULT,
+ &sig, sizeof(int), False);
}
#endif /* DEVELOPER */
}
/* Force a browser election */
-static BOOL do_election(struct messaging_context *msg_ctx,
- const struct server_id pid,
+static BOOL do_election(const struct process_id pid,
const int argc, const char **argv)
{
if (argc != 1) {
@@ -351,16 +367,14 @@ static BOOL do_election(struct messaging_context *msg_ctx,
return False;
}
- return send_message(msg_ctx, pid, MSG_FORCE_ELECTION, NULL, 0);
+ return send_message(
+ pid, MSG_FORCE_ELECTION, NULL, 0, False);
}
/* Ping a samba daemon process */
-static void pong_cb(struct messaging_context *msg,
- void *private_data,
- uint32_t msg_type,
- struct server_id pid,
- DATA_BLOB *data)
+static void pong_cb(int msg_type, struct process_id pid, void *buf,
+ size_t len, void *private_data)
{
char *src_string = procid_str(NULL, &pid);
printf("PONG from pid %s\n", src_string);
@@ -368,9 +382,7 @@ static void pong_cb(struct messaging_context *msg,
num_replies++;
}
-static BOOL do_ping(struct messaging_context *msg_ctx,
- const struct server_id pid,
- const int argc, const char **argv)
+static BOOL do_ping(const struct process_id pid, const int argc, const char **argv)
{
if (argc != 1) {
fprintf(stderr, "Usage: smbcontrol <dest> ping\n");
@@ -379,27 +391,26 @@ static BOOL do_ping(struct messaging_context *msg_ctx,
/* Send a message and register our interest in a reply */
- if (!send_message(msg_ctx, pid, MSG_PING, NULL, 0))
+ if (!send_message(pid, MSG_PING, NULL, 0, False))
return False;
- messaging_register(msg_ctx, NULL, MSG_PONG, pong_cb);
+ message_register(MSG_PONG, pong_cb, NULL);
- wait_replies(msg_ctx, procid_to_pid(&pid) == 0);
+ wait_replies(procid_to_pid(&pid) == 0);
/* No replies were received within the timeout period */
if (num_replies == 0)
printf("No replies received\n");
- messaging_deregister(msg_ctx, MSG_PONG, NULL);
+ message_deregister(MSG_PONG);
return num_replies;
}
/* Set profiling options */
-static BOOL do_profile(struct messaging_context *msg_ctx,
- const struct server_id pid,
+static BOOL do_profile(const struct process_id pid,
const int argc, const char **argv)
{
int v;
@@ -423,29 +434,26 @@ static BOOL do_profile(struct messaging_context *msg_ctx,
return False;
}
- return send_message(msg_ctx, pid, MSG_PROFILE, &v, sizeof(int));
+ return send_message(pid, MSG_PROFILE, &v, sizeof(int), False);
}
/* Return the profiling level */
-static void profilelevel_cb(struct messaging_context *msg_ctx,
- void *private_data,
- uint32_t msg_type,
- struct server_id pid,
- DATA_BLOB *data)
+static void profilelevel_cb(int msg_type, struct process_id pid, void *buf,
+ size_t len, void *private_data)
{
int level;
const char *s;
num_replies++;
- if (data->length != sizeof(int)) {
+ if (len != sizeof(int)) {
fprintf(stderr, "invalid message length %ld returned\n",
- (unsigned long)data->length);
+ (unsigned long)len);
return;
}
- memcpy(&level, data->data, sizeof(int));
+ memcpy(&level, buf, sizeof(int));
switch (level) {
case 0:
@@ -468,21 +476,17 @@ static void profilelevel_cb(struct messaging_context *msg_ctx,
printf("Profiling %s on pid %u\n",s,(unsigned int)procid_to_pid(&pid));
}
-static void profilelevel_rqst(struct messaging_context *msg_ctx,
- void *private_data,
- uint32_t msg_type,
- struct server_id pid,
- DATA_BLOB *data)
+static void profilelevel_rqst(int msg_type, struct process_id pid,
+ void *buf, size_t len, void *private_data)
{
int v = 0;
/* Send back a dummy reply */
- send_message(msg_ctx, pid, MSG_PROFILELEVEL, &v, sizeof(int));
+ send_message(pid, MSG_PROFILELEVEL, &v, sizeof(int), False);
}
-static BOOL do_profilelevel(struct messaging_context *msg_ctx,
- const struct server_id pid,
+static BOOL do_profilelevel(const struct process_id pid,
const int argc, const char **argv)
{
if (argc != 1) {
@@ -492,29 +496,27 @@ static BOOL do_profilelevel(struct messaging_context *msg_ctx,
/* Send a message and register our interest in a reply */
- if (!send_message(msg_ctx, pid, MSG_REQ_PROFILELEVEL, NULL, 0))
+ if (!send_message(pid, MSG_REQ_PROFILELEVEL, NULL, 0, False))
return False;
- messaging_register(msg_ctx, NULL, MSG_PROFILELEVEL, profilelevel_cb);
- messaging_register(msg_ctx, NULL, MSG_REQ_PROFILELEVEL,
- profilelevel_rqst);
+ message_register(MSG_PROFILELEVEL, profilelevel_cb, NULL);
+ message_register(MSG_REQ_PROFILELEVEL, profilelevel_rqst, NULL);
- wait_replies(msg_ctx, procid_to_pid(&pid) == 0);
+ wait_replies(procid_to_pid(&pid) == 0);
/* No replies were received within the timeout period */
if (num_replies == 0)
printf("No replies received\n");
- messaging_deregister(msg_ctx, MSG_PROFILE, NULL);
+ message_deregister(MSG_PROFILE);
return num_replies;
}
/* Display debug level settings */
-static BOOL do_debuglevel(struct messaging_context *msg_ctx,
- const struct server_id pid,
+static BOOL do_debuglevel(const struct process_id pid,
const int argc, const char **argv)
{
if (argc != 1) {
@@ -524,27 +526,26 @@ static BOOL do_debuglevel(struct messaging_context *msg_ctx,
/* Send a message and register our interest in a reply */
- if (!send_message(msg_ctx, pid, MSG_REQ_DEBUGLEVEL, NULL, 0))
+ if (!send_message(pid, MSG_REQ_DEBUGLEVEL, NULL, 0, False))
return False;
- messaging_register(msg_ctx, NULL, MSG_DEBUGLEVEL, print_pid_string_cb);
+ message_register(MSG_DEBUGLEVEL, print_pid_string_cb, NULL);
- wait_replies(msg_ctx, procid_to_pid(&pid) == 0);
+ wait_replies(procid_to_pid(&pid) == 0);
/* No replies were received within the timeout period */
if (num_replies == 0)
printf("No replies received\n");
- messaging_deregister(msg_ctx, MSG_DEBUGLEVEL, NULL);
+ message_deregister(MSG_DEBUGLEVEL);
return num_replies;
}
/* Send a print notify message */
-static BOOL do_printnotify(struct messaging_context *msg_ctx,
- const struct server_id pid,
+static BOOL do_printnotify(const struct process_id pid,
const int argc, const char **argv)
{
const char *cmd;
@@ -678,14 +679,13 @@ static BOOL do_printnotify(struct messaging_context *msg_ctx,
return False;
send:
- print_notify_send_messages(msg_ctx, 0);
+ print_notify_send_messages(0);
return True;
}
/* Close a share */
-static BOOL do_closeshare(struct messaging_context *msg_ctx,
- const struct server_id pid,
+static BOOL do_closeshare(const struct process_id pid,
const int argc, const char **argv)
{
if (argc != 2) {
@@ -694,42 +694,13 @@ static BOOL do_closeshare(struct messaging_context *msg_ctx,
return False;
}
- return send_message(msg_ctx, pid, MSG_SMB_FORCE_TDIS, argv[1],
- strlen(argv[1]) + 1);
-}
-
-/* force a blocking lock retry */
-
-static BOOL do_lockretry(struct messaging_context *msg_ctx,
- const struct server_id pid,
- const int argc, const char **argv)
-{
- if (argc != 1) {
- fprintf(stderr, "Usage: smbcontrol <dest> lockretry\n");
- return False;
- }
-
- return send_message(msg_ctx, pid, MSG_SMB_UNLOCK, NULL, 0);
-}
-
-/* force a validation of all brl entries, including re-sends. */
-
-static BOOL do_brl_revalidate(struct messaging_context *msg_ctx,
- const struct server_id pid,
- const int argc, const char **argv)
-{
- if (argc != 1) {
- fprintf(stderr, "Usage: smbcontrol <dest> brl-revalidate\n");
- return False;
- }
-
- return send_message(msg_ctx, pid, MSG_SMB_BRL_VALIDATE, NULL, 0);
+ return send_message(
+ pid, MSG_SMB_FORCE_TDIS, argv[1], strlen(argv[1]) + 1, False);
}
/* Force a SAM synchronisation */
-static BOOL do_samsync(struct messaging_context *msg_ctx,
- const struct server_id pid,
+static BOOL do_samsync(const struct process_id pid,
const int argc, const char **argv)
{
if (argc != 1) {
@@ -737,13 +708,13 @@ static BOOL do_samsync(struct messaging_context *msg_ctx,
return False;
}
- return send_message(msg_ctx, pid, MSG_SMB_SAM_SYNC, NULL, 0);
+ return send_message(
+ pid, MSG_SMB_SAM_SYNC, NULL, 0, False);
}
/* Force a SAM replication */
-static BOOL do_samrepl(struct messaging_context *msg_ctx,
- const struct server_id pid,
+static BOOL do_samrepl(const struct process_id pid,
const int argc, const char **argv)
{
if (argc != 1) {
@@ -751,13 +722,13 @@ static BOOL do_samrepl(struct messaging_context *msg_ctx,
return False;
}
- return send_message(msg_ctx, pid, MSG_SMB_SAM_REPL, NULL, 0);
+ return send_message(
+ pid, MSG_SMB_SAM_REPL, NULL, 0, False);
}
/* Display talloc pool usage */
-static BOOL do_poolusage(struct messaging_context *msg_ctx,
- const struct server_id pid,
+static BOOL do_poolusage(const struct process_id pid,
const int argc, const char **argv)
{
if (argc != 1) {
@@ -765,29 +736,28 @@ static BOOL do_poolusage(struct messaging_context *msg_ctx,
return False;
}
- messaging_register(msg_ctx, NULL, MSG_POOL_USAGE, print_string_cb);
+ message_register(MSG_POOL_USAGE, print_string_cb, NULL);
/* Send a message and register our interest in a reply */
- if (!send_message(msg_ctx, pid, MSG_REQ_POOL_USAGE, NULL, 0))
+ if (!send_message(pid, MSG_REQ_POOL_USAGE, NULL, 0, False))
return False;
- wait_replies(msg_ctx, procid_to_pid(&pid) == 0);
+ wait_replies(procid_to_pid(&pid) == 0);
/* No replies were received within the timeout period */
if (num_replies == 0)
printf("No replies received\n");
- messaging_deregister(msg_ctx, MSG_POOL_USAGE, NULL);
+ message_deregister(MSG_POOL_USAGE);
return num_replies;
}
/* Perform a dmalloc mark */
-static BOOL do_dmalloc_mark(struct messaging_context *msg_ctx,
- const struct server_id pid,
+static BOOL do_dmalloc_mark(const struct process_id pid,
const int argc, const char **argv)
{
if (argc != 1) {
@@ -795,13 +765,13 @@ static BOOL do_dmalloc_mark(struct messaging_context *msg_ctx,
return False;
}
- return send_message(msg_ctx, pid, MSG_REQ_DMALLOC_MARK, NULL, 0);
+ return send_message(
+ pid, MSG_REQ_DMALLOC_MARK, NULL, 0, False);
}
/* Perform a dmalloc changed */
-static BOOL do_dmalloc_changed(struct messaging_context *msg_ctx,
- const struct server_id pid,
+static BOOL do_dmalloc_changed(const struct process_id pid,
const int argc, const char **argv)
{
if (argc != 1) {
@@ -810,14 +780,13 @@ static BOOL do_dmalloc_changed(struct messaging_context *msg_ctx,
return False;
}
- return send_message(msg_ctx, pid, MSG_REQ_DMALLOC_LOG_CHANGED,
- NULL, 0);
+ return send_message(
+ pid, MSG_REQ_DMALLOC_LOG_CHANGED, NULL, 0, False);
}
/* Shutdown a server process */
-static BOOL do_shutdown(struct messaging_context *msg_ctx,
- const struct server_id pid,
+static BOOL do_shutdown(const struct process_id pid,
const int argc, const char **argv)
{
if (argc != 1) {
@@ -825,13 +794,12 @@ static BOOL do_shutdown(struct messaging_context *msg_ctx,
return False;
}
- return send_message(msg_ctx, pid, MSG_SHUTDOWN, NULL, 0);
+ return send_message(pid, MSG_SHUTDOWN, NULL, 0, False);
}
/* Notify a driver upgrade */
-static BOOL do_drvupgrade(struct messaging_context *msg_ctx,
- const struct server_id pid,
+static BOOL do_drvupgrade(const struct process_id pid,
const int argc, const char **argv)
{
if (argc != 2) {
@@ -840,12 +808,11 @@ static BOOL do_drvupgrade(struct messaging_context *msg_ctx,
return False;
}
- return send_message(msg_ctx, pid, MSG_DEBUG, argv[1],
- strlen(argv[1]) + 1);
+ return send_message(
+ pid, MSG_DEBUG, argv[1], strlen(argv[1]) + 1, False);
}
-static BOOL do_winbind_online(struct messaging_context *msg_ctx,
- const struct server_id pid,
+static BOOL do_winbind_online(const struct process_id pid,
const int argc, const char **argv)
{
TDB_CONTEXT *tdb;
@@ -875,11 +842,10 @@ static BOOL do_winbind_online(struct messaging_context *msg_ctx,
tdb_delete_bystring(tdb, "WINBINDD_OFFLINE");
tdb_close(tdb);
- return send_message(msg_ctx, pid, MSG_WINBIND_ONLINE, NULL, 0);
+ return send_message(pid, MSG_WINBIND_ONLINE, NULL, 0, False);
}
-static BOOL do_winbind_offline(struct messaging_context *msg_ctx,
- const struct server_id pid,
+static BOOL do_winbind_offline(const struct process_id pid,
const int argc, const char **argv)
{
TDB_CONTEXT *tdb;
@@ -921,7 +887,7 @@ static BOOL do_winbind_offline(struct messaging_context *msg_ctx,
for (retry = 0; retry < 5; retry++) {
TDB_DATA d;
- uint8 buf[4];
+ char buf[4];
ZERO_STRUCT(d);
@@ -931,8 +897,7 @@ static BOOL do_winbind_offline(struct messaging_context *msg_ctx,
tdb_store_bystring(tdb, "WINBINDD_OFFLINE", d, TDB_INSERT);
- ret = send_message(msg_ctx, pid, MSG_WINBIND_OFFLINE,
- NULL, 0);
+ ret = send_message(pid, MSG_WINBIND_OFFLINE, NULL, 0, False);
/* Check that the entry "WINBINDD_OFFLINE" still exists. */
d = tdb_fetch_bystring( tdb, "WINBINDD_OFFLINE" );
@@ -950,11 +915,10 @@ static BOOL do_winbind_offline(struct messaging_context *msg_ctx,
return ret;
}
-static BOOL do_winbind_onlinestatus(struct messaging_context *msg_ctx,
- const struct server_id pid,
+static BOOL do_winbind_onlinestatus(const struct process_id pid,
const int argc, const char **argv)
{
- struct server_id myid;
+ struct process_id myid;
myid = pid_to_procid(sys_getpid());
@@ -963,44 +927,25 @@ static BOOL do_winbind_onlinestatus(struct messaging_context *msg_ctx,
return False;
}
- messaging_register(msg_ctx, NULL, MSG_WINBIND_ONLINESTATUS,
- print_pid_string_cb);
+ message_register(MSG_WINBIND_ONLINESTATUS, print_pid_string_cb, NULL);
- if (!send_message(msg_ctx, pid, MSG_WINBIND_ONLINESTATUS, &myid,
- sizeof(myid)))
+ if (!send_message(pid, MSG_WINBIND_ONLINESTATUS, &myid, sizeof(myid), False))
return False;
- wait_replies(msg_ctx, procid_to_pid(&pid) == 0);
+ wait_replies(procid_to_pid(&pid) == 0);
/* No replies were received within the timeout period */
if (num_replies == 0)
printf("No replies received\n");
- messaging_deregister(msg_ctx, MSG_WINBIND_ONLINESTATUS, NULL);
+ message_deregister(MSG_WINBIND_ONLINESTATUS);
return num_replies;
}
-static BOOL do_dump_event_list(struct messaging_context *msg_ctx,
- const struct server_id pid,
- const int argc, const char **argv)
-{
- struct server_id myid;
-
- myid = pid_to_procid(sys_getpid());
-
- if (argc != 1) {
- fprintf(stderr, "Usage: smbcontrol <dest> dump-event-list\n");
- return False;
- }
-
- return send_message(msg_ctx, pid, MSG_DUMP_EVENT_LIST, NULL, 0);
-}
-
-static BOOL do_reload_config(struct messaging_context *msg_ctx,
- const struct server_id pid,
+static BOOL do_reload_config(const struct process_id pid,
const int argc, const char **argv)
{
if (argc != 1) {
@@ -1008,7 +953,7 @@ static BOOL do_reload_config(struct messaging_context *msg_ctx,
return False;
}
- return send_message(msg_ctx, pid, MSG_SMB_CONF_UPDATED, NULL, 0);
+ return send_message(pid, MSG_SMB_CONF_UPDATED, NULL, 0, False);
}
static void my_make_nmb_name( struct nmb_name *n, const char *name, int type)
@@ -1022,8 +967,7 @@ static void my_make_nmb_name( struct nmb_name *n, const char *name, int type)
push_ascii(n->scope, global_scope(), 64, STR_TERMINATE);
}
-static BOOL do_nodestatus(struct messaging_context *msg_ctx,
- const struct server_id pid,
+static BOOL do_nodestatus(const struct process_id pid,
const int argc, const char **argv)
{
struct packet_struct p;
@@ -1056,15 +1000,14 @@ static BOOL do_nodestatus(struct messaging_context *msg_ctx,
p.packet.nmb.question.question_type = 0x21;
p.packet.nmb.question.question_class = 0x1;
- return send_message(msg_ctx, pid, MSG_SEND_PACKET, &p, sizeof(p));
+ return send_message(pid, MSG_SEND_PACKET, &p, sizeof(p), False);
}
/* A list of message type supported */
static const struct {
const char *name; /* Option name */
- BOOL (*fn)(struct messaging_context *msg_ctx,
- const struct server_id pid,
+ BOOL (*fn)(const struct process_id pid,
const int argc, const char **argv);
const char *help; /* Short help text */
} msg_types[] = {
@@ -1081,8 +1024,6 @@ static const struct {
{ "debuglevel", do_debuglevel, "Display current debuglevels" },
{ "printnotify", do_printnotify, "Send a print notify message" },
{ "close-share", do_closeshare, "Forcibly disconnect a share" },
- { "lockretry", do_lockretry, "Force a blocking lock retry" },
- { "brl-revalidate", do_brl_revalidate, "Revalidate all brl entries" },
{ "samsync", do_samsync, "Initiate SAM synchronisation" },
{ "samrepl", do_samrepl, "Initiate SAM replication" },
{ "pool-usage", do_poolusage, "Display talloc memory usage" },
@@ -1095,18 +1036,17 @@ static const struct {
{ "online", do_winbind_online, "Ask winbind to go into online state"},
{ "offline", do_winbind_offline, "Ask winbind to go into offline state"},
{ "onlinestatus", do_winbind_onlinestatus, "Request winbind online status"},
- { "dump-event-list", do_dump_event_list, "Dump event list"},
{ "noop", do_noop, "Do nothing" },
{ NULL }
};
/* Display usage information */
-static void usage(poptContext pc)
+static void usage(poptContext *pc)
{
int i;
- poptPrintHelp(pc, stderr, 0);
+ poptPrintHelp(*pc, stderr, 0);
fprintf(stderr, "\n");
fprintf(stderr, "<destination> is one of \"nmbd\", \"smbd\", \"winbindd\" or a "
@@ -1126,9 +1066,9 @@ static void usage(poptContext pc)
/* Return the pid number for a string destination */
-static struct server_id parse_dest(const char *dest)
+static struct process_id parse_dest(const char *dest)
{
- struct server_id result = {-1};
+ struct process_id result = {-1};
pid_t pid;
/* Zero is a special return value for broadcast smbd */
@@ -1173,11 +1113,10 @@ static struct server_id parse_dest(const char *dest)
/* Execute smbcontrol command */
-static BOOL do_command(struct messaging_context *msg_ctx,
- int argc, const char **argv)
+static BOOL do_command(int argc, const char **argv)
{
const char *dest = argv[0], *command = argv[1];
- struct server_id pid;
+ struct process_id pid;
int i;
/* Check destination */
@@ -1191,8 +1130,7 @@ static BOOL do_command(struct messaging_context *msg_ctx,
for (i = 0; msg_types[i].name; i++) {
if (strequal(command, msg_types[i].name))
- return msg_types[i].fn(msg_ctx, pid,
- argc - 1, argv + 1);
+ return msg_types[i].fn(pid, argc - 1, argv + 1);
}
fprintf(stderr, "smbcontrol: unknown command '%s'\n", command);
@@ -1200,42 +1138,15 @@ static BOOL do_command(struct messaging_context *msg_ctx,
return False;
}
-static void smbcontrol_help(poptContext pc,
- enum poptCallbackReason preason,
- struct poptOption * poption,
- const char * parg,
- void * pdata)
-{
- if (poption->shortName != '?') {
- poptPrintUsage(pc, stdout, 0);
- } else {
- usage(pc);
- }
-
- exit(0);
-}
-
-struct poptOption help_options[] = {
- { NULL, '\0', POPT_ARG_CALLBACK, (void *)&smbcontrol_help, '\0',
- NULL, NULL },
- { "help", '?', 0, NULL, '?', "Show this help message", NULL },
- { "usage", '\0', 0, NULL, 'u', "Display brief usage message", NULL },
- { NULL }
-} ;
-
/* Main program */
int main(int argc, const char **argv)
{
poptContext pc;
int opt;
- struct event_context *evt_ctx;
- struct messaging_context *msg_ctx;
static struct poptOption long_options[] = {
- /* POPT_AUTOHELP */
- { NULL, '\0', POPT_ARG_INCLUDE_TABLE, help_options,
- 0, "Help options:", NULL },
+ POPT_AUTOHELP
{ "timeout", 't', POPT_ARG_INT, &timeout, 't',
"Set timeout value in seconds", "TIMEOUT" },
@@ -1256,7 +1167,7 @@ int main(int argc, const char **argv)
"<parameters>");
if (argc == 1)
- usage(pc);
+ usage(&pc);
while ((opt = poptGetNextOpt(pc)) != -1) {
switch(opt) {
@@ -1280,7 +1191,7 @@ int main(int argc, const char **argv)
}
if (argc == 1)
- usage(pc);
+ usage(&pc);
lp_load(dyn_CONFIGFILE,False,False,False,True);
@@ -1288,11 +1199,5 @@ int main(int argc, const char **argv)
* routines mostly return True==1 for success, but
* shell needs 0. */
- if (!(evt_ctx = event_context_init(NULL)) ||
- !(msg_ctx = messaging_init(NULL, server_id_self(), evt_ctx))) {
- fprintf(stderr, "could not init messaging context\n");
- exit(1);
- }
-
- return !do_command(msg_ctx, argc, argv);
+ return !do_command(argc, argv);
}
diff --git a/source/utils/smbcquotas.c b/source/utils/smbcquotas.c
index bf05441c21e..40f4a86f96b 100644
--- a/source/utils/smbcquotas.c
+++ b/source/utils/smbcquotas.c
@@ -116,7 +116,7 @@ static BOOL StringToSid(DOM_SID *sid, const char *str)
if (!cli_open_policy_hnd() ||
!NT_STATUS_IS_OK(rpccli_lsa_lookup_names(global_pipe_hnd, cli_ipc->mem_ctx,
- &pol, 1, &str, NULL, 1, &sids,
+ &pol, 1, &str, NULL, &sids,
&types))) {
result = False;
goto done;
@@ -500,8 +500,11 @@ FSQFLAGS:QUOTA_ENABLED/DENY_DISK/LOG_SOFTLIMIT/LOG_HARD_LIMIT", "SETSTRING" },
pstrcpy(server,path+2);
share = strchr_m(server,'\\');
if (!share) {
- printf("Invalid argument: %s\n", share);
- exit(EXIT_PARSE_ERROR);
+ share = strchr_m(server,'/');
+ if (!share) {
+ printf("Invalid argument: %s\n", share);
+ exit(EXIT_PARSE_ERROR);
+ }
}
*share = 0;
diff --git a/source/utils/smbpasswd.c b/source/utils/smbpasswd.c
index 92179567812..74606624412 100644
--- a/source/utils/smbpasswd.c
+++ b/source/utils/smbpasswd.c
@@ -305,7 +305,7 @@ static int process_root(int local_flags)
}
/* Ensure passdb startup(). */
- if(!initialize_password_db(False, NULL)) {
+ if(!initialize_password_db(False)) {
DEBUG(0, ("Failed to open passdb!\n"));
exit(1);
}
diff --git a/source/utils/smbtree.c b/source/utils/smbtree.c
index 31ed7635654..d9cd446f6cb 100644
--- a/source/utils/smbtree.c
+++ b/source/utils/smbtree.c
@@ -134,12 +134,10 @@ static BOOL get_rpc_shares(struct cli_state *cli,
NTSTATUS status;
struct rpc_pipe_client *pipe_hnd;
TALLOC_CTX *mem_ctx;
- uint32 enum_hnd;
- struct srvsvc_NetShareCtr1 ctr1;
- union srvsvc_NetShareCtr ctr;
- uint32 numentries;
+ ENUM_HND enum_hnd;
+ WERROR werr;
+ SRV_SHARE_INFO_CTR ctr;
int i;
- uint32 info_level = 1;
mem_ctx = talloc_new(NULL);
if (mem_ctx == NULL) {
@@ -147,7 +145,8 @@ static BOOL get_rpc_shares(struct cli_state *cli,
return False;
}
- enum_hnd = 0;
+ init_enum_hnd(&enum_hnd, 0);
+
pipe_hnd = cli_rpc_pipe_open_noauth(cli, PI_SRVSVC, &status);
if (pipe_hnd == NULL) {
@@ -157,24 +156,23 @@ static BOOL get_rpc_shares(struct cli_state *cli,
return False;
}
- ZERO_STRUCT(ctr1);
- level = 1;
- ctr.ctr1 = &ctr1;
-
- status = rpccli_srvsvc_NetShareEnum(pipe_hnd, mem_ctx, NULL,
- &info_level, &ctr,
- 0xffffffff, &numentries,
- &enum_hnd);
+ werr = rpccli_srvsvc_net_share_enum(pipe_hnd, mem_ctx, 1, &ctr,
+ 0xffffffff, &enum_hnd);
- if (!NT_STATUS_IS_OK(status)) {
+ if (!W_ERROR_IS_OK(werr)) {
TALLOC_FREE(mem_ctx);
cli_rpc_pipe_close(pipe_hnd);
return False;
}
- for (i=0; i<numentries; i++) {
- fn(ctr.ctr1->array[i].name, ctr.ctr1->array[i].type,
- ctr.ctr1->array[i].comment, state);
+ for (i=0; i<ctr.num_entries; i++) {
+ SRV_SHARE_INFO_1 *info = &ctr.share.info1[i];
+ char *name, *comment;
+ name = rpcstr_pull_unistr2_talloc(
+ mem_ctx, &info->info_1_str.uni_netname);
+ comment = rpcstr_pull_unistr2_talloc(
+ mem_ctx, &info->info_1_str.uni_remark);
+ fn(name, info->info_1.type, comment, state);
}
TALLOC_FREE(mem_ctx);
diff --git a/source/utils/status.c b/source/utils/status.c
index d6e408e52ea..df742f73e79 100644
--- a/source/utils/status.c
+++ b/source/utils/status.c
@@ -35,7 +35,7 @@
#define SMB_MAXPIDS 2048
static uid_t Ucrit_uid = 0; /* added by OH */
-static struct server_id Ucrit_pid[SMB_MAXPIDS]; /* Ugly !!! */ /* added by OH */
+static pid_t Ucrit_pid[SMB_MAXPIDS]; /* Ugly !!! */ /* added by OH */
static int Ucrit_MaxPid=0; /* added by OH */
static unsigned int Ucrit_IsActive = 0; /* added by OH */
@@ -69,7 +69,7 @@ static unsigned int Ucrit_checkUid(uid_t uid)
return 0;
}
-static unsigned int Ucrit_checkPid(struct server_id pid)
+static unsigned int Ucrit_checkPid(pid_t pid)
{
int i;
@@ -77,14 +77,14 @@ static unsigned int Ucrit_checkPid(struct server_id pid)
return 1;
for (i=0;i<Ucrit_MaxPid;i++) {
- if (cluster_id_equal(&pid, &Ucrit_pid[i]))
+ if( pid == Ucrit_pid[i] )
return 1;
}
return 0;
}
-static BOOL Ucrit_addPid( struct server_id pid )
+static BOOL Ucrit_addPid( pid_t pid )
{
if ( !Ucrit_IsActive )
return True;
@@ -119,7 +119,7 @@ static void print_share_mode(const struct share_mode_entry *e,
}
count++;
- if (Ucrit_checkPid(e->pid)) {
+ if (Ucrit_checkPid(procid_to_pid(&e->pid))) {
d_printf("%-11s ",procid_str_static(&e->pid));
d_printf("%-9u ", (unsigned int)e->uid);
switch (map_share_mode_to_deny_mode(e->share_access,
@@ -166,27 +166,15 @@ static void print_share_mode(const struct share_mode_entry *e,
}
}
-static void print_brl(struct file_id id,
- struct server_id pid,
+static void print_brl(SMB_DEV_T dev,
+ SMB_INO_T ino,
+ struct process_id pid,
enum brl_type lock_type,
enum brl_flavour lock_flav,
br_off start,
- br_off size,
- void *private_data)
+ br_off size)
{
static int count;
- int i;
- static const struct {
- enum brl_type lock_type;
- const char *desc;
- } lock_types[] = {
- { READ_LOCK, "R" },
- { WRITE_LOCK, "W" },
- { PENDING_READ_LOCK, "PR" },
- { PENDING_WRITE_LOCK, "PW" },
- { UNLOCK_LOCK, "U" }
- };
- const char *desc="X";
if (count==0) {
d_printf("Byte range locks:\n");
d_printf(" Pid dev:inode R/W start size\n");
@@ -194,49 +182,47 @@ static void print_brl(struct file_id id,
}
count++;
- for (i=0;i<ARRAY_SIZE(lock_types);i++) {
- if (lock_type == lock_types[i].lock_type) {
- desc = lock_types[i].desc;
- }
- }
-
- d_printf("%8s %s %2s %9.0f %9.0f\n",
- procid_str_static(&pid), file_id_static_string(&id),
- desc,
- (double)start, (double)size);
+ d_printf("%8s %05x:%05x %s %9.0f %9.0f\n",
+ procid_str_static(&pid), (int)dev, (int)ino,
+ lock_type==READ_LOCK?"R":"W",
+ (double)start, (double)size);
}
-static int traverse_fn1(struct db_record *rec,
- const struct connections_key *key,
- const struct connections_data *crec,
- void *state)
+static int traverse_fn1(TDB_CONTEXT *tdb, TDB_DATA kbuf, TDB_DATA dbuf, void *state)
{
- if (crec->cnum == -1)
+ struct connections_data crec;
+
+ if (dbuf.dsize != sizeof(crec))
+ return 0;
+
+ memcpy(&crec, dbuf.dptr, sizeof(crec));
+
+ if (crec.cnum == -1)
return 0;
- if (!process_exists(crec->pid) || !Ucrit_checkUid(crec->uid)) {
+ if (!process_exists(crec.pid) || !Ucrit_checkUid(crec.uid)) {
return 0;
}
d_printf("%-10s %s %-12s %s",
- crec->servicename,procid_str_static(&crec->pid),
- crec->machine,
- time_to_asc(crec->start));
+ crec.servicename,procid_str_static(&crec.pid),
+ crec.machine,
+ time_to_asc(crec.start));
return 0;
}
-static int traverse_sessionid(struct db_record *db, void *state)
+static int traverse_sessionid(TDB_CONTEXT *tdb, TDB_DATA kbuf, TDB_DATA dbuf, void *state)
{
struct sessionid sessionid;
fstring uid_str, gid_str;
- if (db->value.dsize != sizeof(sessionid))
+ if (dbuf.dsize != sizeof(sessionid))
return 0;
- memcpy(&sessionid, db->value.dptr, sizeof(sessionid));
+ memcpy(&sessionid, dbuf.dptr, sizeof(sessionid));
- if (!process_exists(sessionid.pid) || !Ucrit_checkUid(sessionid.uid)) {
+ if (!process_exists_by_pid(sessionid.pid) || !Ucrit_checkUid(sessionid.uid)) {
return 0;
}
@@ -245,8 +231,8 @@ static int traverse_sessionid(struct db_record *db, void *state)
fstr_sprintf(uid_str, "%d", sessionid.uid);
fstr_sprintf(gid_str, "%d", sessionid.gid);
- d_printf("%-7s %-12s %-12s %-12s (%s)\n",
- procid_str_static(&sessionid.pid),
+ d_printf("%5d %-12s %-12s %-12s (%s)\n",
+ (int)sessionid.pid,
numeric_only ? uid_str : uidtoname(sessionid.uid),
numeric_only ? gid_str : gidtoname(sessionid.gid),
sessionid.remote_machine, sessionid.hostname);
@@ -261,6 +247,7 @@ static int traverse_sessionid(struct db_record *db, void *state)
{
int c;
int profile_only = 0;
+ TDB_CONTEXT *tdb;
BOOL show_processes, show_locks, show_shares;
poptContext pc;
struct poptOption long_options[] = {
@@ -323,13 +310,6 @@ static int traverse_sessionid(struct db_record *db, void *state)
return (-1);
}
- /*
- * This implicitly initializes the global ctdbd connection, usable by
- * the db_open() calls further down.
- */
-
- messaging_init(NULL, procid_self(), event_context_init(NULL));
-
switch (profile_only) {
case 'P':
/* Dump profile data */
@@ -342,18 +322,16 @@ static int traverse_sessionid(struct db_record *db, void *state)
}
if ( show_processes ) {
- struct db_context *db;
- db = db_open(NULL, lock_path("sessionid.tdb"), 0,
- TDB_DEFAULT, O_RDWR, 0644);
- if (!db) {
+ tdb = tdb_open_log(lock_path("sessionid.tdb"), 0, TDB_DEFAULT, O_RDONLY, 0);
+ if (!tdb) {
d_printf("sessionid.tdb not initialised\n");
} else {
d_printf("\nSamba version %s\n",SAMBA_VERSION_STRING);
d_printf("PID Username Group Machine \n");
d_printf("-------------------------------------------------------------------\n");
- db->traverse_read(db, traverse_sessionid, NULL);
- talloc_free(db);
+ tdb_traverse(tdb, traverse_sessionid, NULL);
+ tdb_close(tdb);
}
if (processes_only)
@@ -361,19 +339,26 @@ static int traverse_sessionid(struct db_record *db, void *state)
}
if ( show_shares ) {
- if (verbose) {
- d_printf("Opened %s\n", lock_path("connections.tdb"));
- }
+ tdb = tdb_open_log(lock_path("connections.tdb"), 0, TDB_DEFAULT, O_RDONLY, 0);
+ if (!tdb) {
+ d_printf("%s not initialised\n", lock_path("connections.tdb"));
+ d_printf("This is normal if an SMB client has never connected to your server.\n");
+ } else {
+ if (verbose) {
+ d_printf("Opened %s\n", lock_path("connections.tdb"));
+ }
- if (brief)
- exit(0);
+ if (brief)
+ exit(0);
- d_printf("\nService pid machine Connected at\n");
- d_printf("-------------------------------------------------------\n");
+ d_printf("\nService pid machine Connected at\n");
+ d_printf("-------------------------------------------------------\n");
- connections_forall(traverse_fn1, NULL);
+ tdb_traverse(tdb, traverse_fn1, NULL);
+ tdb_close(tdb);
- d_printf("\n");
+ d_printf("\n");
+ }
if ( shares_only )
exit(0);
@@ -398,7 +383,7 @@ static int traverse_sessionid(struct db_record *db, void *state)
d_printf("\n");
if (show_brl) {
- brl_forall(print_brl, NULL);
+ brl_forall(print_brl);
}
locking_end();
diff --git a/source/utils/status_profile.c b/source/utils/status_profile.c
index cc7feec2d83..b4c4940f3fd 100644
--- a/source/utils/status_profile.c
+++ b/source/utils/status_profile.c
@@ -47,7 +47,7 @@ static void profile_separator(const char * title)
BOOL status_profile_dump(BOOL verbose)
{
#ifdef WITH_PROFILE
- if (!profile_setup(NULL, True)) {
+ if (!profile_setup(True)) {
fprintf(stderr,"Failed to initialise profile memory\n");
return False;
}
@@ -487,7 +487,7 @@ BOOL status_profile_rates(BOOL verbose)
usec_to_sec(sample_interval_usec));
}
- if (!profile_setup(NULL, True)) {
+ if (!profile_setup(True)) {
fprintf(stderr,"Failed to initialise profile memory\n");
return False;
}