"Fossies" - the Fresh Open Source Software Archive

Member "burp-2.3.6/utest/client/test_extrameta.c" (28 Apr 2019, 2780 Bytes) of package /linux/privat/burp-2.3.6.tar.bz2:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "test_extrameta.c" see the Fossies "Dox" file reference documentation and the last Fossies "Diffs" side-by-side code changes report: 2.2.12_vs_2.3.0.

    1 #include "../test.h"
    2 #include "../builders/build_file.h"
    3 #include "../../src/alloc.h"
    4 #include "../../src/cmd.h"
    5 #include "../../src/fsops.h"
    6 #include "../../src/client/extrameta.h"
    7 #include "../../src/client/xattr.h"
    8 
    9 #ifdef HAVE_ACL
   10 #ifdef HAVE_XATTR
   11 
   12 #define BASE        "utest_extrameta"
   13 
   14 static void tear_down(void)
   15 {
   16     fail_unless(recursive_delete(BASE)==0);
   17     alloc_check();
   18 }
   19 
   20 struct extrametadata
   21 {
   22     int do_dir;
   23         const char *extrameta;
   24 };
   25 
   26 static struct extrametadata x[] = {
   27     {
   28         // File - A single extrameta
   29         0,
   30 #ifdef HAVE_FREEBSD_OS
   31         "B0000001E0000000Cuser.comment00000002cd"
   32 #else
   33         "X0000001E0000000Cuser.comment00000002cd"
   34 #endif
   35     },
   36 #ifndef HAVE_DARWIN_OS
   37     {
   38         // File - An access acl.
   39         0,
   40 #ifdef HAVE_FREEBSD_OS
   41         "A0000003Cuser::rwx\nuser:%s:rwx\ngroup::rwx\nmask::rwx\nother::r--\n"
   42 #else
   43         "A00000026u::rwx,u:1001:rwx,g::rwx,m::rwx,o::r--"
   44 #endif
   45     },
   46     {
   47         // Directory - A default acl.
   48         1,
   49 #ifdef HAVE_FREEBSD_OS
   50         "D00000020user::rwx\ngroup::rwx\nother::r-x\n"
   51 #else
   52         "D00000014u::rwx,g::rwx,o::r-x"
   53 #endif
   54     },
   55     {
   56         // File - A single extrameta and a single access acl.
   57         0,
   58 #ifdef HAVE_FREEBSD_OS
   59         "A0000003Cuser::rwx\nuser:%s:rwx\ngroup::rwx\nmask::rwx\nother::r--\n"
   60         "B0000001E0000000Cuser.comment00000002cd"
   61 #else
   62         "A00000026u::rwx,u:1001:rwx,g::rwx,m::rwx,o::r--"
   63         "X0000001E0000000Cuser.comment00000002cd"
   64 #endif
   65     },
   66 #endif
   67 };
   68 
   69 static void test_extrameta(struct extrametadata x)
   70 {
   71     size_t rlen=0;
   72     char *retrieved=NULL;
   73     const char *path=NULL;
   74     const char *myfile=BASE "/myfile";
   75     char expected[256];
   76     enum cmd cmd;
   77     struct passwd *passwd=NULL;
   78 
   79     fail_unless(recursive_delete(BASE)==0);
   80     build_file(myfile, NULL);
   81 
   82     if(x.do_dir)
   83     {
   84         cmd=CMD_DIRECTORY;
   85         path=BASE;
   86     }
   87     else
   88     {
   89         cmd=CMD_FILE;
   90         path=myfile;
   91     }
   92 
   93     if(strstr(x.extrameta, "%s"))
   94         fail_unless((passwd=getpwuid(1001))!=NULL);
   95     snprintf(expected, sizeof(expected), x.extrameta,
   96         passwd?passwd->pw_name:"");
   97 
   98     fail_unless(has_extrameta(path, cmd,
   99         1, // enable_acl
  100         1  // enable_xattr
  101     )==0);
  102 
  103     fail_unless(!set_extrameta(
  104         NULL, // asfd
  105 #ifdef HAVE_WIN32
  106         NULL, // bfd
  107 #endif
  108         path,
  109         expected,
  110         strlen(expected),
  111         NULL // cntr
  112     ));
  113     fail_unless(!get_extrameta(
  114         NULL, // asfd
  115 #ifdef HAVE_WIN32
  116         NULL, // bfd
  117 #endif
  118         path,
  119         x.do_dir,
  120         &retrieved,
  121         &rlen,
  122         NULL // cntr
  123     ));
  124     fail_unless(rlen==strlen(expected));
  125 
  126     fail_unless(!memcmp(expected, retrieved, rlen));
  127 
  128     free_w(&retrieved);
  129     tear_down();
  130 }
  131 
  132 START_TEST(test_extrametas)
  133 {
  134     FOREACH(x)
  135     {
  136         test_extrameta(x[i]);
  137     }
  138 }
  139 END_TEST
  140 
  141 Suite *suite_client_extrameta(void)
  142 {
  143     Suite *s;
  144     TCase *tc_core;
  145 
  146     s=suite_create("client_extrameta");
  147 
  148     if(!fs_supports_xattr())
  149         return s;
  150 
  151     tc_core=tcase_create("Core");
  152 
  153     tcase_add_test(tc_core, test_extrametas);
  154 
  155     suite_add_tcase(s, tc_core);
  156 
  157     return s;
  158 }
  159 
  160 #endif
  161 #endif