diff options
author | Michael Adam <obnox@samba.org> | 2007-12-31 01:56:18 +0100 |
---|---|---|
committer | Michael Adam <obnox@samba.org> | 2007-12-31 01:56:18 +0100 |
commit | 01f8fd55a7f9cb9cc90e3d2b53397412a7bad714 (patch) | |
tree | 540cb0e2367cacbb8df8d8bd8186222a9b30e221 | |
parent | e8a680cdf391255fcbdacd1dcebc0f5a947408f1 (diff) | |
download | samba-01f8fd55a7f9cb9cc90e3d2b53397412a7bad714.tar.gz samba-01f8fd55a7f9cb9cc90e3d2b53397412a7bad714.tar.bz2 samba-01f8fd55a7f9cb9cc90e3d2b53397412a7bad714.zip |
Rewrite net_conf_addshare() to only use libnet_conf API functions.
Also exit on error if the share already exists.
net_conf_addshare() is considered a high level utility function.
It should not be an libnet_conf API function in itself since it is
kind of arbitrary.
Michael
(This used to be commit af5218f1505321236be52df10ebfe8f42b99573d)
-rw-r--r-- | source3/utils/net_conf.c | 37 |
1 files changed, 17 insertions, 20 deletions
diff --git a/source3/utils/net_conf.c b/source3/utils/net_conf.c index 24257fe7cf..9e4d4300d5 100644 --- a/source3/utils/net_conf.c +++ b/source3/utils/net_conf.c @@ -506,11 +506,16 @@ done: return ret; } +/** + * Add a share, with a couple of standard parameters, partly optional. + * + * This is a high level utility function of the net conf utility, + * not a direct frontend to the libnet_conf API. + */ static 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; @@ -562,7 +567,6 @@ static int net_conf_addshare(int argc, const char **argv) net_conf_addshare_usage(argc, argv); goto done; } - case 2: path = argv[1]; sharename = strdup_lower(argv[0]); @@ -596,6 +600,12 @@ static int net_conf_addshare(int argc, const char **argv) goto done; } + if (libnet_smbconf_share_exists(sharename)) { + d_fprintf(stderr, "ERROR: share %s already exists.\n", + sharename); + goto done; + } + /* validate path */ if (path[0] != '/') { @@ -622,19 +632,10 @@ static int net_conf_addshare(int argc, const char **argv) } /* - * create the share + * create the share by adding the parameters */ - werr = libnet_smbconf_reg_createkey_internal(NULL, argv[0], &newkey); - if (!W_ERROR_IS_OK(werr)) { - d_fprintf(stderr, "Error creating share %s: %s\n", - argv[0], dos_errstr(werr)); - goto done; - } - - /* add config params as values */ - - werr = libnet_smbconf_reg_setvalue_internal(newkey, "path", path); + werr = libnet_smbconf_setparm(sharename, "path", path); if (!W_ERROR_IS_OK(werr)) { d_fprintf(stderr, "Error setting parameter %s: %s\n", "path", dos_errstr(werr)); @@ -642,8 +643,7 @@ static int net_conf_addshare(int argc, const char **argv) } if (comment != NULL) { - werr = libnet_smbconf_reg_setvalue_internal(newkey, "comment", - comment); + werr = libnet_smbconf_setparm(sharename, "comment", comment); if (!W_ERROR_IS_OK(werr)) { d_fprintf(stderr, "Error setting parameter %s: %s\n", "comment", dos_errstr(werr)); @@ -651,16 +651,14 @@ static int net_conf_addshare(int argc, const char **argv) } } - werr = libnet_smbconf_reg_setvalue_internal(newkey, "guest ok", - guest_ok); + werr = libnet_smbconf_setparm(sharename, "guest ok", guest_ok); if (!W_ERROR_IS_OK(werr)) { d_fprintf(stderr, "Error setting parameter %s: %s\n", "'guest ok'", dos_errstr(werr)); goto done; } - werr = libnet_smbconf_reg_setvalue_internal(newkey, "writeable", - writeable); + werr = libnet_smbconf_setparm(sharename, "writeable", writeable); if (!W_ERROR_IS_OK(werr)) { d_fprintf(stderr, "Error setting parameter %s: %s\n", "writeable", dos_errstr(werr)); @@ -670,7 +668,6 @@ static int net_conf_addshare(int argc, const char **argv) ret = 0; done: - TALLOC_FREE(newkey); SAFE_FREE(sharename); return ret; } |