git.fiddlerwoaroof.com
Browse code

pam request construct

Greg Wiley authored on 19/04/2017 18:26:32
Showing 7 changed files
... ...
@@ -29,21 +29,21 @@ dual_control.o: dual_control.h
29 29
 dual_control_test: dual_control_test.o dual_control.o
30 30
 	$(CXX) $(CXXFLAGS) $(CPPFLAGS)  -o $@ $^
31 31
 
32
-argument_test: argument_test.o argument.o
32
+request_test: request_test.o request.o
33 33
 	$(CXX) $(CXXFLAGS) $(CPPFLAGS)  -o $@ $^
34 34
 
35 35
 validator_test: validator_test.o validator.o
36 36
 	$(CXX) $(CXXFLAGS) $(CPPFLAGS)  -o $@ $^
37 37
 
38
-conversation_test: conversation_test.o conversation.o
39
-	$(CXX) $(CXXFLAGS) $(CPPFLAGS)  -o $@ $^
38
+# conversation_test: conversation_test.o conversation.o
39
+# 	$(CXX) $(CXXFLAGS) $(CPPFLAGS)  -o $@ $^
40 40
 
41 41
 .PHONY: test
42
-test: validator_test conversation_test argument_test dual_control_test
42
+test: validator_test request_test dual_control_test
43 43
 	@./validator_test
44
-	@./conversation_test
45
-	@./argument_test
44
+	@./request_test
46 45
 	@./dual_control_test
46
+#	@./conversation_test
47 47
 
48 48
 .PHONY: install
49 49
 install: $(OBJS)
