traveler has asked for the wisdom of the Perl Monks concerning the following question:

All,

I have a perl script that runs under Linux and writes to a share exported by a Win32 host. I'd like to test and see if the file written by the script is encrypted (using Windows XP's built-in file encryption). I can't just read the file back and see if it is different than what I wrote, because the encryption should be transparent to me. The file is in a directory mounted by Linux's automounter. So, is there some way to detect if the file is encrypted?

Thanks,

--traveler

  • Comment on Detecting Encrypted Files in a mounted Windows FS?

Replies are listed 'Best First'.
Re: Detecting Encrypted Files in a mounted Windows FS?
by RMGir (Prior) on Aug 07, 2002 at 19:59 UTC
    I'm not a 100% sure, but I think you can see whether the file's encrypted by checking its properties on the Windows box.

    I'm fairly certain you couldn't tell from the Linux side, since, as you said, it's transparent to you.

    I'd check, but I don't have an XP box with an NTFS drive available within easy reach. On Win2k, it's in Properties, then click Advanced.
    --
    Mike

      Yeah, I intend to set up the directories myself and they should all be encrypted. What I'd like to do is ensure that the file is encrypted and send mail to the user if it isn't.

      --traveler

        Interestingly, you can get this on Windows if you have ActivePerl installed, using the Win32::File module.

        The catch (apart from the fact that you'd like to do this from Linux) is that Win32::File doesn't seem to have a constant for "ENCRYPTED", but it does return the correct bit set...

        grep FILE_ATTRIBUTE_ENCRYPTED *\*.h Include/WinNT.h:#define FILE_ATTRIBUTE_ENCRYPTED 0x00004000
        And running GetAttributes on an encrypted file yields:
        C:\>perl -MWin32::File -e"Win32::File::GetAttributes('README.TXT',$x); + printf qq(%X\n),$x;map {printf qq(%-10s %08X\n),$_,&{'Win32::File::'.$_}} qw +(ARCHIVE C OMPRESSED DIRECTORY HIDDEN NORMAL OFFLINE READONLY SYSTEM TEMPORARY)" 6021 ARCHIVE 00000020 COMPRESSED 00000800 DIRECTORY 00000010 HIDDEN 00000002 NORMAL 00000080 OFFLINE 00001000 READONLY 00000001 SYSTEM 00000004 TEMPORARY 00000100
        I realize that doesn't really help you from Linux, unless you set up an "isencrypted_d" service running on NT :)

        If you're curious, the 0x2000 bit is "FILE_ATTRIBUTE_NOT_CONTENT_INDEXED"...
        --
        Mike

Re: Detecting Encrypted Files in a mounted Windows FS?
by Rex(Wrecks) (Curate) on Aug 07, 2002 at 21:01 UTC
    You could always disconnect from the Win32 host, then reconnect with a test user that has no rights and see if the files are readable.

    Solution1:
    If the share point is C:\files and the encrypted directories are C:\files\encryp1 and so on...connect, write a file to encryp1, disconnect, reconnect with the test user and try to read the file.

    This is a lot of overhead to do on each write, but cron a job for the evening to check if you can read some of the files shouldn't be so hard.

    Solution2:
    Write an admin accessable service on the Windows machine that you can query and will tell you if the file has been encrypted...this would be better than solution1

    "Nothing is sure but death and taxes" I say combine the two and its death to all taxes!
Re: Detecting Encrypted Files in a mounted Windows FS?
by BrowserUk (Patriarch) on Aug 08, 2002 at 00:41 UTC

    'scuse my lack of knowledge of *nix stuff, but the following (vague) description might work for you.

    Spawn a thread or more likely fork a child process, set the (?real|effective) userid to a non-privaledged ID. Pass the file name/handle and the first word in the file to the child process (via a pipe or shared mem) and have it attempt to read that word and return yea/nay as appropriate.

Re: Detecting Encrypted Files in a mounted Windows FS?
by John M. Dlugosz (Monsignor) on Aug 07, 2002 at 21:26 UTC
    Have the perl script or other program that tests the file's properties run on the Windows box.