[SCM] Samba Shared Repository - branch master updated
Volker Lendecke
vlendec at samba.org
Wed Mar 10 08:07:02 UTC 2021
The branch, master has been updated
via d7e620ff41d lib/util: Replace buggy string_sub_talloc() with talloc_string_sub() in lib/util
via 5cdc065211e lib/param: Remove lpcfg_volume_label() and only caller in NTVFS file server
via 202d4d6da6a lib/param: Remove unused functions in lib/param/loadparm.c
from 26bc731212b winbindd: Apply some const to normalize_name_map()
https://git.samba.org/?p=samba.git;a=shortlog;h=master
- Log -----------------------------------------------------------------
commit d7e620ff41d6583b5554c03abaac6c4c183d5146
Author: Andrew Bartlett <abartlet at samba.org>
Date: Wed Mar 10 16:16:42 2021 +1300
lib/util: Replace buggy string_sub_talloc() with talloc_string_sub() in lib/util
BUG: https://bugzilla.samba.org/show_bug.cgi?id=14658
Signed-off-by: Andrew Bartlett <abartlet at samba.org>
Reviewed-by: Volker Lendecke <vl at samba.org>
Autobuild-User(master): Volker Lendecke <vl at samba.org>
Autobuild-Date(master): Wed Mar 10 08:06:25 UTC 2021 on sn-devel-184
commit 5cdc065211ef26f0c262751f17c3511a2dcca950
Author: Andrew Bartlett <abartlet at samba.org>
Date: Wed Mar 10 15:59:10 2021 +1300
lib/param: Remove lpcfg_volume_label() and only caller in NTVFS file server
Signed-off-by: Andrew Bartlett <abartlet at samba.org>
Reviewed-by: Volker Lendecke <vl at samba.org>
commit 202d4d6da6a1923e768799b576acf5057473a7f7
Author: Andrew Bartlett <abartlet at samba.org>
Date: Wed Mar 10 15:31:05 2021 +1300
lib/param: Remove unused functions in lib/param/loadparm.c
The lib/param code does not service smbd, no home directories nor printers are handled
in this codebase and these functions are uncalled.
BUG: https://bugzilla.samba.org/show_bug.cgi?id=14658
Signed-off-by: Andrew Bartlett <abartlet at samba.org>
Reviewed-by: Volker Lendecke <vl at samba.org>
-----------------------------------------------------------------------
Summary of changes:
lib/param/loadparm.c | 169 ------------------------------------------
lib/param/param.h | 29 --------
lib/util/substitute.c | 166 +++++++++++++++++++++++++++++------------
lib/util/substitute.h | 20 +++--
lib/util/tests/str.c | 14 ++--
source3/include/proto.h | 14 ----
source3/lib/util_str.c | 117 -----------------------------
source4/param/share.h | 1 -
source4/param/share_classic.c | 4 -
9 files changed, 138 insertions(+), 396 deletions(-)
Changeset truncated at 500 lines:
diff --git a/lib/param/loadparm.c b/lib/param/loadparm.c
index 3548c47d857..0c4c3d0f555 100644
--- a/lib/param/loadparm.c
+++ b/lib/param/loadparm.c
@@ -728,76 +728,6 @@ struct loadparm_service *lpcfg_add_service(struct loadparm_context *lp_ctx,
return lp_ctx->services[i];
}
-/**
- * Add a new home service, with the specified home directory, defaults coming
- * from service ifrom.
- */
-
-bool lpcfg_add_home(struct loadparm_context *lp_ctx,
- const char *pszHomename,
- struct loadparm_service *default_service,
- const char *user, const char *pszHomedir)
-{
- struct loadparm_service *service;
-
- service = lpcfg_add_service(lp_ctx, default_service, pszHomename);
-
- if (service == NULL)
- return false;
-
- if (!(*(default_service->path))
- || strequal(default_service->path, lp_ctx->sDefault->path)) {
- service->path = talloc_strdup(service, pszHomedir);
- } else {
- service->path = string_sub_talloc(service, lpcfg_path(default_service, lp_ctx->sDefault, service), "%H", pszHomedir);
- }
-
- if (!(*(service->comment))) {
- service->comment = talloc_asprintf(service, "Home directory of %s", user);
- }
- service->available = default_service->available;
- service->browseable = default_service->browseable;
-
- DEBUG(3, ("adding home's share [%s] for user '%s' at '%s'\n",
- pszHomename, user, service->path));
-
- return true;
-}
-
-/**
- * Add a new printer service, with defaults coming from service iFrom.
- */
-
-bool lpcfg_add_printer(struct loadparm_context *lp_ctx,
- const char *pszPrintername,
- struct loadparm_service *default_service)
-{
- const char *comment = "From Printcap";
- struct loadparm_service *service;
- service = lpcfg_add_service(lp_ctx, default_service, pszPrintername);
-
- if (service == NULL)
- return false;
-
- /* note that we do NOT default the availability flag to True - */
- /* we take it from the default service passed. This allows all */
- /* dynamic printers to be disabled by disabling the [printers] */
- /* entry (if/when the 'available' keyword is implemented!). */
-
- /* the printer name is set to the service name. */
- lpcfg_string_set(service, &service->_printername, pszPrintername);
- lpcfg_string_set(service, &service->comment, comment);
- service->browseable = default_service->browseable;
- /* Printers cannot be read_only. */
- service->read_only = false;
- /* Printer services must be printable. */
- service->printable = true;
-
- DEBUG(3, ("adding printer service %s\n", pszPrintername));
-
- return true;
-}
-
/**
* Map a parameter's string representation to something we can use.
* Returns False if the parameter string is not recognised, else TRUE.
@@ -1102,39 +1032,6 @@ fail:
}
-/*******************************************************************
- Check if a config file has changed date.
-********************************************************************/
-bool lpcfg_file_list_changed(struct loadparm_context *lp_ctx)
-{
- struct file_lists *f;
- DEBUG(6, ("lpcfg_file_list_changed()\n"));
-
- for (f = lp_ctx->file_lists; f != NULL; f = f->next) {
- char *n2;
- time_t mod_time;
-
- n2 = standard_sub_basic(lp_ctx, f->name);
-
- DEBUGADD(6, ("file %s -> %s last mod_time: %s\n",
- f->name, n2, ctime(&f->modtime)));
-
- mod_time = file_modtime(n2);
-
- if (mod_time && ((f->modtime != mod_time) || (f->subfname == NULL) || (strcmp(n2, f->subfname) != 0))) {
- DEBUGADD(6, ("file %s modified: %s\n", n2,
- ctime(&mod_time)));
- f->modtime = mod_time;
- talloc_free(f->subfname);
- f->subfname = talloc_strdup(f, n2);
- TALLOC_FREE(n2);
- return true;
- }
- TALLOC_FREE(n2);
- }
- return false;
-}
-
/*
* set the value for a P_ENUM
*/
@@ -2565,31 +2462,6 @@ void init_printer_values(struct loadparm_context *lp_ctx, TALLOC_CTX *ctx,
}
}
-/**
- * Unload unused services.
- */
-
-void lpcfg_killunused(struct loadparm_context *lp_ctx,
- struct smbsrv_connection *smb,
- bool (*snumused) (struct smbsrv_connection *, int))
-{
- int i;
-
- if (lp_ctx->s3_fns != NULL) {
- smb_panic("Cannot be used from an s3 loadparm ctx");
- }
-
- for (i = 0; i < lp_ctx->iNumServices; i++) {
- if (lp_ctx->services[i] == NULL)
- continue;
-
- if (!snumused || !snumused(smb, i)) {
- talloc_free(lp_ctx->services[i]);
- lp_ctx->services[i] = NULL;
- }
- }
-}
-
static int lpcfg_destructor(struct loadparm_context *lp_ctx)
{
@@ -3408,47 +3280,6 @@ const char *lpcfg_servicename(const struct loadparm_service *service)
return service ? lpcfg_string((const char *)service->szService) : NULL;
}
-/**
- * A useful volume label function.
- */
-const char *lpcfg_volume_label(struct loadparm_service *service, struct loadparm_service *sDefault)
-{
- const char *ret;
- ret = lpcfg_string((const char *)((service != NULL && service->volume != NULL) ?
- service->volume : sDefault->volume));
- if (!*ret)
- return lpcfg_servicename(service);
- return ret;
-}
-
-/**
- * Return the correct printer name.
- */
-const char *lpcfg_printername(struct loadparm_service *service, struct loadparm_service *sDefault)
-{
- const char *ret;
- ret = lpcfg_string((const char *)((service != NULL && service->_printername != NULL) ?
- service->_printername : sDefault->_printername));
- if (ret == NULL || (ret != NULL && *ret == '\0'))
- ret = lpcfg_servicename(service);
-
- return ret;
-}
-
-
-/**
- * Return the max print jobs per queue.
- */
-int lpcfg_maxprintjobs(struct loadparm_service *service, struct loadparm_service *sDefault)
-{
- int maxjobs = lpcfg_max_print_jobs(service, sDefault);
-
- if (maxjobs <= 0 || maxjobs >= PRINT_MAX_JOBID)
- maxjobs = PRINT_MAX_JOBID - 1;
-
- return maxjobs;
-}
-
struct smb_iconv_handle *lpcfg_iconv_handle(struct loadparm_context *lp_ctx)
{
if (lp_ctx == NULL) {
diff --git a/lib/param/param.h b/lib/param/param.h
index f7204c5702d..07b387a8108 100644
--- a/lib/param/param.h
+++ b/lib/param/param.h
@@ -116,18 +116,10 @@ bool lpcfg_parm_bool(struct loadparm_context *lp_ctx,
struct loadparm_service *lpcfg_add_service(struct loadparm_context *lp_ctx,
const struct loadparm_service *pservice,
const char *name);
-bool lpcfg_add_home(struct loadparm_context *lp_ctx,
- const char *pszHomename,
- struct loadparm_service *default_service,
- const char *user, const char *pszHomedir);
-bool lpcfg_add_printer(struct loadparm_context *lp_ctx,
- const char *pszPrintername,
- struct loadparm_service *default_service);
struct parm_struct *lpcfg_parm_struct(struct loadparm_context *lp_ctx, const char *name);
void *lpcfg_parm_ptr(struct loadparm_context *lp_ctx,
struct loadparm_service *service, struct parm_struct *parm);
bool lpcfg_parm_is_cmdline(struct loadparm_context *lp_ctx, const char *name);
-bool lpcfg_file_list_changed(struct loadparm_context *lp_ctx);
bool lpcfg_do_global_parameter(struct loadparm_context *lp_ctx,
const char *pszParmName, const char *pszParmValue);
@@ -151,13 +143,6 @@ bool lpcfg_dump_a_parameter(struct loadparm_context *lp_ctx,
struct loadparm_service *service,
const char *parm_name, FILE * f);
-/**
- * Unload unused services.
- */
-void lpcfg_killunused(struct loadparm_context *lp_ctx,
- struct smbsrv_connection *smb,
- bool (*snumused) (struct smbsrv_connection *, int));
-
/**
* Initialise the global parameter structure.
*/
@@ -194,20 +179,6 @@ struct loadparm_service *lpcfg_servicebynum(struct loadparm_context *lp_ctx,
struct loadparm_service *lpcfg_service(struct loadparm_context *lp_ctx,
const char *service_name);
-/**
- * A useful volume label function.
- */
-const char *lp_cfg_volume_label(struct loadparm_service *service, struct loadparm_service *sDefault);
-
-/**
- * If we are PDC then prefer us as DMB
- */
-const char *lpcfg_printername(struct loadparm_service *service, struct loadparm_service *sDefault);
-
-/**
- * Return the max print jobs per queue.
- */
-int lpcfg_maxprintjobs(struct loadparm_service *service, struct loadparm_service *sDefault);
struct smb_iconv_handle *lpcfg_iconv_handle(struct loadparm_context *lp_ctx);
void lpcfg_smbcli_options(struct loadparm_context *lp_ctx,
struct smbcli_options *options);
diff --git a/lib/util/substitute.c b/lib/util/substitute.c
index 2d88e97fd19..3ca53d912c4 100644
--- a/lib/util/substitute.c
+++ b/lib/util/substitute.c
@@ -113,60 +113,11 @@ static void string_sub2(char *s,const char *pattern, const char *insert, size_t
}
}
-void string_sub_once(char *s, const char *pattern,
- const char *insert, size_t len)
-{
- string_sub2( s, pattern, insert, len, true, true, false );
-}
-
void string_sub(char *s,const char *pattern, const char *insert, size_t len)
{
string_sub2( s, pattern, insert, len, true, false, false );
}
-/**
- * Talloc'ed version of string_sub
- */
-_PUBLIC_ char *string_sub_talloc(TALLOC_CTX *mem_ctx, const char *s,
- const char *pattern, const char *insert)
-{
- const char *p;
- char *ret;
- size_t len, alloc_len;
-
- if (insert == NULL || pattern == NULL || !*pattern || s == NULL)
- return NULL;
-
- /* determine length needed */
- len = strlen(s);
-
- for (p = strstr(s, pattern); p != NULL;
- p = strstr(p+strlen(pattern), pattern)) {
- len += strlen(insert) - strlen(pattern);
- }
-
- alloc_len = MAX(len, strlen(s))+1;
- ret = talloc_array(mem_ctx, char, alloc_len);
- if (ret == NULL)
- return NULL;
- strncpy(ret, s, alloc_len);
- string_sub(ret, pattern, insert, alloc_len);
-
- ret = talloc_realloc(mem_ctx, ret, char, len+1);
- if (ret == NULL)
- return NULL;
-
- if (ret[len] != '\0') {
- DEBUG(0,("Internal error at %s(%d): string not terminated\n",
- __FILE__, __LINE__));
- abort();
- }
-
- talloc_set_name_const(ret, ret);
-
- return ret;
-}
-
/**
Similar to string_sub() but allows for any character to be substituted.
Use with caution!
@@ -209,3 +160,120 @@ _PUBLIC_ void all_string_sub(char *s,const char *pattern,const char *insert, siz
ls = ls + li - lp;
}
}
+
+/*
+ * Internal guts of talloc_string_sub and talloc_all_string_sub.
+ * talloc version of string_sub2.
+ */
+
+char *talloc_string_sub2(TALLOC_CTX *mem_ctx, const char *src,
+ const char *pattern,
+ const char *insert,
+ bool remove_unsafe_characters,
+ bool replace_once,
+ bool allow_trailing_dollar)
+{
+ char *p, *in;
+ char *s;
+ char *string;
+ ssize_t ls,lp,li,ld, i;
+
+ if (!insert || !pattern || !*pattern || !src) {
+ return NULL;
+ }
+
+ string = talloc_strdup(mem_ctx, src);
+ if (string == NULL) {
+ DEBUG(0, ("talloc_string_sub2: "
+ "talloc_strdup failed\n"));
+ return NULL;
+ }
+
+ s = string;
+
+ in = talloc_strdup(mem_ctx, insert);
+ if (!in) {
+ DEBUG(0, ("talloc_string_sub2: ENOMEM\n"));
+ return NULL;
+ }
+ ls = (ssize_t)strlen(s);
+ lp = (ssize_t)strlen(pattern);
+ li = (ssize_t)strlen(insert);
+ ld = li - lp;
+
+ for (i=0;i<li;i++) {
+ switch (in[i]) {
+ case '$':
+ /* allow a trailing $
+ * (as in machine accounts) */
+ if (allow_trailing_dollar && (i == li - 1 )) {
+ break;
+ }
+
+ FALL_THROUGH;
+ case '`':
+ case '"':
+ case '\'':
+ case ';':
+ case '%':
+ case '\r':
+ case '\n':
+ if (remove_unsafe_characters) {
+ in[i] = '_';
+ break;
+ }
+
+ FALL_THROUGH;
+ default:
+ /* ok */
+ break;
+ }
+ }
+
+ while ((p = strstr_m(s,pattern))) {
+ if (ld > 0) {
+ int offset = PTR_DIFF(s,string);
+ string = (char *)talloc_realloc_size(mem_ctx, string,
+ ls + ld + 1);
+ if (!string) {
+ DEBUG(0, ("talloc_string_sub: out of "
+ "memory!\n"));
+ TALLOC_FREE(in);
+ return NULL;
+ }
+ p = string + offset + (p - s);
+ }
+ if (li != lp) {
+ memmove(p+li,p+lp,strlen(p+lp)+1);
+ }
+ memcpy(p, in, li);
+ s = p + li;
+ ls += ld;
+
+ if (replace_once) {
+ break;
+ }
+ }
+ TALLOC_FREE(in);
+ return string;
+}
+
+/* Same as string_sub, but returns a talloc'ed string */
+
+char *talloc_string_sub(TALLOC_CTX *mem_ctx,
+ const char *src,
+ const char *pattern,
+ const char *insert)
+{
+ return talloc_string_sub2(mem_ctx, src, pattern, insert,
+ true, false, false);
+}
+
+char *talloc_all_string_sub(TALLOC_CTX *ctx,
+ const char *src,
+ const char *pattern,
+ const char *insert)
+{
+ return talloc_string_sub2(ctx, src, pattern, insert,
+ false, false, false);
+}
diff --git a/lib/util/substitute.h b/lib/util/substitute.h
index 5ba469c52ba..3134cfcdea5 100644
--- a/lib/util/substitute.h
+++ b/lib/util/substitute.h
@@ -39,12 +39,6 @@
**/
void string_sub(char *s,const char *pattern, const char *insert, size_t len);
-void string_sub_once(char *s, const char *pattern,
- const char *insert, size_t len);
-
-char *string_sub_talloc(TALLOC_CTX *mem_ctx, const char *s,
- const char *pattern, const char *insert);
-
/**
Similar to string_sub() but allows for any character to be substituted.
Use with caution!
@@ -53,4 +47,18 @@ char *string_sub_talloc(TALLOC_CTX *mem_ctx, const char *s,
**/
void all_string_sub(char *s,const char *pattern,const char *insert, size_t len);
+char *talloc_string_sub2(TALLOC_CTX *mem_ctx, const char *src,
+ const char *pattern,
+ const char *insert,
+ bool remove_unsafe_characters,
+ bool replace_once,
+ bool allow_trailing_dollar);
+char *talloc_string_sub(TALLOC_CTX *mem_ctx,
+ const char *src,
+ const char *pattern,
+ const char *insert);
+char *talloc_all_string_sub(TALLOC_CTX *ctx,
+ const char *src,
+ const char *pattern,
+ const char *insert);
#endif /* _SAMBA_SUBSTITUTE_H_ */
diff --git a/lib/util/tests/str.c b/lib/util/tests/str.c
index 6c234738ead..93bf809f385 100644
--- a/lib/util/tests/str.c
+++ b/lib/util/tests/str.c
@@ -68,22 +68,22 @@ static bool test_string_sub_special_char(struct torture_context *tctx)
return true;
}
-static bool test_string_sub_talloc_simple(struct torture_context *tctx)
+static bool test_talloc_string_sub_simple(struct torture_context *tctx)
{
char *t;
- t = string_sub_talloc(tctx, "foobla", "foo", "bl");
+ t = talloc_string_sub(tctx, "foobla", "foo", "bl");
torture_assert_str_equal(tctx, t, "blbla", "invalid sub");
return true;
--
Samba Shared Repository
More information about the samba-cvs
mailing list