diff mbox series

[cifs-utils,RFC,06/12] upcall-helper: set upcall_opts on a match, or if 'default' is given

Message ID 20250510161609.2615639-7-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
When all criteria match, or if 'default' is specified, set
upcall_opts using the options field of the conf file line.

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

Patch

diff --git a/contrib/upcall-helper/cifs-upcall-helper b/contrib/upcall-helper/cifs-upcall-helper
index d1d7436..8929bd6 100755
--- a/contrib/upcall-helper/cifs-upcall-helper
+++ b/contrib/upcall-helper/cifs-upcall-helper
@@ -34,6 +34,7 @@  my $log_level = 0;
 # 2 - verbose debugging (LOG_INFO)
 
 my $helper_conf = '/etc/cifs-upcall-helper.conf';
+my %upcall_opts = ();
 my $keyid;
 my %key_vars;
 
@@ -109,6 +110,32 @@  sub parse_key_description {
 		$key_vars{'sec'}, $key_vars{'uid'}, $key_vars{'creduid'},
 		$key_vars{'user'}, $key_vars{'upcall_target'});
 }
+sub set_upcall_opts {
+	my $opts_str = shift;
+
+	my @opts = split /$split_char/, $opts_str;
+	foreach my $opt (@opts) {
+		if ((my $field, my $val) = $opt =~ /^([^=]+)=(.+)$/) {
+			if ($field eq 'keytab' or $field eq 'krb5conf' or $field eq 'krb5_trace') {
+				$upcall_opts{$field} = $val;
+			} else {
+				log_msg 0, "unrecognized upcall option: $opt";
+			}
+		} elsif ($opt eq 'use_proxy' or $opt eq 'use-proxy') {
+			$upcall_opts{'use_proxy'} = 1;
+		} elsif ($opt eq 'legacy_uid' or $opt eq 'legacy-uid') {
+			$upcall_opts{'legacy_uid'} = 1;
+		} elsif ($opt eq 'trust_dns' or $opt eq 'trust-dns') {
+			$upcall_opts{'trust_dns'} = 1;
+		} elsif ($opt eq 'no_env_probe' or $opt eq 'no-env-probe') {
+			$upcall_opts{'no_env_probe'} = 1;
+		} elsif ($opt eq '*' or $opt eq '-') {
+		} else {
+			log_msg 0, "unrecognized upcall option: $opt";
+		}
+	}
+}
+
 sub match_criterion {
 	my $criterion = shift;
 
@@ -132,8 +159,15 @@  sub parse_conf_line {
 	}
 	my ($criteria_str, $opts_str) = $line =~ $conf_split_re;
 
+	if ($criteria_str eq 'default' or $criteria_str eq 'defaults') {
+		%upcall_opts = (); # clear defaults
+		log_msg 1, "setting default options '$opts_str'";
+		set_upcall_opts $opts_str;
+		return;
+	}
 	if (match_criteria($criteria_str)) {
 		log_msg 1, "matched '$criteria_str'; options '$opts_str'";
+		set_upcall_opts $opts_str; # similar to defaults, but don't clear first
 		exec_upcall;
 	}
 }