git.fiddlerwoaroof.com
Browse code

CJPM-5223: add missing uid-related methods

Ed Langley authored on 15/06/2017 00:30:39
Showing 4 changed files
... ...
@@ -25,6 +25,10 @@ public:
25 25
     {
26 26
         return ::getlogin();
27 27
     }
28
+    virtual int seteuid(uid_t euid) const override
29
+    {
30
+        return ::seteuid(euid);
31
+    };
28 32
 };
29 33
 }
30 34
 
... ...
@@ -33,4 +37,3 @@ unistd unistd::create()
33 37
     static unistd sys_unistd (unistd::delegate (new impl));
34 38
     return sys_unistd;
35 39
 }
36
-
... ...
@@ -28,6 +28,11 @@ public:
28 28
     {
29 29
         return "";
30 30
     }
31
+    virtual int seteuid(uid_t euid) const
32
+    {
33
+        return -1;
34
+    };
35
+
31 36
 };
32 37
 
33 38
 class unistd
... ...
@@ -49,10 +54,13 @@ public:
49 54
     {
50 55
         return delegate_->getlogin();
51 56
     }
57
+    int seteuid(uid_t euid) const
58
+    {
59
+        return delegate_->seteuid(euid);
60
+    };
52 61
     static unistd create();
53 62
 };
54 63
 
55 64
 template class std::shared_ptr<unistd_ifc>;
56 65
 
57 66
 #endif
58
-
... ...
@@ -23,10 +23,16 @@ class user_impl : public user_ifc
23 23
 private:
24 24
     std::string home_directory_;
25 25
     std::string user_name_;
26
+    uid_t uid_;
26 27
 public:
27 28
     user_impl (const passwd user_info) :
28 29
         home_directory_ (std::string (user_info.pw_dir)),
29
-        user_name_ (std::string (user_info.pw_name)) {}
30
+        user_name_ (std::string (user_info.pw_name)),
31
+        uid_ (user_info.pw_uid) {}
32
+    uid_t uid() const override
33
+    {
34
+        return uid_;
35
+    }
30 36
     std::string home_directory() const override
31 37
     {
32 38
         return home_directory_;
... ...
@@ -81,4 +87,3 @@ directory directory::create (unistd &unistd, pwd &pwd)
81 87
 {
82 88
     return directory (delegate (new directory_impl (unistd, pwd)));
83 89
 }
84
-
... ...
@@ -26,6 +26,10 @@ public:
26 26
     {
27 27
         return "";
28 28
     }
29
+    virtual uid_t uid() const
30
+    {
31
+        return -1;
32
+    }
29 33
 };
30 34
 
31 35
 class user
... ...
@@ -43,6 +47,10 @@ public:
43 47
     {
44 48
         return delegate_-> home_directory();
45 49
     }
50
+    uid_t uid() const
51
+    {
52
+        return delegate_->uid();
53
+    }
46 54
     static user create (const passwd &passwd);
47 55
 };
48 56
 
... ...
@@ -82,4 +90,3 @@ public:
82 90
 };
83 91
 
84 92
 #endif
85
-