mirror of
https://github.com/samba-team/samba.git
synced 2025-03-20 22:50:26 +03:00
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)
This commit is contained in:
parent
f484b24706
commit
ef97c16c67
@ -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;
|
||||
|
@ -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(®ex, 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(®ex, 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(®ex);
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
#define MISSING_PARAMETER(name) \
|
||||
DEBUG(0, ("%s(): value is NULL or empty!\n", #name))
|
||||
|
Loading…
x
Reference in New Issue
Block a user