Browse code
checkpoint - restructure
Greg Wiley authored on 17/04/2017 23:15:09
Showing 4 changed files
Showing 4 changed files
... | ... |
@@ -1,8 +1,7 @@ |
1 | 1 |
CXXFLAGS += -fPIC -fno-stack-protector |
2 | 2 |
CFLAGS += -fPIC -fno-stack-protector |
3 | 3 |
|
4 |
-OBJS = logging.o conversation.o token.o dual_control.o |
|
5 |
-HEADERS = logging.h test_support.h token.h |
|
4 |
+OBJS = dual_control.o |
|
6 | 5 |
|
7 | 6 |
MODULELIB = pam_dual_control.so |
8 | 7 |
|
... | ... |
@@ -25,27 +24,12 @@ clean: |
25 | 24 |
distclean: clean |
26 | 25 |
@rm -f Makefile config.h |
27 | 26 |
|
27 |
+dual_control.o: dual_control.h |
|
28 | 28 |
|
29 |
- |
|
30 |
-t_%.o: %.cc |
|
31 |
- $(CXX) -c $(CPPFLAGS) $(CXXFLAGS) -D UNIT_TEST -o $@ $< |
|
32 |
- |
|
33 |
-#dual_control_test: dual_control_test.o t_dual_control.o |
|
34 |
-# $(CXX) $(CXXFLAGS) $(CPPLAGS) -lpam -o $@ $^ |
|
35 |
-# |
|
36 |
-#logging_test: logging_test.o t_logging.o |
|
37 |
-# $(CXX) $(CXXFLAGS) $(CPPFLAGS) -lpam -o $@ $^ |
|
38 |
-# |
|
39 |
-#token_test: token_test.o t_token.o |
|
40 |
-# $(CXX) $(CXXFLAGS) $(CPPFLAGS) -lpam -o $@ $^ |
|
41 |
- |
|
42 |
-user_test: user_test.o t_user.o |
|
29 |
+validator_test: validator_test.o validator.o |
|
43 | 30 |
$(CXX) $(CXXFLAGS) $(CPPFLAGS) -o $@ $^ |
44 | 31 |
|
45 |
-validator_test: validator_test.o t_validator.o |
|
46 |
- $(CXX) $(CXXFLAGS) $(CPPFLAGS) -o $@ $^ |
|
47 |
- |
|
48 |
-conversation_test: conversation_test.o t_conversation.o |
|
32 |
+conversation_test: conversation_test.o conversation.o |
|
49 | 33 |
$(CXX) $(CXXFLAGS) $(CPPFLAGS) -o $@ $^ |
50 | 34 |
|
51 | 35 |
.PHONY: test |
... | ... |
@@ -53,11 +37,6 @@ test: validator_test conversation_test |
53 | 37 |
@./validator_test |
54 | 38 |
@./conversation_test |
55 | 39 |
|
56 |
-# @./dual_control_test |
|
57 |
-# @./logging_test |
|
58 |
-# @./token_test |
|
59 |
-# @echo all tests passed |
|
60 |
- |
|
61 | 40 |
.PHONY: install |
62 | 41 |
install: $(OBJS) |
63 | 42 |
ifeq ($(UNAME_S), Linux) |
... | ... |
@@ -1,29 +1,21 @@ |
1 |
-#include <security/pam_appl.h> |
|
2 | 1 |
#include <security/pam_modules.h> |
3 |
-#include <cstring> |
|
4 |
-#include <cstdlib> |
|
2 |
+#include <string> |
|
3 |
+#include <memory> |
|
4 |
+#include <vector> |
|
5 | 5 |
|
6 |
-#include "logging.h" |
|
7 |
-#include "conversation.h" |
|
8 |
-#include "validator.h" |
|
6 |
+#include "arguments.h" |
|
9 | 7 |
|
10 |
-extern validator system_validator; |
|
8 |
+std::vector<const std::string> convert_arguments(int argc, const char **argv); |
|
11 | 9 |
|
12 |
-PAM_EXTERN int pam_sm_authenticate(pam_handle_t *pamh, int flags, int argc, const char **argv) { |
|
13 |
- |
|
14 |
- pam_token_conversation conversation(pamh); |
|
15 |
- int returned_validation = system_validator.validate(conversation.user_name(), conversation.token()); |
|
10 |
+extern dual_control dc; |
|
16 | 11 |
|
17 |
- if (returned_validation) { |
|
18 |
- log_success(); |
|
19 |
- return PAM_SUCCESS; |
|
20 |
- } else { |
|
21 |
- log_failure(); |
|
22 |
- return PAM_AUTH_ERR; |
|
23 |
- } |
|
12 |
+PAM_EXTERN int pam_sm_authenticate(pam_handle_t *pamh, int flags, int argc, const char **argv) { |
|
13 |
+ std::vector<const std::string> arguments = convert_arguments(argc, argv); |
|
14 |
+ return dc.authenticate(pamh, flags, arguments); |
|
24 | 15 |
} |
25 | 16 |
|
26 | 17 |
PAM_EXTERN int pam_sm_setcred(pam_handle_t *pamh, int flags, int argc, const char **argv) { |
27 |
- return PAM_SUCCESS; |
|
18 |
+ std::vector<const std::string> arguments = convert_arguments(argc, argv); |
|
19 |
+ return dc.setcred(pamh, flags, arguments); |
|
28 | 20 |
} |
29 | 21 |
|
30 | 22 |
new file mode 100644 |
... | ... |
@@ -0,0 +1,28 @@ |
1 |
+#ifndef _DUAL_CONTROL_H |
|
2 |
+#define _DUAL_CONTROL_H |
|
3 |
+ |
|
4 |
+#include <string> |
|
5 |
+#include <memory> |
|
6 |
+#include <vector> |
|
7 |
+#include <security/pam_modules.h> |
|
8 |
+ |
|
9 |
+class dual_control_ifc { |
|
10 |
+ public: |
|
11 |
+ virtual int authenticate(pam_handle_t *handle, int flags, const std::vector<const std::string> &arguments ) = 0; |
|
12 |
+ virtual int setcred(pam_handle_t *handle, int flags, const std::vector<const std::string> &arguments) = 0; |
|
13 |
+}; |
|
14 |
+ |
|
15 |
+class dual_control : public dual_control_ifc { |
|
16 |
+ private: |
|
17 |
+ std::shared_ptr<dual_control_ifc> delegate_; |
|
18 |
+ public: |
|
19 |
+ int authenticate(pam_handle_t *handle, int flags, const std::vector<const std::string> &arguments ) { |
|
20 |
+ return delegate_->authenticate(handle, flags, arguments); |
|
21 |
+ } |
|
22 |
+ int setcred(pam_handle_t *handle, int flags, const std::vector<const std::string> &arguments) { |
|
23 |
+ return delegate_->setcred(handle, flags, arguments); |
|
24 |
+ } |
|
25 |
+}; |
|
26 |
+ |
|
27 |
+#endif |
|
28 |
+ |