mirror of
https://github.com/samba-team/samba.git
synced 2025-01-08 21:18:16 +03:00
param: handle smb_ports as a special handler
Avoids some problems with using str_list_make and str_list_make_v3 and tries to verify if the ports assignment is reasonable Change-Id: I441c4cca605c7548a5023b65994004fbac57d2df Signed-off-by: Garming Sam <garming@catalyst.net.nz> Reviewed-by: Andrew Bartlett <abartlet@samba.org> Reviewed-by: Nadezhda Ivanova <nivanova@samba.org>
This commit is contained in:
parent
8947af1bd2
commit
e87cb83b47
@ -233,6 +233,8 @@ static struct loadparm_service *lpcfg_getservicebyname(struct loadparm_context *
|
|||||||
const char *pszServiceName);
|
const char *pszServiceName);
|
||||||
static bool lpcfg_service_ok(struct loadparm_service *service);
|
static bool lpcfg_service_ok(struct loadparm_service *service);
|
||||||
static bool do_section(const char *pszSectionName, void *);
|
static bool do_section(const char *pszSectionName, void *);
|
||||||
|
static bool set_variable_helper(TALLOC_CTX *mem_ctx, int parmnum, void *parm_ptr,
|
||||||
|
const char *pszParmName, const char *pszParmValue);
|
||||||
|
|
||||||
/* The following are helper functions for parametrical options support. */
|
/* The following are helper functions for parametrical options support. */
|
||||||
/* It returns a pointer to parametrical option value if it exists or NULL otherwise */
|
/* It returns a pointer to parametrical option value if it exists or NULL otherwise */
|
||||||
@ -1345,6 +1347,44 @@ bool handle_idmap_gid(struct loadparm_context *lp_ctx, int snum, const char *psz
|
|||||||
return lpcfg_string_set(lp_ctx, ptr, pszParmValue);
|
return lpcfg_string_set(lp_ctx, ptr, pszParmValue);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool handle_smb_ports(struct loadparm_context *lp_ctx, int snum, const char *pszParmValue, char **ptr)
|
||||||
|
{
|
||||||
|
static int parm_num = -1;
|
||||||
|
int i;
|
||||||
|
const char **list;
|
||||||
|
|
||||||
|
if (!pszParmValue || !*pszParmValue) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (parm_num == -1) {
|
||||||
|
parm_num = lpcfg_map_parameter("smb ports");
|
||||||
|
}
|
||||||
|
|
||||||
|
if(!set_variable_helper(lp_ctx->globals->ctx, parm_num, ptr, "smb ports",
|
||||||
|
pszParmValue)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
list = lp_ctx->globals->smb_ports;
|
||||||
|
if (list == NULL) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Check that each port is a valid integer and within range */
|
||||||
|
for (i = 0; list[i] != NULL; i++) {
|
||||||
|
char *end = NULL;
|
||||||
|
int port = 0;
|
||||||
|
port = strtol(list[i], &end, 10);
|
||||||
|
if (*end != '\0' || port <= 0 || port > 65535) {
|
||||||
|
TALLOC_FREE(list);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
/***************************************************************************
|
/***************************************************************************
|
||||||
Initialise a copymap.
|
Initialise a copymap.
|
||||||
***************************************************************************/
|
***************************************************************************/
|
||||||
|
@ -1324,7 +1324,7 @@ struct parm_struct parm_table[] = {
|
|||||||
.type = P_CMDLIST,
|
.type = P_CMDLIST,
|
||||||
.p_class = P_GLOBAL,
|
.p_class = P_GLOBAL,
|
||||||
.offset = GLOBAL_VAR(smb_ports),
|
.offset = GLOBAL_VAR(smb_ports),
|
||||||
.special = NULL,
|
.special = handle_smb_ports,
|
||||||
.enum_list = NULL,
|
.enum_list = NULL,
|
||||||
.flags = FLAG_ADVANCED,
|
.flags = FLAG_ADVANCED,
|
||||||
},
|
},
|
||||||
|
@ -188,12 +188,14 @@ class SmbDotConfTests(TestCase):
|
|||||||
'registry shares',
|
'registry shares',
|
||||||
'idmap backend',
|
'idmap backend',
|
||||||
'idmap gid',
|
'idmap gid',
|
||||||
'idmap uid'])
|
'idmap uid',
|
||||||
|
'smb ports'])
|
||||||
|
|
||||||
def test_default_s4(self):
|
def test_default_s4(self):
|
||||||
self._test_default(['bin/samba-tool', 'testparm'])
|
self._test_default(['bin/samba-tool', 'testparm'])
|
||||||
self._set_defaults(['bin/samba-tool', 'testparm'])
|
self._set_defaults(['bin/samba-tool', 'testparm'])
|
||||||
self._set_arbitrary(['bin/samba-tool', 'testparm'])
|
self._set_arbitrary(['bin/samba-tool', 'testparm'],
|
||||||
|
exceptions = ['smb ports'])
|
||||||
|
|
||||||
def _test_default(self, program):
|
def _test_default(self, program):
|
||||||
topdir = os.path.abspath(samba.source_tree_topdir())
|
topdir = os.path.abspath(samba.source_tree_topdir())
|
||||||
|
Loading…
Reference in New Issue
Block a user