WindowsNT user authentication

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • billie

    #1

    WindowsNT user authentication

    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

  • Tim Golden

    #2
    Re: WindowsNT user authentication

    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?


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

    HTH
    TJG

    Comment

    • billie

      #3
      Re: WindowsNT user authentication

      On 12 Feb, 14:45, Tim Golden <m...@timgolden .me.ukwrote:
      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_...ers-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?

      Comment

      • Tim Golden

        #4
        Re: WindowsNT user authentication

        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.expandu ser 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.SHGetSpec ialFolderLocati on (0, shellcon.CSIDL_ PERSONAL)
        documents_and_s ettings = shell.SHGetPath FromIDList (idlist)
        print documents_and_s ettings

        </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

        Comment

        • billie

          #5
          Re: WindowsNT user authentication

          On 12 Feb, 16:53, Tim Golden <m...@timgolden .me.ukwrote:
          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.expandu ser 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.SHGetSpec ialFolderLocati on (0, shellcon.CSIDL_ PERSONAL)
          documents_and_s ettings = shell.SHGetPath FromIDList (idlist)
          print documents_and_s ettings
          >
          </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.

          Comment

          • billie

            #6
            Re: WindowsNT user authentication

            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.

            Comment

            • Tim Golden

              #7
              Re: WindowsNT user authentication

              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

              Comment

              • Tim Golden

                #8
                Re: WindowsNT user authentication

                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

                Comment

                • billie

                  #9
                  Re: WindowsNT user authentication

                  On 14 Feb, 14:30, Tim Golden <m...@timgolden .me.ukwrote:
                  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.


                  Comment

                  Working...