WindowsNT user authentication

B

billie

Hi there,
I would like to submit a username/password pair to a Windows NT
workstation and find out if it's valid.
Moreover I would like to get the user's home directory given the
username.
Does it is possible to do that by using pywin32 extension?

Could someone point me in the right direction?


Best regards
 
T

Tim Golden

billie said:
Do you got any idea about how getting user's home directory?

The answer to that is unfortunately slightly complicated,
because Windows has no such thing as a "user's home directory"
or, if you prefer, it has several such things.

If you want, you can let Python make the decision, by
calling os.path.expanduser on "~" which, in my case,
correctly gives h:\ which is my domain home directory.

Obviously this is not necessarily the same as my Documents
and Settings directory, which can also be considered a home
directory. That you can get by querying the shell:

<code>
from win32com.shell import shell, shellcon

idlist = shell.SHGetSpecialFolderLocation (0, shellcon.CSIDL_PERSONAL)
documents_and_settings = shell.SHGetPathFromIDList (idlist)
print documents_and_settings

</code>

In my case they are the same but that will depend on your
setup. I know in the past at least one of these has
defaulted to c:\

Alternatives (which in my case amount to the same thing)
include using the HOMEDRIVE / HOMEPATH / HOMESHARE
environment vars:

<code>
import os
drive = os.environ.get ("HOMEDRIVE", "")
path = os.environ.get ("HOMEPATH", "")

share = os.environ.get ("HOMESHARE", "")

print drive+path
print share
</code>

I haven't bothered to look, but I think this latter
is how the expanduser function works things out.

YMMV
TJG
 
B

billie

The answer to that is unfortunately slightly complicated,
because Windows has no such thing as a "user's home directory"
or, if you prefer, it has several such things.

If you want, you can let Python make the decision, by
calling os.path.expanduser on "~" which, in my case,
correctly gives h:\ which is my domain home directory.

Obviously this is not necessarily the same as my Documents
and Settings directory, which can also be considered a home
directory. That you can get by querying the shell:

<code>
from win32com.shell import shell, shellcon

idlist = shell.SHGetSpecialFolderLocation (0, shellcon.CSIDL_PERSONAL)
documents_and_settings = shell.SHGetPathFromIDList (idlist)
print documents_and_settings

</code>

In my case they are the same but that will depend on your
setup. I know in the past at least one of these has
defaulted to c:\

Alternatives (which in my case amount to the same thing)
include using the HOMEDRIVE / HOMEPATH / HOMESHARE
environment vars:

<code>
import os
drive = os.environ.get ("HOMEDRIVE", "")
path = os.environ.get ("HOMEPATH", "")

share = os.environ.get ("HOMESHARE", "")

print drive+path
print share
</code>

I haven't bothered to look, but I think this latter
is how the expanduser function works things out.

YMMV
TJG

Thanks.
 
B

billie

Another question, I'm sorry.
Do you got any idea about how to get permissions of a file/directory
given the username?
For example: I would like to know if C:\my_file.ext is readable/
writable by user 'x' or not.
 
T

Tim Golden

billie said:
Another question, I'm sorry.
Do you got any idea about how to get permissions of a file/directory
given the username?
For example: I would like to know if C:\my_file.ext is readable/
writable by user 'x' or not.

This is an unfortunately messy question. The easiest
answer -- and I'm quite serious -- might be to have
the user *try* to read it and to catch the exception.

Quite apart from the mildly labyrinthine techniques for
determining object security, you face a potential race
condition: by the time you've tested and got your answer,
someone could have changed the permissions. Unlikely,
you'll admit, but possible enough to the try-except
approach attractive.

There are some examples of file security both in the
CHM which comes with the pywin32 extensions and in the
demos folder, on my machine:

c:\python24\lib\site-packages\win32\demos\security

I was going to start explaining win32 security terms
in this reply, but perhaps I won't unless the try-it-and-see
approach advocated above doesn't work!

HTH somewhat
TJG
 
T

Tim Golden

Tim said:
This is an unfortunately messy question.

I'm sorry; that probably came out wrong. What I meant
was that, although the question was perfectly intelligible,
the answer is going to be more complex than you probably
expected ;)

TJG
 
B

billie

I'm sorry; that probably came out wrong. What I meant
was that, although the question was perfectly intelligible,
the answer is going to be more complex than you probably
expected ;)

TJG

No problem about that. ;)
I'll try to check demos folder then let you know something about it.
Thanks again.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top