mirror of
https://github.com/samba-team/samba.git
synced 2024-12-22 13:34:15 +03:00
libcli:smb: Add smb_encryption_setting_translate()
Add encryption enum and function to avoid confusion when reading the code. Signed-off-by: Andreas Schneider <asn@samba.org> Reviewed-by: Stefan Metzmacher <metze@samba.org>
This commit is contained in:
parent
e524719010
commit
4bf8a66731
@ -51,5 +51,6 @@ NTSTATUS smb_bytes_pull_str(TALLOC_CTX *mem_ctx, char **_str, bool ucs2,
|
||||
size_t *_consumed);
|
||||
|
||||
enum smb_signing_setting smb_signing_setting_translate(const char *str);
|
||||
enum smb_encryption_setting smb_encryption_setting_translate(const char *str);
|
||||
|
||||
#endif /* _SMB_UTIL_H */
|
||||
|
@ -46,11 +46,30 @@ static void test_smb_signing_setting_translate(void **state)
|
||||
|
||||
}
|
||||
|
||||
static void test_smb_encryption_setting_translate(void **state)
|
||||
{
|
||||
enum smb_encryption_setting encryption_state;
|
||||
|
||||
encryption_state = smb_encryption_setting_translate("wurst");
|
||||
assert_int_equal(encryption_state, SMB_ENCRYPTION_REQUIRED);
|
||||
|
||||
encryption_state = smb_encryption_setting_translate("off");
|
||||
assert_int_equal(encryption_state, SMB_ENCRYPTION_OFF);
|
||||
|
||||
encryption_state = smb_encryption_setting_translate("if_required");
|
||||
assert_int_equal(encryption_state, SMB_ENCRYPTION_IF_REQUIRED);
|
||||
|
||||
encryption_state = smb_encryption_setting_translate("mandatory");
|
||||
assert_int_equal(encryption_state, SMB_ENCRYPTION_REQUIRED);
|
||||
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
int rc;
|
||||
const struct CMUnitTest tests[] = {
|
||||
cmocka_unit_test(test_smb_signing_setting_translate),
|
||||
cmocka_unit_test(test_smb_encryption_setting_translate),
|
||||
};
|
||||
|
||||
if (argc == 2) {
|
||||
|
@ -448,3 +448,23 @@ enum smb_signing_setting smb_signing_setting_translate(const char *str)
|
||||
|
||||
return signing_state;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Translate SMB encryption settings as string to an enum.
|
||||
*
|
||||
* @param[in] str The string to translate.
|
||||
*
|
||||
* @return A corresponding enum @smb_encryption_setting tranlated from the
|
||||
* string.
|
||||
*/
|
||||
enum smb_encryption_setting smb_encryption_setting_translate(const char *str)
|
||||
{
|
||||
enum smb_encryption_setting encryption_state = SMB_ENCRYPTION_REQUIRED;
|
||||
int32_t val = lpcfg_parse_enum_vals("client smb encrypt", str);
|
||||
|
||||
if (val != INT32_MIN) {
|
||||
encryption_state = val;
|
||||
}
|
||||
|
||||
return encryption_state;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user