1*b9128a37SMartin Matuska /*- 2*b9128a37SMartin Matuska * Copyright (c) 2003-2010 Tim Kientzle 3*b9128a37SMartin Matuska * Copyright (c) 2024 Haelwenn (lanodan) Monnier 4*b9128a37SMartin Matuska * All rights reserved. 5*b9128a37SMartin Matuska * 6*b9128a37SMartin Matuska * Redistribution and use in source and binary forms, with or without 7*b9128a37SMartin Matuska * modification, are permitted provided that the following conditions 8*b9128a37SMartin Matuska * are met: 9*b9128a37SMartin Matuska * 1. Redistributions of source code must retain the above copyright 10*b9128a37SMartin Matuska * notice, this list of conditions and the following disclaimer. 11*b9128a37SMartin Matuska * 2. Redistributions in binary form must reproduce the above copyright 12*b9128a37SMartin Matuska * notice, this list of conditions and the following disclaimer in the 13*b9128a37SMartin Matuska * documentation and/or other materials provided with the distribution. 14*b9128a37SMartin Matuska * 15*b9128a37SMartin Matuska * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR 16*b9128a37SMartin Matuska * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 17*b9128a37SMartin Matuska * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 18*b9128a37SMartin Matuska * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT, 19*b9128a37SMartin Matuska * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 20*b9128a37SMartin Matuska * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 21*b9128a37SMartin Matuska * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 22*b9128a37SMartin Matuska * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 23*b9128a37SMartin Matuska * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 24*b9128a37SMartin Matuska * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25*b9128a37SMartin Matuska */ 26*b9128a37SMartin Matuska #include "test.h" 27*b9128a37SMartin Matuska 28*b9128a37SMartin Matuska DEFINE_TEST(test_option_owner) 29*b9128a37SMartin Matuska { 30*b9128a37SMartin Matuska char *reference, *data; 31*b9128a37SMartin Matuska size_t s; 32*b9128a37SMartin Matuska 33*b9128a37SMartin Matuska assertUmask(0); 34*b9128a37SMartin Matuska assertMakeFile("file", 0644, "1234567890"); 35*b9128a37SMartin Matuska 36*b9128a37SMartin Matuska /* Create archive with no special options. */ 37*b9128a37SMartin Matuska failure("Error invoking %s c", testprog); 38*b9128a37SMartin Matuska assertEqualInt(0, 39*b9128a37SMartin Matuska systemf("%s cf archive1 --format=ustar file >stdout1.txt 2>stderr1.txt", 40*b9128a37SMartin Matuska testprog)); 41*b9128a37SMartin Matuska assertEmptyFile("stdout1.txt"); 42*b9128a37SMartin Matuska assertEmptyFile("stderr1.txt"); 43*b9128a37SMartin Matuska reference = slurpfile(&s, "archive1"); 44*b9128a37SMartin Matuska 45*b9128a37SMartin Matuska /* Create archive with --owner (numeric) */ 46*b9128a37SMartin Matuska failure("Error invoking %s c", testprog); 47*b9128a37SMartin Matuska assertEqualInt(0, 48*b9128a37SMartin Matuska systemf("%s cf archive2 --owner=65123 --format=ustar file >stdout2.txt 2>stderr2.txt", 49*b9128a37SMartin Matuska testprog)); 50*b9128a37SMartin Matuska assertEmptyFile("stdout2.txt"); 51*b9128a37SMartin Matuska assertEmptyFile("stderr2.txt"); 52*b9128a37SMartin Matuska data = slurpfile(&s, "archive2"); 53*b9128a37SMartin Matuska assertEqualMem(data + 108, "177143 \0", 8); 54*b9128a37SMartin Matuska /* Uname field in ustar header should be empty. */ 55*b9128a37SMartin Matuska assertEqualMem(data + 265, "\0", 1); 56*b9128a37SMartin Matuska free(data); 57*b9128a37SMartin Matuska 58*b9128a37SMartin Matuska /* Again with just --owner (name) */ 59*b9128a37SMartin Matuska failure("Error invoking %s c", testprog); 60*b9128a37SMartin Matuska assertEqualInt(0, 61*b9128a37SMartin Matuska systemf("%s cf archive3 --owner=foofoofoo --format=ustar file >stdout3.txt 2>stderr3.txt", 62*b9128a37SMartin Matuska testprog)); 63*b9128a37SMartin Matuska assertEmptyFile("stdout3.txt"); 64*b9128a37SMartin Matuska assertEmptyFile("stderr3.txt"); 65*b9128a37SMartin Matuska data = slurpfile(&s, "archive3"); 66*b9128a37SMartin Matuska /* Uid should be unchanged from original reference. */ 67*b9128a37SMartin Matuska assertEqualMem(data + 108, reference + 108, 8); 68*b9128a37SMartin Matuska assertEqualMem(data + 265, "foofoofoo\0", 10); 69*b9128a37SMartin Matuska free(data); 70*b9128a37SMartin Matuska 71*b9128a37SMartin Matuska /* Again with just --owner (name:id) */ 72*b9128a37SMartin Matuska failure("Error invoking %s c", testprog); 73*b9128a37SMartin Matuska assertEqualInt(0, 74*b9128a37SMartin Matuska systemf("%s cf archive4 --owner=foofoofoo:65123 --format=ustar file >stdout4.txt 2>stderr4.txt", 75*b9128a37SMartin Matuska testprog)); 76*b9128a37SMartin Matuska assertEmptyFile("stdout4.txt"); 77*b9128a37SMartin Matuska assertEmptyFile("stderr4.txt"); 78*b9128a37SMartin Matuska data = slurpfile(&s, "archive4"); 79*b9128a37SMartin Matuska assertEqualMem(data + 108, "177143 \0", 8); 80*b9128a37SMartin Matuska assertEqualMem(data + 265, "foofoofoo\0", 10); 81*b9128a37SMartin Matuska free(data); 82*b9128a37SMartin Matuska 83*b9128a37SMartin Matuska free(reference); 84*b9128a37SMartin Matuska } 85