git.fiddlerwoaroof.com
Browse code

prototype conversation

Greg Wiley authored on 04/04/2017 22:32:17
Showing 2 changed files
... ...
@@ -7,7 +7,7 @@ MODULELIB = pam_dual_control.so
7 7
 UNAME_S := $(shell uname -s)
8 8
 
9 9
 .PHONY: all
10
-all: test dual_control.a
10
+all: dual_control.a
11 11
 
12 12
 dual_control.a: $(MODULEOBJS)
13 13
 	ar rvs $@ $^
... ...
@@ -26,7 +26,7 @@ distclean: clean
26 26
 	@rm -f Makefile config.h
27 27
 
28 28
 dual_control_test: dual_control_test.c $(LOGICOBJS)
29
-	$(CC) $(CFLAGS) $(CPPFLAGS) -o $@ $^
29
+	$(CC) $(CFLAGS) $(CPPFLAGS) -lpam -o $@ $^
30 30
 
31 31
 .PHONY: test
32 32
 test: dual_control_test
... ...
@@ -36,7 +36,7 @@ test: dual_control_test
36 36
 .PHONY: install
37 37
 install: $(MODULEOBJS)
38 38
 ifeq ($(UNAME_S), Linux)
39
-	ld $(LDFLAGS) -x --shared -o $(DESTDIR)@PAM_MODULE_DIRECTORY@/$(MODULELIB) $(MODULEOBJS)
39
+	ld $(LDFLAGS) -x --shared -lpam -o $(DESTDIR)@PAM_MODULE_DIRECTORY@/$(MODULELIB) $(MODULEOBJS)
40 40
 else
41 41
 	@echo installation recipe not known for $(UNAME_S)
42 42
 endif
... ...
@@ -12,7 +12,30 @@ PAM_EXTERN int pam_sm_authenticate(pam_handle_t *pamh, int flags, int argc, cons
12 12
     printf("Authentication\n");
13 13
     log_dual_control();
14 14
 
15
-    return PAM_SUCCESS;
15
+    struct pam_conv *conversation;
16
+    int get_item_result = pam_get_item(pamh, PAM_CONV, (void *)&conversation);
17
+    if (get_item_result != PAM_SUCCESS) {
18
+        return get_item_result;
19
+    }
20
+
21
+    struct pam_message msg1;
22
+    msg1.msg_style = PAM_PROMPT_ECHO_ON;
23
+    msg1.msg = "Birthday: ";
24
+
25
+    struct pam_message *messages[1];
26
+    messages[0] = &msg1;
27
+
28
+
29
+    struct pam_response *responses[1];
30
+
31
+
32
+    int conversation_result  = conversation->conv(1, &messages, &responses, conversation->appdata_ptr);
33
+    if (conversation_result != PAM_SUCCESS) {
34
+        return conversation_result;
35
+    }
36
+
37
+   printf("code: %d   response: %s\n", responses[0]->resp_retcode, responses[0]->resp);
38
+   return PAM_SUCCESS;
16 39
 }
17 40
 
18 41
 PAM_EXTERN int pam_sm_setcred(pam_handle_t *pamh, int flags, int argc, const char **argv) {