WindowsNT user authentication

Discussion in 'Python' started by billie, Feb 12, 2007.

  1. billie

    billie Guest

    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
    billie, Feb 12, 2007
    #1
    1. Advertising

  2. billie

    Tim Golden Guest

    billie wrote:
    > 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?


    http://timgolden.me.uk/python/win32_how_do_i/check-a-users-credentials.html

    There are a few caveats (and there are other ways, too). This
    one is pretty simple, though.

    HTH
    TJG
    Tim Golden, Feb 12, 2007
    #2
    1. Advertising

  3. billie

    billie Guest

    On 12 Feb, 14:45, Tim Golden <> wrote:
    > billie wrote:
    > > 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?

    >
    > http://timgolden.me.uk/python/win32_how_do_i/check-a-users-credential...
    >
    > There are a few caveats (and there are other ways, too). This
    > one is pretty simple, though.
    >
    > HTH
    > TJG


    Thanks, it shoulda work.
    Do you got any idea about how getting user's home directory?
    billie, Feb 12, 2007
    #3
  4. billie

    Tim Golden Guest

    billie wrote:

    > 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
    Tim Golden, Feb 12, 2007
    #4
  5. billie

    billie Guest

    On 12 Feb, 16:53, Tim Golden <> wrote:
    > billie wrote:
    > > 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


    Thanks.
    billie, Feb 13, 2007
    #5
  6. billie

    billie Guest

    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.
    billie, Feb 14, 2007
    #6
  7. billie

    Tim Golden Guest

    billie wrote:
    > 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
    Tim Golden, Feb 14, 2007
    #7
  8. billie

    Tim Golden Guest

    Tim Golden wrote:
    > billie wrote:
    >> 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.


    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
    Tim Golden, Feb 14, 2007
    #8
  9. billie

    billie Guest

    On 14 Feb, 14:30, Tim Golden <> wrote:
    > Tim Golden wrote:
    > > billie wrote:
    > >> 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.

    >
    > 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.
    billie, Feb 14, 2007
    #9
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Kevin Love
    Replies:
    1
    Views:
    404
    William F. Robertson, Jr.
    Jun 30, 2003
  2. Andrew Connell
    Replies:
    1
    Views:
    544
    Natty Gur
    Oct 21, 2003
  3. raj mandadi
    Replies:
    0
    Views:
    426
    raj mandadi
    Dec 22, 2003
  4. Brett Porter
    Replies:
    2
    Views:
    758
    Andrea D'Onofrio [MSFT]
    Jan 20, 2004
  5. Gijs Korremans
    Replies:
    0
    Views:
    290
    Gijs Korremans
    May 18, 2005
Loading...

Share This Page