Skip to content

Commit

Permalink
Precision FSP detection update (optional)
Browse files Browse the repository at this point in the history
  • Loading branch information
ondrejv2 committed Sep 17, 2024
1 parent 10348f7 commit 0b82f8e
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 6 deletions.
6 changes: 3 additions & 3 deletions src/lib/idmap/sss_idmap.c
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ const char *idmap_error_string(enum idmap_error_code err)
}
}

bool is_domain_sid(const char *sid)
bool is_str_sid(const char *sid, int count)

Check warning on line 204 in src/lib/idmap/sss_idmap.c

View workflow job for this annotation

GitHub Actions / cppcheck

The function 'is_str_sid' is never used.
{
const char *p;
long long a;
Expand All @@ -228,9 +228,9 @@ bool is_domain_sid(const char *sid)
return false;
}
c++;
} while(c < 3 && *endptr != '\0');
} while(c < count && *endptr != '\0');

if (c != 3 || *endptr != '\0') {
if (c != count || *endptr != '\0') {
return false;
}

Expand Down
2 changes: 1 addition & 1 deletion src/lib/idmap/sss_idmap.exports
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ SSS_IDMAP_0.4 {
sss_idmap_free_smb_sid;
sss_idmap_free_bin_sid;
idmap_error_string;
is_domain_sid;
is_str_sid;
sss_idmap_domain_has_algorithmic_mapping;
sss_idmap_domain_by_name_has_algorithmic_mapping;
sss_idmap_bin_sid_to_dom_sid;
Expand Down
22 changes: 21 additions & 1 deletion src/lib/idmap/sss_idmap.h
Original file line number Diff line number Diff line change
Expand Up @@ -695,6 +695,8 @@ enum idmap_error_code sss_idmap_free_bin_sid(struct sss_idmap_ctx *ctx,
*/
const char *idmap_error_string(enum idmap_error_code err);

bool is_str_sid(const char *str, int count);

/**
* @brief Check if given string can be used as domain SID
*
Expand All @@ -704,7 +706,25 @@ const char *idmap_error_string(enum idmap_error_code err);
* - true: String can be used as domain SID
* - false: String can not be used as domain SID
*/
bool is_domain_sid(const char *str);
static inline bool is_domain_sid(const char *str)
{
return is_str_sid(str, 3);
}

/**
* @brief Check if given string can be used as principal SID
*
* @param[in] str String to check
*
* @return
* - true: String can be used as principal SID
* - false: String can not be used as principal SID
*/
static inline bool is_principal_sid(const char *str)
{
return is_str_sid(str, 4);
}


/**
* @brief Check if a domain is configured with algorithmic mapping
Expand Down
13 changes: 12 additions & 1 deletion src/providers/ldap/sdap_async_nested_groups.c
Original file line number Diff line number Diff line change
Expand Up @@ -553,12 +553,23 @@ sdap_nested_member_is_fsp(struct sdap_nested_group_ctx *group_ctx,
fspdn_len = strlen(fspdn);
dn_len = strlen(dn);
len_diff = dn_len - fspdn_len;
if (len_diff < 0) {
if (len_diff < 5) {
talloc_free(fspdn);
return false;
}
ret = strncasecmp(&dn[len_diff], fspdn, fspdn_len) == 0;
talloc_free(fspdn);

if (ret) { /* looks like FSP, so just double check to be 100% sure */
char *fsp_str = talloc_strdup(group_ctx, dn);

if (fsp_str == NULL)
return false;
fsp_str[len_diff - 1] = '\0'; /* replace comma with NULL */
ret = is_principal_sid(&fsp_str[3]);
talloc_free(fsp_str);
}

return ret;
}

Expand Down

0 comments on commit 0b82f8e

Please sign in to comment.