50 50
deleted file mode 100644
... ...
@@ -1,17 +0,0 @@
1
-#include <vector>
2
-#include <string>
3
-
4
-#include "argument.h"
5
-
6
-std::vector<const std::string> convert_arguments (int nargs,
7
-        const char **argv)
8
-{
9
-    std::vector<std::string> temp;
10
-
11
-    for (int i = 0; i < nargs; ++i) {
12
-        temp.push_back (argv[i]);
13
-    }
14
-
15
-    return std::vector<const std::string> (temp.begin(), temp.end());
16
-}
17
-
18 0
deleted file mode 100644
... ...
@@ -1,11 +0,0 @@
1
-#ifndef ARGUMENT_H
2
-#define ARGUMENT_H
3
-
4
-#include <string>
5
-#include <vector>
6
-
7
-std::vector<const std::string> convert_arguments (int argc,
8
-        const char **argv);
9
-
10
-#endif
11
-
12 0
deleted file mode 100644
... ...
@@ -1,81 +0,0 @@
1
-#include <vector>
2
-#include <string>
3
-
4
-#include <iostream>
5
-
6
-#include "argument.h"
7
-#include "test_util.h"
8
-
9
-int convert_single_argument_to_cplusplus()
10
-{
11
-    //given
12
-    int nargs = 1;
13
-    const char *arg = "blah";
14
-    const char **argv = &arg;
15
-
16
-    //when
17
-    std::vector<const std::string> actual = convert_arguments (nargs, argv);
18
-
19
-    //then
20
-    std::vector<std::string> temp (1);
21
-    temp[0] = arg;
22
-    std::vector<const std::string> expected (temp.begin(), temp.end());
23
-
24
-    check (actual == expected, "did not convert to c++");
25
-    succeed();
26
-}
27
-
28
-int convert_no_arguments_to_cplusplus()
29
-{
30
-    //given
31
-    int nargs = 0;
32
-    const char **argv = 0;
33
-
34
-    //when
35
-    std::vector<const std::string> actual = convert_arguments (nargs, argv);
36
-
37
-    //then
38
-    std::vector<const std::string> expected;
39
-
40
-    check (actual == expected, "did not convert to c++");
41
-    succeed();
42
-}
43
-
44
-int convert_multiple_arguments_to_cplusplus()
45
-{
46
-    //given
47
-    int nargs = 3;
48
-    const char *arg1 = "one";
49
-    const char *arg2 = "two";
50
-    const char *arg3 = "three";
51
-    const char *argv[] = {arg1,arg2,arg3};
52
-
53
-    //when
54
-    std::vector<const std::string> actual = convert_arguments (nargs, argv);
55
-
56
-    //then
57
-    std::vector<std::string> temp;
58
-    temp.push_back (arg1);
59
-    temp.push_back (arg2);
60
-    temp.push_back (arg3);
61
-    std::vector<const std::string> expected (temp.begin(), temp.end());
62
-
63
-    check (actual == expected, "did not convert to c++");
64
-    succeed();
65
-}
66
-
67
-RESET_VARS_START
68
-RESET_VARS_END
69
-
70
-int run_tests()
71
-{
72
-    test (convert_single_argument_to_cplusplus);
73
-    test (convert_no_arguments_to_cplusplus);
74
-    succeed();
75
-}
76
-
77
-int main()
78
-{
79
-    return !run_tests();
80
-}
81
-
82 0
new file mode 100644
... ...
@@ -0,0 +1,43 @@
1
+#include <vector>
2
+#include <string>
3
+
4
+#include "request.h"
5
+
6
+
7
+/*
8
+ * #ifndef ARGUMENT_H
9
+#define ARGUMENT_H
10
+
11
+#include <string>
12
+#include <vector>
13
+#include <security/pam_modules.h>
14
+
15
+class pam_request {
16
+        int argc_;
17
+        char **argv_;
18
+        int flags_;
19
+        pam_handle *handle_;
20
+    public:
21
+        pam_request(pam_handle *handle, int flags, int argc, char **argv)
22
+            : handle_(handle),
23
+              flags_(flags),
24
+              argc_(argc),
25
+              argv_(argv) {}
26
+        std::vector<std::string> arguments();
27
+        int flags() { return flags_; }
28
+        pam_handle *handle() {return handle_; }
29
+};
30
+
31
+#endif
32
+
33
+*/
34
+
35
+std::vector<std::string> pam_request::arguments() {
36
+    std::vector<std::string> rval;
37
+    for(int i= 0; i < argc_; i++) {
38
+        rval.push_back(argv_[i]);
39
+    }
40
+    return rval;
41
+}
42
+
43
+
0 44
new file mode 100644
... ...
@@ -0,0 +1,25 @@
1
+#ifndef ARGUMENT_H
2
+#define ARGUMENT_H
3
+
4
+#include <string>
5
+#include <vector>
6
+#include <security/pam_modules.h>
7
+
8
+class pam_request {
9
+        int argc_;
10
+        const char **argv_;
11
+        int flags_;
12
+        pam_handle *handle_;
13
+    public:
14
+        pam_request(pam_handle *handle, int flags, int argc, const char **argv)
15
+            : handle_(handle),
16
+              flags_(flags),
17
+              argc_(argc),
18
+              argv_(argv) {}
19
+        std::vector<std::string> arguments();
20
+        int flags() { return flags_; }
21
+        pam_handle *handle() {return handle_; }
22
+};
23
+
24
+#endif
25
+
0 26
new file mode 100644
... ...
@@ -0,0 +1,98 @@
1
+#include <vector>
2
+#include <string>
3
+#include <security/pam_modules.h>
4
+
5
+#include "request.h"
6
+#include "test_util.h"
7
+
8
+bool construction_happy() {
9
+    // given
10
+    pam_handle *handle = reinterpret_cast<pam_handle *>(975);
11
+    int flags = 0x23;
12
+    const char *arg = "an argument";
13
+
14
+    // when
15
+    pam_request actual(handle, flags, 1, &arg);
16
+
17
+    // then
18
+    check(handle == actual.handle(), "handle does not match");
19
+    check(flags == actual.flags(), "flags does not match");
20
+    std::vector<std::string> expected_args;
21
+    expected_args.push_back(arg);
22
+    check(expected_args == actual.arguments(), "arguments does not match");
23
+    succeed();
24
+}
25
+
26
+
27
+//int convert_single_argument_to_cplusplus()
28
+//{
29
+//    //given
30
+//    int nargs = 1;
31
+//    const char *arg = "blah";
32
+//    const char **argv = &arg;
33
+//
34
+//    //when
35
+//    std::vector<const std::string> actual = convert_arguments (nargs, argv);
36
+//
37
+//    //then
38
+//    std::vector<std::string> temp (1);
39
+//    temp[0] = arg;
40
+//    std::vector<const std::string> expected (temp.begin(), temp.end());
41
+//
42
+//    check (actual == expected, "did not convert to c++");
43
+//    succeed();
44
+//}
45
+//
46
+//int convert_no_arguments_to_cplusplus()
47
+//{
48
+//    //given
49
+//    int nargs = 0;
50
+//    const char **argv = 0;
51
+//
52
+//    //when
53
+//    std::vector<const std::string> actual = convert_arguments (nargs, argv);
54
+//
55
+//    //then
56
+//    std::vector<const std::string> expected;
57
+//
58
+//    check (actual == expected, "did not convert to c++");
59
+//    succeed();
60
+//}
61
+//
62
+//int convert_multiple_arguments_to_cplusplus()
63
+//{
64
+//    //given
65
+//    int nargs = 3;
66
+//    const char *arg1 = "one";
67
+//    const char *arg2 = "two";
68
+//    const char *arg3 = "three";
69
+//    const char *argv[] = {arg1,arg2,arg3};
70
+//
71
+//    //when
72
+//    std::vector<const std::string> actual = convert_arguments (nargs, argv);
73
+//
74
+//    //then
75
+//    std::vector<std::string> temp;
76
+//    temp.push_back (arg1);
77
+//    temp.push_back (arg2);
78
+//    temp.push_back (arg3);
79
+//    std::vector<const std::string> expected (temp.begin(), temp.end());
80
+//
81
+//    check (actual == expected, "did not convert to c++");
82
+//    succeed();
83
+//}
84
+
85
+RESET_VARS_START
86
+RESET_VARS_END
87
+
88
+int run_tests()
89
+{
90
+    test (construction_happy);
91
+    succeed();
92
+}
93
+
94
+int main()
95
+{
96
+    return !run_tests();
97
+}
98
+