summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGünther Deschner <gd@samba.org>2007-12-11 21:21:17 +0100
committerGünther Deschner <gd@samba.org>2007-12-21 15:29:09 +0100
commit1b5c1ae7424ba2fad857adf3701a5809ba3b27fe (patch)
tree21af290370c8fdea0dfbe8421cb94d3dc894f0ca
parent8edf48bbf716c3a6b7919c74aa5ed954d9cce48d (diff)
downloadsamba-1b5c1ae7424ba2fad857adf3701a5809ba3b27fe.tar.gz
samba-1b5c1ae7424ba2fad857adf3701a5809ba3b27fe.tar.bz2
samba-1b5c1ae7424ba2fad857adf3701a5809ba3b27fe.zip
Very quick conversion of net_conf functions into the libnet_conf layer.
Certainly needs cleanup later. Guenther (This used to be commit 2b41ac926de76804a50681bd246b3a20e112853b)
-rw-r--r--source3/Makefile.in14
-rw-r--r--source3/libnet/libnet_conf.c149
-rw-r--r--source3/utils/net_conf.c158
3 files changed, 176 insertions, 145 deletions
diff --git a/source3/Makefile.in b/source3/Makefile.in
index 63a83befa8..cbd8118746 100644
--- a/source3/Makefile.in
+++ b/source3/Makefile.in
@@ -707,6 +707,8 @@ REG_API_OBJ = registry/reg_api.o \
NETAPI_OBJ = lib/netapi/joindomain.o
+LIBNET_OBJ = libnet/libnet_conf.o
+
NET_OBJ1 = utils/net.o utils/net_ads.o utils/net_domain.o utils/net_help.o \
utils/net_rap.o utils/net_rpc.o utils/net_rpc_samsync.o \
utils/net_rpc_join.o utils/net_time.o utils/net_lookup.o \
@@ -726,7 +728,7 @@ NET_OBJ = $(NET_OBJ1) $(PARAM_WITHOUT_REG_OBJ) $(SECRETS_OBJ) $(LIBSMB_OBJ) \
$(SMBLDAP_OBJ) $(DCUTIL_OBJ) $(SERVER_MUTEX_OBJ) \
$(AFS_OBJ) $(AFS_SETTOKEN_OBJ) $(REGFIO_OBJ) $(READLINE_OBJ) \
$(LDB_OBJ) $(LIBGPO_OBJ) @BUILD_INIPARSER@ $(DISPLAY_SEC_OBJ) \
- $(REG_API_OBJ) $(DISPLAY_DSDCINFO_OBJ) $(NETAPI_OBJ)
+ $(REG_API_OBJ) $(DISPLAY_DSDCINFO_OBJ) $(NETAPI_OBJ) $(LIBNET_OBJ)
CUPS_OBJ = client/smbspool.o $(PARAM_OBJ) $(LIBSMB_OBJ) \
$(LIB_NONSMBD_OBJ) $(KRBCLIENT_OBJ) $(SECRETS_OBJ) $(POPT_LIB_OBJ)
@@ -1933,7 +1935,7 @@ delheaders:
winbindd/winbindd_proto.h web/swat_proto.h \
client/client_proto.h utils/net_proto.h \
smbd/build_options.c utils/ntlm_auth_proto.h \
- utils/passwd_proto.h
+ utils/passwd_proto.h libnet/libnet_proto.h
MKPROTO_SH = $(srcdir)/script/mkproto.sh
@@ -1978,6 +1980,11 @@ utils/ntlm_auth_proto.h:
-h _NTLM_AUTH_PROTO_H_ $(builddir)/utils/ntlm_auth_proto.h \
$(NTLM_AUTH_OBJ1)
+libnet/libnet_proto.h:
+ @cd $(srcdir) && $(SHELL) $(MKPROTO_SH) $(AWK) \
+ -h _LIBNET_PROTO_H_ $(builddir)/libnet/libnet_proto.h \
+ $(LIBNET_OBJ)
+
# "make headers" or "make proto" calls a subshell because we need to
# make sure these commands are executed in sequence even for a
# parallel make.
@@ -1991,7 +1998,8 @@ headers:
$(MAKE) client/client_proto.h; \
$(MAKE) utils/ntlm_auth_proto.h; \
$(MAKE) utils/net_proto.h; \
- $(MAKE) utils/passwd_proto.h;
+ $(MAKE) utils/passwd_proto.h; \
+ $(MAKE) libnet/libnet_proto.h;
proto: headers
diff --git a/source3/libnet/libnet_conf.c b/source3/libnet/libnet_conf.c
new file mode 100644
index 0000000000..f394e02e20
--- /dev/null
+++ b/source3/libnet/libnet_conf.c
@@ -0,0 +1,149 @@
+/*
+ * Unix SMB/CIFS implementation.
+ * libnet smbconf registry Support
+ * Copyright (C) Michael Adam 2007
+ * Copyright (C) Guenther Deschner 2007
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include "includes.h"
+
+/*
+ * Open a subkey of KEY_SMBCONF (i.e a service)
+ * - variant without error output (q = quiet)-
+ */
+WERROR libnet_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;
+}
+
+/*
+ * check if a subkey of KEY_SMBCONF of a given name exists
+ */
+bool libnet_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 = libnet_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;
+}
+
+/*
+ * Open a subkey of KEY_SMBCONF (i.e a service)
+ * - variant with error output -
+ */
+WERROR libnet_smbconf_open_path(TALLOC_CTX *ctx, const char *subkeyname,
+ uint32 desired_access,
+ struct registry_key **key)
+{
+ WERROR werr = WERR_OK;
+
+ werr = libnet_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
+ */
+WERROR libnet_smbconf_open_basepath(TALLOC_CTX *ctx, uint32 desired_access,
+ struct registry_key **key)
+{
+ return libnet_smbconf_open_path(ctx, NULL, desired_access, key);
+}
+
+/*
+ * create a subkey of KEY_SMBCONF
+ */
+WERROR libnet_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 = libnet_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;
+}
+
diff --git a/source3/utils/net_conf.c b/source3/utils/net_conf.c
index 16b372ca72..c853a79249 100644
--- a/source3/utils/net_conf.c
+++ b/source3/utils/net_conf.c
@@ -26,6 +26,7 @@
#include "includes.h"
#include "utils/net.h"
+#include "libnet/libnet_proto.h"
/*
* usage functions
@@ -214,67 +215,6 @@ done:
}
/*
- * 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)
@@ -282,7 +222,7 @@ 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);
+ werr = libnet_smbconf_open_basepath(ctx, REG_KEY_WRITE, &key);
if (!W_ERROR_IS_OK(werr)) {
goto done;
}
@@ -298,72 +238,6 @@ done:
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)
{
@@ -553,13 +427,13 @@ static int import_process_service(TALLOC_CTX *ctx,
if (opt_testmode) {
d_printf("[%s]\n", servicename);
} else {
- if (smbconf_key_exists(tmp_ctx, servicename)) {
+ if (libnet_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);
+ werr = libnet_reg_createkey_internal(tmp_ctx, servicename, &key);
if (!W_ERROR_IS_OK(werr)) {
goto done;
}
@@ -632,12 +506,12 @@ int net_conf_list(int argc, const char **argv)
goto done;
}
- werr = smbconf_open_basepath(ctx, REG_KEY_READ, &base_key);
+ werr = libnet_smbconf_open_basepath(ctx, REG_KEY_READ, &base_key);
if (!W_ERROR_IS_OK(werr)) {
goto done;
}
- if (smbconf_key_exists(ctx, GLOBAL_NAME)) {
+ if (libnet_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)) {
@@ -790,7 +664,7 @@ int net_conf_listshares(int argc, const char **argv)
goto done;
}
- werr = smbconf_open_basepath(ctx, SEC_RIGHTS_ENUM_SUBKEYS, &key);
+ werr = libnet_smbconf_open_basepath(ctx, SEC_RIGHTS_ENUM_SUBKEYS, &key);
if (!W_ERROR_IS_OK(werr)) {
goto done;
}
@@ -852,7 +726,7 @@ int net_conf_showshare(int argc, const char **argv)
goto done;
}
- werr = smbconf_open_path(ctx, argv[0], REG_KEY_READ, &key);
+ werr = libnet_smbconf_open_path(ctx, argv[0], REG_KEY_READ, &key);
if (!W_ERROR_IS_OK(werr)) {
goto done;
}
@@ -989,7 +863,7 @@ int net_conf_addshare(int argc, const char **argv)
* create the share
*/
- werr = reg_createkey_internal(NULL, argv[0], &newkey);
+ werr = libnet_reg_createkey_internal(NULL, argv[0], &newkey);
if (!W_ERROR_IS_OK(werr)) {
goto done;
}
@@ -1060,10 +934,10 @@ static int net_conf_setparm(int argc, const char **argv)
param = strdup_lower(argv[1]);
value_str = argv[2];
- if (!smbconf_key_exists(ctx, service)) {
- werr = reg_createkey_internal(ctx, service, &key);
+ if (!libnet_smbconf_key_exists(ctx, service)) {
+ werr = libnet_reg_createkey_internal(ctx, service, &key);
} else {
- werr = smbconf_open_path(ctx, service, REG_KEY_READ, &key);
+ werr = libnet_smbconf_open_path(ctx, service, REG_KEY_WRITE, &key);
}
if (!W_ERROR_IS_OK(werr)) {
goto done;
@@ -1104,14 +978,14 @@ static int net_conf_getparm(int argc, const char **argv)
service = strdup_lower(argv[0]);
param = strdup_lower(argv[1]);
- if (!smbconf_key_exists(ctx, service)) {
+ if (!libnet_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);
+ werr = libnet_smbconf_open_path(ctx, service, REG_KEY_READ, &key);
if (!W_ERROR_IS_OK(werr)) {
goto done;
}
@@ -1151,14 +1025,14 @@ static int net_conf_delparm(int argc, const char **argv)
service = strdup_lower(argv[0]);
param = strdup_lower(argv[1]);
- if (!smbconf_key_exists(ctx, service)) {
+ if (!libnet_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);
+ werr = libnet_smbconf_open_path(ctx, service, REG_KEY_READ, &key);
if (!W_ERROR_IS_OK(werr)) {
goto done;
}