summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVolker Lendecke <vl@samba.org>2015-08-18 13:18:33 +0200
committerStefan Metzmacher <metze@samba.org>2015-08-31 10:18:16 +0200
commitef97c16c6729e3bc516c6719580f964dde1fa298 (patch)
treed1d600e4b4ed098b44e09d8b3ad7471c452c50a3
parentf484b247068f6e120984b7fec6f6f641040f3c04 (diff)
downloadsamba-ef97c16c6729e3bc516c6719580f964dde1fa298.tar.gz
loadparm3: Add lp_wi_scan_global_parametrics()
This routine takes a regex and goes through all parametric parameters in [global], matching the regex. It can easily be extended to also look at shares, but right now it will only be used to list all idmap config domain names. Signed-off-by: Volker Lendecke <vl@samba.org> Reviewed-by: Stefan Metzmacher <metze@samba.org> Bug: https://bugzilla.samba.org/show_bug.cgi?id=11464 (cherry picked from commit 443dd9bbbc641ede10a2a3708465f61ea3dfbde3)
-rw-r--r--source3/include/proto.h9
-rw-r--r--source3/param/loadparm.c73
2 files changed, 82 insertions, 0 deletions
diff --git a/source3/include/proto.h b/source3/include/proto.h
index 0858289ad9f..b8f4a670da0 100644
--- a/source3/include/proto.h
+++ b/source3/include/proto.h
@@ -23,6 +23,9 @@
#ifndef _PROTO_H_
#define _PROTO_H_
+#include <sys/types.h>
+#include <regex.h>
+
/* The following definitions come from lib/access.c */
bool client_match(const char *tok, const void *item);
@@ -986,6 +989,12 @@ int lp_smb2_max_credits(void);
int lp_cups_encrypt(void);
bool lp_widelinks(int );
+int lp_wi_scan_global_parametrics(
+ const char *regex, size_t max_matches,
+ bool (*cb)(const char *string, regmatch_t matches[],
+ void *private_data),
+ void *private_data);
+
char *lp_parm_talloc_string(TALLOC_CTX *ctx, int snum, const char *type, const char *option, const char *def);
const char *lp_parm_const_string(int snum, const char *type, const char *option, const char *def);
struct loadparm_service;
diff --git a/source3/param/loadparm.c b/source3/param/loadparm.c
index beba137aacf..2f53a745de6 100644
--- a/source3/param/loadparm.c
+++ b/source3/param/loadparm.c
@@ -1099,6 +1099,79 @@ static struct parmlist_entry *get_parametrics(int snum, const char *type,
}
}
+static void discard_whitespace(char *str)
+{
+ size_t len = strlen(str);
+ size_t i = 0;
+
+ while (i < len) {
+ if (isspace(str[i])) {
+ memmove(&str[i], &str[i+1], len-i);
+ len -= 1;
+ continue;
+ }
+ i += 1;
+ }
+}
+
+/**
+ * @brief Go through all global parametric parameters
+ *
+ * @param regex_str A regular expression to scan param for
+ * @param max_matches Max number of submatches the regexp expects
+ * @param cb Function to call on match. Should return true
+ * when it wants wi_scan_global_parametrics to stop
+ * scanning
+ * @param private_data Anonymous pointer passed to cb
+ *
+ * @return 0: success, regcomp/regexec return value on error.
+ * See "man regexec" for possible errors
+ */
+
+int lp_wi_scan_global_parametrics(
+ const char *regex_str, size_t max_matches,
+ bool (*cb)(const char *string, regmatch_t matches[],
+ void *private_data),
+ void *private_data)
+{
+ struct parmlist_entry *data;
+ regex_t regex;
+ int ret;
+
+ ret = regcomp(&regex, regex_str, REG_ICASE);
+ if (ret != 0) {
+ return ret;
+ }
+
+ for (data = Globals.param_opt; data != NULL; data = data->next) {
+ size_t keylen = strlen(data->key);
+ char key[keylen+1];
+ regmatch_t matches[max_matches];
+ bool stop;
+
+ memcpy(key, data->key, sizeof(key));
+ discard_whitespace(key);
+
+ ret = regexec(&regex, key, max_matches, matches, 0);
+ if (ret == REG_NOMATCH) {
+ continue;
+ }
+ if (ret != 0) {
+ goto fail;
+ }
+
+ stop = cb(key, matches, private_data);
+ if (stop) {
+ break;
+ }
+ }
+
+ ret = 0;
+fail:
+ regfree(&regex);
+ return ret;
+}
+
#define MISSING_PARAMETER(name) \
DEBUG(0, ("%s(): value is NULL or empty!\n", #name))