]> eyrie.org Git - kerberos/wallet.git/commitdiff
Update handling of long host names
authorBill MacAllister <whm@dropbox.com>
Wed, 1 Jun 2016 18:48:31 +0000 (18:48 +0000)
committerRuss Allbery <eagle@eyrie.org>
Mon, 28 May 2018 00:33:31 +0000 (17:33 -0700)
perl/lib/Wallet/Config.pm
perl/lib/Wallet/Kadmin/AD.pm

index 5d40978ef15e048e72a569bd5222a1ed4198cb9e..09db609abcfac50c2e2cfe118d79b1e72c0b8299 100644 (file)
@@ -463,10 +463,22 @@ default PATH.
 
 our $AD_MSKTUTIL = 'msktutil';
 
+=item AD_SERVICE_LENGTH
+
+The maximum length of a unique identifier, samAccountName, for Active
+Directory keytab objects.  If the indentifier exceeds this length then
+it will be trunciated and an integer will be appended to the end of
+the identifier.  This parameter is here in hopes that at some point
+in the future Microsoft will remove the limitation.
+
+=cut
+
+our $AD_SERVICE_LENGTH = '20';
+
 =item AD_SERVICE_LIMIT
 
 Used to limit the number of iterations used in attempting to find a
-unique account name for service principals.  Defaults to 999.
+unique account name for principals.  Defaults to 999.
 
 =cut
 
index 9749a2ac605079736595c88091653c464b98e40f..a59914221add91474af6e526f22a9b4eeaf0915e 100644 (file)
@@ -272,15 +272,21 @@ sub get_account_id {
         $this_id =~ s/.*?=//xms;
     } else {
         my ($this_type, $this_cn) = split '/', $this_princ, 2;
-        if ($Wallet::Config::AD_SERVICE_PREFIX && $this_type = 'service') {
-            $this_cn = $Wallet::Config::AD_SERVICE_PREFIX . $this_cn;
+        my $max_len;
+        if ($this_type eq 'host') {
+            $max_len = $Wallet::Config::AD_SERVICE_LENGTH - 1;
+        } else {
+            $max_len = $Wallet::Config::AD_SERVICE_LENGTH;
+            if ($Wallet::Config::AD_SERVICE_PREFIX) {
+                $this_cn = $Wallet::Config::AD_SERVICE_PREFIX . $this_cn;
+            }
         }
         my $loop_limit = $Wallet::Config::AD_SERVICE_LIMIT;
-        if (length($this_cn)>20) {
+        if (length($this_cn)>$max_len) {
             my $cnt = 0;
             my $this_dn;
             my $suffix_size = length("$loop_limit");
-            my $this_prefix = substr($this_cn, 0, 20-$suffix_size);
+            my $this_prefix = substr($this_cn, 0, $max_len - $suffix_size);
             my $this_format = "%0${suffix_size}i";
             while ($cnt<$loop_limit) {
                 $this_cn = $this_prefix . sprintf($this_format, $cnt);