English 中文(简体)
How to identify if currently logged in user is an LDAP user in Solaris
原标题:

I want to know how to identify if the currently logged in user in Solaris is a LDAP user or local user.
Any command?
or any C Run time functions like getspname, getpwnam which returns an attribute saying it is an LDAP user or local user after user logged in?

问题回答

Ldaplist will tell you if the user has an entry in the ldap database. It doesn t sort out the case where the user has also an entry in the /etc/passwd file though.

ldaplist passwd username

I am assuming that UID s that are "local" are in separate range from "LDAP". I m also assuming that nsswitch is configured to use files and ldap for passwd, shadow, and or group. The command getent should be present on GNU libc systems. I m going to assume that the local files databases are smaller than ldap source and so we will want to test the smaller and / or faster of the two sources.

if you wanted to determine if a given UID was present one of the databses you could run somthing similar to

$ getent --service=files passwd | grep 655

This could match the the default GID in the file so a more creative grep may be in order.

$ getent --service=files passwd | grep -e $.*:.*:655

If you are looking to turn this into a script-able item, then you will want to tack wc on the end to do integer testing.

$ getent --service=files passwd | grep -e $.*:.*:655 | wc -l

This should return 0 if not found, or 1 (or more) if found. We would only test one source because we are assuming that we are testing a valid UID and that it will be in the other source if its not in here.

Lastly, as long as you are using nsswitch you should be able to use any of the C Libraries that support this to check if they are valid. I don t have any first hand experience with them, but i would assume that you can pass an option like we did here to only use a specific source. Alternately you can use the same logic as above and just cat /etc/passwd. Assuming again that if they arn t in here they are in ldap.

It is not going to be easy. You can open the password file and look for them. If they aren t there, conclude LDAP. Unless, of course, it s NIS. Or Kerberos. If your version of Solaris has PAM you could read up on that to see if it has any relief to offer.

If you are using sss as part of the ipaclient package,

getent --service=sss passwd $USER | wc -l

will tell you if the user exists in the LDAP Database of the FreeIPA server.

I have no idea how to tell what credentials they used to actually authenticate, but it should be easier to just look them up in the LDAP database and see if they are there. I use the ldap_client utility to look people up all the time. You need to know the name of the ldap server, and a few other details. Check the man page for it. For example, if the user has a local account, and they are in LDAP, the passwords that get checked at login will depend on the system configuration.





相关问题
Portable way to get file size (in bytes) in the shell

On Linux, I use stat --format="%s" FILE, but the Solaris machine I have access to doesn t have the stat command. What should I use then? I m writing Bash scripts and can t really install any ...

Unix: fast remove directory for cleaning up daily builds

Is there a faster way to remove a directory then simply submitting rm -r -f *directory* ? I am asking this because our daily cross-platform builds are really huge (e.g. 4GB per build). So the ...

Startup time in Solaris server using shell script

How to find the start up time of a Solaris 5.1 server using a shell script,need to know how much time it took to be on running state?I need to know how much time it took to come to running mode from ...

Ruby 1.8.6 BigDecimal.to_f always returns 0,0 on Solaris

I have come across a very weird error. I m on Solaris 10, using Ruby Enterprise Edition (ruby 1.8.6 (2008-08-08 patchlevel 286) [i386-solaris2.10]) with Rails 2.3.4. I have a very weird error. In irb: ...

Where to set JDK to be used for SunOne server?

Where to set the JDK to be used by the SunOne server on Solaris? Is it all configured via an environment variable like JDK_HOME or JAVA_HOME, or is there a config file for the SunOne server somewhere ...

热门标签