diff mbox series

[cifs-utils,RFC,11/12] upcall-helper: add uid comparison

Message ID 20250510161609.2615639-12-sorenson@redhat.com
State New
Headers show
Series cifs.upcall helper script enabling complex key description matching | expand

Commit Message

Frank Sorenson May 10, 2025, 4:16 p.m. UTC
Use numeric comparisons for 'uid' and 'creduid' matching.

Signed-off-by: Frank Sorenson <sorenson@redhat.com>
---
 contrib/upcall-helper/cifs-upcall-helper | 14 ++++++++++++++
 1 file changed, 14 insertions(+)
diff mbox series

Patch

diff --git a/contrib/upcall-helper/cifs-upcall-helper b/contrib/upcall-helper/cifs-upcall-helper
index 91243bd..2379914 100755
--- a/contrib/upcall-helper/cifs-upcall-helper
+++ b/contrib/upcall-helper/cifs-upcall-helper
@@ -50,6 +50,7 @@  my $conf_split_re = qr/^([^\s]+)\s+(.+)/; # splitting each line of the conf file
 my $split_char = '[,;]'; # separator for match and options fields
 
 my $string_comparison_re = qr/^(host|user|sec|upcall_target)(=|==|!=|~|!~)(.+)/;
+my $uid_comparison_re = qr/^(uid|creduid)(<|<=|=|==|>=|>|!=)(0x[0-9a-f]+|[0-9]+)$/;
 
 sub log_msg {
 	my $msg_level = shift;
@@ -198,6 +199,17 @@  sub check_string_match {
 
 	return $result;
 }
+sub check_uid_match {
+	my $key_uid = shift;
+	my $comparison = shift;
+	my $comparison_uid = shift;
+
+	$comparison_uid = scalar POSIX::strtol($comparison_uid, 16) if (substr($comparison_uid, 0, 2) eq '0x');
+
+	my $comparison_string = sprintf("%d %s %d", $key_uid, $comparison, $comparison_uid);
+	return 1 if (eval $comparison_string);
+	return 0;
+}
 sub match_criterion {
 	my $criterion = shift;
 
@@ -206,6 +218,8 @@  sub match_criterion {
 	return 1 if ($criterion eq '*');  # '*' is always true
 	if (($field, $comparator, $match_pattern) = $criterion =~ $string_comparison_re) {
 		return 0 if (! check_string_match($key_vars{$field}, $comparator, $match_pattern));
+	} elsif (($field, $comparator, $match_pattern) = $criterion =~ $uid_comparison_re) {
+		return 0 if (! check_uid_match($key_vars{$field}, $comparator, $match_pattern));
 	} else {
 		log_msg 0, "unrecognized match string: $criterion";
 		return 0;