diff options
author | Simon Rettberg | 2016-05-20 18:02:23 +0200 |
---|---|---|
committer | Simon Rettberg | 2016-05-20 18:02:23 +0200 |
commit | 684d5ca47788eed4bdd8fa30a29b9979acb1f4b4 (patch) | |
tree | 4259b9ede9880a60007a43f9f6dd6eba46ff454b /src/main/java/org/openslx/taskmanager/tasks/LdapSearch.java | |
parent | [ipxe] Also create usb image (diff) | |
download | tmlite-bwlp-684d5ca47788eed4bdd8fa30a29b9979acb1f4b4.tar.gz tmlite-bwlp-684d5ca47788eed4bdd8fa30a29b9979acb1f4b4.tar.xz tmlite-bwlp-684d5ca47788eed4bdd8fa30a29b9979acb1f4b4.zip |
[ldap/ad] Support home directory remapping options
Diffstat (limited to 'src/main/java/org/openslx/taskmanager/tasks/LdapSearch.java')
-rw-r--r-- | src/main/java/org/openslx/taskmanager/tasks/LdapSearch.java | 75 |
1 files changed, 55 insertions, 20 deletions
diff --git a/src/main/java/org/openslx/taskmanager/tasks/LdapSearch.java b/src/main/java/org/openslx/taskmanager/tasks/LdapSearch.java index a2b9f57..3ad8957 100644 --- a/src/main/java/org/openslx/taskmanager/tasks/LdapSearch.java +++ b/src/main/java/org/openslx/taskmanager/tasks/LdapSearch.java @@ -4,6 +4,7 @@ import java.io.File; import java.io.IOException; import java.nio.charset.StandardCharsets; import java.util.ArrayList; +import java.util.List; import java.util.Random; import org.apache.commons.io.FileUtils; @@ -14,7 +15,7 @@ import com.google.gson.annotations.Expose; public class LdapSearch extends SystemCommandTask { - + private static final Logger LOGGER = Logger.getLogger( LdapSearch.class ); @Expose @@ -26,9 +27,9 @@ public class LdapSearch extends SystemCommandTask @Expose private String bindpw = null; @Expose - private String username = null; - @Expose private boolean plainldap = false; + @Expose + private String filter = null; private String fifo = null; @@ -73,20 +74,17 @@ public class LdapSearch extends SystemCommandTask return null; } } - if ( this.username == null ) { + String filter; + if ( this.filter == null ) { status.addMessage( "Trying to find 4 random AD users to verify everything is all right..." ); - this.username = "*"; + if ( this.plainldap ) { + filter = "(&(objectClass=posixAccount)(uid=*))"; + } else { + filter = "(&(objectClass=user)(objectClass=person)(sAMAccountName=*))"; + } } else { this.getDn = true; - } - String filter; - String wantedAttr; - if ( this.plainldap ) { - filter = "(&(objectClass=posixAccount)(uid=" + this.username + "))"; - wantedAttr = "uid"; - } else { - filter = "(&(objectClass=user)(objectClass=person)(sAMAccountName=" + this.username + "))"; - wantedAttr = "sAMAccountName"; + filter = this.filter; } // As we don't care about the certificate here, you might want to put TLS_REQCERT never @@ -103,9 +101,7 @@ public class LdapSearch extends SystemCommandTask "-o", "nettimeout=4", "-z", "4", // Max number of results "-o", "ldif-wrap=no", // Turn off retarded line wrapping done by ldapsearch - filter, - wantedAttr, // Find account name - "dn" // And dn + filter }; } return new String[] { @@ -120,9 +116,7 @@ public class LdapSearch extends SystemCommandTask "-o", "nettimeout=4", "-z", "4", // Max number of results "-o", "ldif-wrap=no", // Turn off retarded line wrapping done by ldapsearch - filter, - wantedAttr, // Find account name - "dn" // And dn + filter }; } @@ -166,6 +160,32 @@ public class LdapSearch extends SystemCommandTask if ( line.startsWith( "dn: " ) ) { status.dn = line.substring( 4 ); } + // Figure out if we have homedir + if ( this.getDn ) { + String p[] = line.split( ": ", 2 ); + if ( p.length == 2 ) { + int score = 0; + if ( p[1].startsWith( "\\\\" ) ) { + score += 10; + } + if ( p[0].equalsIgnoreCase( "homeDirectory" ) ) { + score += 60; + } else if ( p[0].contains( "homeDirectory" ) ) { + score += 50; + } else if ( p[0].contains( "homedirectory" ) ) { + score += 40; + } else if ( p[0].contains( "home" ) ) { + score += 10; + } + if ( p[0].contains( "user" ) ) { + score += 10; + } + if ( score > 10 ) { + status.addMessage( "Potential home directory attribute: " + p[0] ); + status.home.add( new DirCandidate( p[0], p[1], score ) ); + } + } + } } @Override @@ -176,10 +196,25 @@ public class LdapSearch extends SystemCommandTask status.addMessage( "Error: " + line ); } + class DirCandidate + { + public String attr; + public String value; + public int score; + + public DirCandidate( String attr, String value, int score ) + { + this.attr = attr; + this.value = value; + this.score = score; + } + } + class Output { private String messages = null; public String dn = null; + public List<DirCandidate> home = new ArrayList<>(); private synchronized void addMessage( String str ) { |