1 #define _XOPEN_SOURCE 500
11 int main(int argc
, char **argv
) {
12 struct isds_ctx
*ctx
= NULL
;
14 const char *request_url
= url
;
15 const char *request_username
= username();
16 const char *request_password
= password();
20 setlocale(LC_ALL
, "");
23 if (argc
< 4 || argc
> 6) {
24 printf("Usage: %s [URL LOGIN PASSWORD [{hotp OTP_CODE} | {totp [OTP_CODE]}]\n",
25 (argv
[0])?argv
[0]: "");
29 request_url
= argv
[1];
30 request_username
= argv
[2];
31 request_password
= argv
[3];
35 if (!strcmp(argv
[4], "hotp")) otp
.method
= OTP_HMAC
;
36 else if (!strcmp(argv
[4], "totp")) otp
.method
= OTP_TIME
;
38 printf("Bad invocation: %s: Unknown OTP method\n", argv
[4]);
41 if (argc
> 5) otp
.otp_code
= argv
[5];
42 else otp
.otp_code
= NULL
;
49 printf("isds_init() failed: %s\n", isds_strerror(err
));
53 isds_set_logging(ILF_ALL
, ILL_ALL
);
55 ctx
= isds_ctx_create();
57 printf("isds_ctx_create() failed");
60 err
= isds_set_timeout(ctx
, 10000);
62 printf("isds_set_timeout() failed: %s\n", isds_strerror(err
));
65 err
= isds_login(ctx
, request_url
, request_username
, request_password
,
66 NULL
, (use_otp
) ? &otp
: NULL
);
67 if (err
== IE_PARTIAL_SUCCESS
) {
68 printf("isds_login() partially succeeded: %s: %s\n", isds_strerror(err
),
69 isds_long_message(ctx
));
70 if (use_otp
&& otp
.resolution
== OTP_RESOLUTION_TOTP_SENT
)
71 printf("Redo log-in with OTP code to finish log-in procedure.\n");
74 printf("isds_login() failed: %s: %s\n", isds_strerror(err
),
75 isds_long_message(ctx
));
77 printf("Logged in :)\n");
81 err
= isds_logout(ctx
);
83 printf("isds_logout() failed: %s\n", isds_strerror(err
));
87 err
= isds_ctx_free(&ctx
);
89 printf("isds_ctx_free() failed: %s\n", isds_strerror(err
));
95 printf("isds_cleanup() failed: %s\n", isds_strerror(err
));