git.fiddlerwoaroof.com
Browse code

wiring

Greg Wiley authored on 26/04/2017 18:50:25
Showing 11 changed files
... ...
@@ -67,7 +67,7 @@ public:
67 67
 };
68 68
 }
69 69
 
70
-conversation create_conversation (pam &pam)
70
+conversation conversation::create (pam &pam)
71 71
 {
72 72
     return conversation (std::shared_ptr<conversation_ifc> (new impl (pam)));
73 73
 }
... ...
@@ -45,6 +45,7 @@ public:
45 45
     {
46 46
         return delegate_->initiate (request);
47 47
     }
48
+    static conversation create (pam &pam);
48 49
 };
49 50
 
50 51
 inline conversation wrap (conversation_ifc *delegate)
... ...
@@ -52,7 +53,6 @@ inline conversation wrap (conversation_ifc *delegate)
52 53
     return conversation (std::shared_ptr<conversation_ifc> (delegate));
53 54
 };
54 55
 
55
-conversation create_conversation (pam &pam);
56 56
 
57 57
 #endif
58 58
 
... ...
@@ -19,11 +19,33 @@
19 19
 
20 20
 #include "request.h"
21 21
 #include "dual_control.h"
22
+#include "validator.h"
23
+#include "logger.h"
24
+#include "conversation.h"
25
+#include "user.h"
26
+#include "token.h"
27
+#include "sys_pwd.h"
28
+#include "sys_unistd.h"
29
+#include "sys_fstream.h"
30
+#include "pam.h"
31
+#include "sys_syslog.h"
22 32
 
23 33
 namespace {
24 34
     dual_control initialize() {
25 35
         dual_control_configuration configuration;
26
-        // ....
36
+        pwd pwd(pwd::create());
37
+        unistd unistd(unistd::create());
38
+        directory directory(directory::create(unistd, pwd));
39
+        fstreams fstreams(fstreams::create());
40
+        user_token_supplier user_token_supplier (user_token_supplier::create(fstreams));
41
+        validator validator(validator::create(directory, user_token_supplier));
42
+        pam pam(pam::create());
43
+        conversation conversation(conversation::create(pam));
44
+        sys_syslog sys_syslog(sys_syslog::create());
45
+        logger logger(logger::create(sys_syslog));
46
+        configuration.validator = validator;
47
+        configuration.logger = logger;
48
+        configuration.conversation = conversation;
27 49
         return dual_control::create(configuration);
28 50
     }
29 51
     dual_control dc = initialize();
... ...
@@ -9,21 +9,25 @@
9 9
  * at https://github.com/cjdev/dual-control.
10 10
  */
11 11
 
12
+#include <memory>
12 13
 #include <vector>
13 14
 #include <security/pam_modules.h>
14 15
 #include <security/pam_appl.h>
15 16
 
16 17
 #include "pam.h"
17 18
 
18
-class syspam : public pam_ifc
19
+namespace {
20
+class impl : public pam_ifc
19 21
 {
20 22
 public:
21
-    int get_conv (pam_handle *handle, const pam_conv **pout);
23
+    int get_conv (pam_handle *handle, const pam_conv **out) {
24
+        return ::pam_get_item(handle, PAM_CONV, (const void **)out);
25
+    }
22 26
 };
23
-
24
-int syspam::get_conv (pam_handle *handle,
25
-                      std::shared_ptr<pam_conv_ifc> &out)
26
-{
27
-    return pam_get_item (handle, PAM_CONV, (const void **)pout);
28 27
 }
29 28
 
29
+
30
+pam pam::create() {
31
+    static pam singleton(std::shared_ptr<pam_ifc>(new impl));
32
+    return singleton;
33
+}
... ...
@@ -36,9 +36,9 @@ public:
36 36
     {
37 37
         return delegate_->get_conv (handle, out);
38 38
     }
39
+    static pam create();
39 40
 };
40 41
 
41
-pam system_pam();
42 42
 
43 43
 #endif
44 44
 
... ...
@@ -28,7 +28,7 @@ public:
28 28
 static pwd system_pwd (pwd::delegate (new impl));
29 29
 }
30 30
 
31
-pwd pwd::system()
31
+pwd pwd::create()
32 32
 {
33 33
     return system_pwd;
34 34
 }
... ...
@@ -42,7 +42,7 @@ public:
42 42
     {
43 43
         return delegate_-> getpwnam_r (user_name, out, buffer, buffer_sz, result);
44 44
     }
45
-    static pwd system();
45
+    static pwd create();
46 46
 };
47 47
 
48 48
 #endif
... ...
@@ -25,7 +25,7 @@ public:
25 25
 static unistd sys_unistd (unistd::delegate (new impl));
26 26
 }
27 27
 
28
-unistd unistd::system()
28
+unistd unistd::create()
29 29
 {
30 30
     return sys_unistd;
31 31
 }
... ...
@@ -40,7 +40,7 @@ public:
40 40
     {
41 41
         return delegate_->sysconf (name);
42 42
     }
43
-    static unistd system();
43
+    static unistd create();
44 44
 };
45 45
 
46 46
 #endif
... ...
@@ -41,7 +41,7 @@ public:
41 41
 };
42 42
 }
43 43
 
44
-validator create_validator (const directory &directory,
44
+validator validator::create (const directory &directory,
45 45
                             const user_token_supplier &user_token_supplier)
46 46
 {
47 47
     std::shared_ptr<validator_ifc> delegate (new impl (directory,
... ...
@@ -42,10 +42,8 @@ public:
42 42
     {
43 43
         return delegate_->validate (user_name, token);
44 44
     }
45
+    static validator create(const directory &directory, const user_token_supplier &token_supplier);
45 46
 };
46 47
 
47
-validator create_validator (const directory &directory,
48
-                            const user_token_supplier &token_supplier);
49
-
50 48
 #endif
51 49