2 #define _XOPEN_SOURCE /* For getopt(3) */
9 #include <sys/select.h>
10 #include <sys/types.h> /* For pid_t */
12 static const char *username
= NULL
;
13 static const char *password
= NULL
;
14 static const char *otp_code
= NULL
;
15 static _Bool terminate
= 0;
16 static int otp_type
= 'n';
19 static void terminator(int signal
) {
23 static void usage(const char *name
) {
24 printf("Usage: %s OPTIONS\n", name
);
33 int main(int argc
, char **argv
) {
36 char *server_address
= NULL
;
39 struct arguments_asws_changePassword_ChangePasswordOTP service_passwdotp_arguments
;
40 struct arguments_DS_DsManage_ChangeISDSPassword service_passwdbase_arguments
;
41 struct service_configuration services
[] = {
42 { SERVICE_END
, NULL
}, /* This entry will be replaced later */
43 { SERVICE_DS_Dz_DummyOperation
, NULL
},
46 struct arguments_basic_authentication server_basic_arguments
;
47 struct arguments_otp_authentication server_otp_arguments
;
50 while (-1 != (option
= getopt(argc
, argv
, "h:p:t:u:"))) {
67 usage((argv
!= NULL
) ? argv
[0] : NULL
);
73 fprintf(stderr
, "Superfluous argument\n");
74 usage((argv
!= NULL
) ? argv
[0] : NULL
);
78 /* Configure server */
79 if (otp_type
== 'n') {
80 service_passwdbase_arguments
.username
= username
;
81 service_passwdbase_arguments
.current_password
= password
;
82 services
[0].name
= SERVICE_DS_DsManage_ChangeISDSPassword
;
83 services
[0].arguments
= &service_passwdbase_arguments
;
84 server_basic_arguments
.username
= username
;
85 server_basic_arguments
.password
= password
;
86 server_basic_arguments
.isds_deviations
= 1;
87 server_basic_arguments
.services
= services
;
89 service_passwdotp_arguments
.username
= username
;
90 service_passwdotp_arguments
.current_password
= password
;
91 services
[0].name
= SERVICE_asws_changePassword_ChangePasswordOTP
;
92 services
[0].arguments
= &service_passwdotp_arguments
;
93 server_otp_arguments
.otp
= otp_code
;
94 if (otp_type
== 't') {
95 server_otp_arguments
.method
= AUTH_OTP_TIME
;
96 } else if (otp_type
== 'h') {
97 server_otp_arguments
.method
= AUTH_OTP_HMAC
;
99 server_otp_arguments
.username
= username
;
100 server_otp_arguments
.password
= password
;
101 server_otp_arguments
.isds_deviations
= 1;
102 server_otp_arguments
.services
= services
;
105 /* Spawn the server */
106 if ((SIG_ERR
== signal(SIGTERM
, terminator
))) {
107 fprintf(stderr
, "Could not register SIGTERM handler\n");
110 if ((SIG_ERR
== signal(SIGCHLD
, terminator
))) {
111 fprintf(stderr
, "Could not register SIGCHLD handler\n");
115 printf("Starting server on:\n");
116 if (otp_type
== 'n') {
117 error
= start_server(&server_process
, &server_address
,
118 server_basic_authentication
, &server_basic_arguments
);
120 error
= start_server(&server_process
, &server_address
,
121 server_otp_authentication
, &server_otp_arguments
);
124 fprintf(stderr
, "Could not start server\n");
125 free(server_address
);
128 printf("http://%s/\n", server_address
);
129 free(server_address
);
131 printf("Waiting on SIGTERM...\n");
133 select(0, NULL
, NULL
, NULL
, NULL
);
136 printf("Terminating...\n");
137 if (-1 == stop_server(server_process
)) {
138 fprintf(stderr
, "Could not stop server: %s\n", server_error
);
142 printf("Terminated.\n");