mirror of
https://github.com/samba-team/samba.git
synced 2025-01-08 21:18:16 +03:00
libcli:smb: Add smb_signing_setting_translate()
Signed-off-by: Andreas Schneider <asn@samba.org> Reviewed-by: Stefan Metzmacher <metze@samba.org>
This commit is contained in:
parent
93e97d5afd
commit
e524719010
@ -24,6 +24,9 @@
|
||||
#include "smb_constants.h"
|
||||
#include <talloc.h>
|
||||
|
||||
#ifndef _SMB_UTIL_H
|
||||
#define _SMB_UTIL_H
|
||||
|
||||
const char *smb_protocol_types_string(enum protocol_types protocol);
|
||||
char *attrib_string(TALLOC_CTX *mem_ctx, uint32_t attrib);
|
||||
uint32_t unix_perms_to_wire(mode_t perms);
|
||||
@ -46,3 +49,7 @@ NTSTATUS smb_bytes_pull_str(TALLOC_CTX *mem_ctx, char **_str, bool ucs2,
|
||||
const uint8_t *buf, size_t buf_len,
|
||||
const uint8_t *position,
|
||||
size_t *_consumed);
|
||||
|
||||
enum smb_signing_setting smb_signing_setting_translate(const char *str);
|
||||
|
||||
#endif /* _SMB_UTIL_H */
|
||||
|
64
libcli/smb/test_util_translate.c
Normal file
64
libcli/smb/test_util_translate.c
Normal file
@ -0,0 +1,64 @@
|
||||
/*
|
||||
* Unix SMB/CIFS implementation.
|
||||
*
|
||||
* Copyright (C) 2020 Andreas Schneider <asn@samba.org>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <stdarg.h>
|
||||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
#include <setjmp.h>
|
||||
#include <cmocka.h>
|
||||
|
||||
#include "lib/replace/replace.h"
|
||||
#include <talloc.h>
|
||||
|
||||
#include "libcli/smb/util.c"
|
||||
|
||||
static void test_smb_signing_setting_translate(void **state)
|
||||
{
|
||||
enum smb_signing_setting signing_state;
|
||||
|
||||
signing_state = smb_signing_setting_translate("wurst");
|
||||
assert_int_equal(signing_state, SMB_SIGNING_REQUIRED);
|
||||
|
||||
signing_state = smb_signing_setting_translate("off");
|
||||
assert_int_equal(signing_state, SMB_SIGNING_OFF);
|
||||
|
||||
signing_state = smb_signing_setting_translate("if_required");
|
||||
assert_int_equal(signing_state, SMB_SIGNING_IF_REQUIRED);
|
||||
|
||||
signing_state = smb_signing_setting_translate("mandatory");
|
||||
assert_int_equal(signing_state, SMB_SIGNING_REQUIRED);
|
||||
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
int rc;
|
||||
const struct CMUnitTest tests[] = {
|
||||
cmocka_unit_test(test_smb_signing_setting_translate),
|
||||
};
|
||||
|
||||
if (argc == 2) {
|
||||
cmocka_set_test_filter(argv[1]);
|
||||
}
|
||||
cmocka_set_message_output(CM_OUTPUT_SUBUNIT);
|
||||
|
||||
rc = cmocka_run_group_tests(tests, NULL, NULL);
|
||||
|
||||
return rc;
|
||||
}
|
@ -22,6 +22,7 @@
|
||||
#include "includes.h"
|
||||
#include "libcli/smb/smb_common.h"
|
||||
#include "system/filesys.h"
|
||||
#include "lib/param/loadparm.h"
|
||||
|
||||
const char *smb_protocol_types_string(enum protocol_types protocol)
|
||||
{
|
||||
@ -428,3 +429,22 @@ NTSTATUS smb_bytes_pull_str(TALLOC_CTX *mem_ctx, char **_str, bool ucs2,
|
||||
return internal_bytes_pull_str(mem_ctx, _str, ucs2, true,
|
||||
buf, buf_len, position, _consumed);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Translate SMB signing settings as string to an enum.
|
||||
*
|
||||
* @param[in] str The string to translate.
|
||||
*
|
||||
* @return A corresponding enum @smb_signing_setting tranlated from the string.
|
||||
*/
|
||||
enum smb_signing_setting smb_signing_setting_translate(const char *str)
|
||||
{
|
||||
enum smb_signing_setting signing_state = SMB_SIGNING_REQUIRED;
|
||||
int32_t val = lpcfg_parse_enum_vals("client signing", str);
|
||||
|
||||
if (val != INT32_MIN) {
|
||||
signing_state = val;
|
||||
}
|
||||
|
||||
return signing_state;
|
||||
}
|
||||
|
@ -72,3 +72,8 @@ def build(bld):
|
||||
source='test_smb1cli_session.c',
|
||||
deps='cmocka cli_smb_common',
|
||||
for_selftest=True)
|
||||
|
||||
bld.SAMBA_BINARY('test_util_translate',
|
||||
source='test_util_translate.c',
|
||||
deps='cmocka cli_smb_common',
|
||||
for_selftest=True)
|
||||
|
@ -376,6 +376,8 @@ plantestsuite("samba.unittests.lib_util_modules", "none",
|
||||
|
||||
plantestsuite("samba.unittests.smb1cli_session", "none",
|
||||
[os.path.join(bindir(), "default/libcli/smb/test_smb1cli_session")])
|
||||
plantestsuite("samba.unittests.smb_util_translate", "none",
|
||||
[os.path.join(bindir(), "default/libcli/smb/test_util_translate")])
|
||||
|
||||
plantestsuite("samba.unittests.talloc_keep_secret", "none",
|
||||
[os.path.join(bindir(), "default/lib/util/test_talloc_keep_secret")])
|
||||
|
Loading…
Reference in New Issue
Block a user