API
 
Loading...
Searching...
No Matches
thSetuid_test.cpp
Go to the documentation of this file.
1#include "../../../tests/catch2/catch.hpp"
2
3
4#include "../thSetuid.hpp"
5
6#include <iostream>
7#include <thread>
8
9
11{
12
14
17uid_t th_suid;
18
20{
21 while(timeToDie == false)
22 {
23 getresuid(&th_euidReal, &th_euidCalled, &th_suid);
24 }
25}
26
27
28SCENARIO( "Setting per-thread setuid privileges", "[libMagAOX::sys]" )
29{
30 uid_t euidReal, er;
31 uid_t euidCalled, ec;
32 uid_t suid;
33
34 getresuid(&euidReal, &euidCalled, &suid);
35
36 if(euidReal == suid) {
37 std::cerr << "Can't test setuid as root, moving on\n";
38 SUCCEED("Can't test setuid as root, moving on");
39 } else {
40 GIVEN("A process with setuid bit set")
41 {
42 std::thread thrd;
43
44 timeToDie = false;
45
46 bool is_setuid = ((euidReal != euidCalled) && (euidReal != suid));
47 REQUIRE(is_setuid == true); //Must run this test from setuid as unprivileged user
48
50
51 getresuid(&er, &ec, &suid);
52
53 thrd = std::thread( logThreadStart );
54
55 usleep(10000);
56
57 REQUIRE( er == th_euidReal ); // Thread real uid not synched
58 REQUIRE( ec == th_euidCalled ); // Thread called uid not synched
59
60 MagAOX::sys::th_seteuid(euidCalled);
61
62 getresuid(&er, &ec, &suid);
63 usleep(10000);
64
65 REQUIRE( er == th_euidReal ); //Thread real uid not synched
66 REQUIRE( ec != th_euidCalled ); //Thread called uid synched
67
68 timeToDie = true;
69
70 thrd.join();
71 }
72 }
73}
74
75} //namespace thSetuid_test
#define GIVEN(desc)
Definition catch.hpp:17763
#define SUCCEED(...)
Definition catch.hpp:17720
#define SCENARIO(...)
Definition catch.hpp:17760
#define REQUIRE(...)
Definition catch.hpp:17676
int th_seteuid(uid_t euid)
Sets the effective user id of the calling thread, rather than the whole process.
Definition thSetuid.cpp:18