2012-10-04 50 views
1

我正在使用C++中的壓縮程序。我想添加安全描述符,以便在壓縮時保留我的文件權限。我正在使用Zlib的Minizip壓縮文件,我知道Minizip沒有保存文件權限的能力。我認爲我可能必須手動將安全性描述添加到額外字段。C++將文件權限添加到Zip文件

如何獲得文件的安全權限?

如何格式化zip文件的安全描述符?

回答

1

看看Info-ZIP's zip and unzip的實用程序。與基本的minizip功能相比,它們爲各種操作系統提供更廣泛的支持。

對於你自己來說,你可以參考Info-ZIP appnote。在Windows額外的字段中有定義,在這裏複製:

  -PKWARE Win95/WinNT Extra Field (0x000a): 
      ======================================= 

      The following description covers PKWARE's "NTFS" attributes 
      "extra" block, introduced with the release of PKZIP 2.50 for 
      Windows. (Last Revision 20001118) 

      (Note: At this time the Mtime, Atime and Ctime values may 
      be used on any WIN32 system.) 
     [Info-ZIP note: In the current implementations, this field has 
      a fixed total data size of 32 bytes and is only stored as local 
      extra field.] 

      Value   Size  Description 
      -----   ----  ----------- 
    (NTFS) 0x000a  Short  Tag for this "extra" block type 
      TSize   Short  Total Data Size for this block 
      Reserved  Long  for future use 
      Tag1   Short  NTFS attribute tag value #1 
      Size1   Short  Size of attribute #1, in bytes 
      (var.)  SubSize1 Attribute #1 data 
      . 
      . 
      . 
      TagN   Short  NTFS attribute tag value #N 
      SizeN   Short  Size of attribute #N, in bytes 
      (var.)  SubSizeN Attribute #N data 

      For NTFS, values for Tag1 through TagN are as follows: 
      (currently only one set of attributes is defined for NTFS) 

      Tag  Size  Description 
      -----  ----  ----------- 
      0x0001  2 bytes Tag for attribute #1 
      Size1  2 bytes Size of attribute #1, in bytes (24) 
      Mtime  8 bytes 64-bit NTFS file last modification time 
      Atime  8 bytes 64-bit NTFS file last access time 
      Ctime  8 bytes 64-bit NTFS file creation time 

      The total length for this block is 28 bytes, resulting in a 
      fixed size value of 32 for the TSize field of the NTFS block. 

      The NTFS filetimes are 64-bit unsigned integers, stored in Intel 
      (least significant byte first) byte order. They determine the 
      number of 1.0E-07 seconds (1/10th microseconds!) past WinNT "epoch", 
      which is "01-Jan-1601 00:00:00 UTC". 
+0

謝謝,我們實際上是從以前使用了Info-ZIP改變了我們的代碼,現在用Minizip因爲我們需要ZIP64支持。但是如果你可以給我一些關於如何手動獲得權限的想法,我想我可以自己將它們添加到額外的數據字段中。 – Megan

+0

或者,如果您可以將Info-Zip的zip64支持添加,那將非常棒! :) – Megan

+0

您試圖保留權限屬性的是哪種系統? –

相關問題