locked
Impersonation : How use two impersonations "at the same time" RRS feed

  • Question

  • I'm writing a copy system. One of the feature is read a file on a server with a specific Windows identity and write on another one with another identity.

    One of the way I found is :

     * Impersonate the code that reads the file and write a local temporary file

     * Impersonate the code that writes the file from the local temporary file

    What I want to do is read the file byte by byte (or block of bytes) with a specific identity and write on another share folder with another identity.

    Can I keep the identity context to execute some code, or do I have to undo the impersonation between each call ?

    The final code looks like : fileSource.BeginCopy(fileDestination.WriteBufferCallback, doneAutoResetEvent);

    The BeginCopy must be executed with an identity and the Write under another one.

    Thank you for your help.

    Wednesday, January 23, 2013 3:37 PM

Answers

  • You can only do what you want if you have 2 threads.  A single thread can only have one identity, but if you know multithreading programming then you can share the data buffer with a writing thread running using a different identity.  The actual details on buffer sharing would be your choice (syncrhonized buffer or heap buffers queued for writing would be my two choices).

    Jose R. MCP
    Code Samples

    • Proposed as answer by Alex Skalozub Wednesday, January 23, 2013 8:47 PM
    • Marked as answer by Mike Feng Thursday, January 24, 2013 9:39 AM
    Wednesday, January 23, 2013 4:12 PM

All replies

  • You can only do what you want if you have 2 threads.  A single thread can only have one identity, but if you know multithreading programming then you can share the data buffer with a writing thread running using a different identity.  The actual details on buffer sharing would be your choice (syncrhonized buffer or heap buffers queued for writing would be my two choices).

    Jose R. MCP
    Code Samples

    • Proposed as answer by Alex Skalozub Wednesday, January 23, 2013 8:47 PM
    • Marked as answer by Mike Feng Thursday, January 24, 2013 9:39 AM
    Wednesday, January 23, 2013 4:12 PM
  • Thank you.

    I'll do what you advise.


    Sebastien

    • Marked as answer by Sebastien Curutchet Thursday, January 24, 2013 8:38 AM
    • Unmarked as answer by Mike Feng Thursday, January 24, 2013 9:39 AM
    Thursday, January 24, 2013 8:38 AM