Adapt to OpenSSL 1.1.0
[libisds.git] / client / resetpassword.c
blob468ad8fec00f9eb4d0f2f3061425a094de58945a
1 #define _XOPEN_SOURCE 500
2 #include <stdlib.h>
3 #include <stdio.h>
4 #include <locale.h>
5 #include <time.h>
6 #include <string.h>
7 #include <isds.h>
8 #include "common.h"
10 void reset_password(struct isds_ctx *ctx,
11 const struct isds_DbOwnerInfo *box, const struct isds_DbUserInfo *user,
12 const _Bool paid,
13 struct isds_credentials_delivery *credentials_delivery) {
14 char *refnumber = NULL;
16 printf("Resetting password\n");
17 isds_error err = isds_reset_password(ctx, box, user, paid, NULL,
18 credentials_delivery, &refnumber);
19 if (err) {
20 printf("isds_reset_password() failed: %s: %s\n",
21 isds_strerror(err), isds_long_message(ctx));
22 } else {
23 printf("isds_reset_password() succeeded as request #%s.\n"
24 "This should not happen\n", refnumber);
25 if (credentials_delivery) {
26 printf("email = %s\n", credentials_delivery->email);
27 printf("token = %s\n", credentials_delivery->token);
28 printf("new_user_name = %s\n", credentials_delivery->new_user_name);
31 printf("\n");
32 free(refnumber);
35 int main(void) {
36 struct isds_ctx *ctx = NULL;
37 isds_error err;
38 struct isds_DbOwnerInfo *db_owner_info = NULL;
39 struct isds_DbUserInfo *db_user_info = NULL;
41 setlocale(LC_ALL, "");
43 err = isds_init();
44 if (err) {
45 printf("isds_init() failed: %s\n", isds_strerror(err));
46 exit(EXIT_FAILURE);
49 isds_set_logging(ILF_ALL & ~ILF_HTTP, ILL_ALL);
51 ctx = isds_ctx_create();
52 if (!ctx) {
53 printf("isds_ctx_create() failed");
56 err = isds_set_timeout(ctx, 10000);
57 if (err) {
58 printf("isds_set_timeout() failed: %s\n", isds_strerror(err));
61 err = isds_login(ctx, url, username(), password(), NULL, NULL);
62 if (err) {
63 printf("isds_login() failed: %s: %s\n", isds_strerror(err),
64 isds_long_message(ctx));
65 } else {
66 printf("Logged in :)\n");
71 /* Get info about my box */
72 printf("Getting info about my box:\n");
73 err = isds_GetOwnerInfoFromLogin(ctx, &db_owner_info);
74 if (err) {
75 printf("isds_GetOwnerInfoFromLogin() failed: %s: %s\n",
76 isds_strerror(err), isds_long_message(ctx));
77 } else {
78 printf("isds_GetOwnerInfoFromLogin() succeeded\n");
80 print_DbOwnerInfo(db_owner_info);
84 /* Get info about my account */
85 printf("Getting info about my account:\n");
86 err = isds_GetUserInfoFromLogin(ctx, &db_user_info);
87 if (err) {
88 printf("isds_GetUserInfoFromLogin() failed: %s: %s\n",
89 isds_strerror(err), isds_long_message(ctx));
90 } else {
91 printf("isds_GetUserInfoFromLogin() succeeded\n");
92 print_DbUserInfo(db_user_info);
96 if (db_owner_info && db_user_info) {
97 #if 0
98 struct isds_credentials_delivery credentials_delivery;
99 /* Try some invalid invocation that should fail */
100 reset_password(ctx, db_owner_info, db_user_info, 0, NULL);
101 reset_password(ctx, db_owner_info, db_user_info, 1, NULL);
103 credentials_delivery.email = NULL;
104 credentials_delivery.token = NULL;
105 credentials_delivery.new_user_name = NULL;
106 reset_password(ctx, db_owner_info, db_user_info, 1,
107 &credentials_delivery);
108 free(credentials_delivery.token);
109 free(credentials_delivery.new_user_name);
111 credentials_delivery.email = "42";
112 credentials_delivery.token = NULL;
113 credentials_delivery.new_user_name = NULL;
114 reset_password(ctx, db_owner_info, db_user_info, 1,
115 &credentials_delivery);
116 free(credentials_delivery.token);
117 free(credentials_delivery.new_user_name);
118 #endif
119 fprintf(stderr, "This function can lose current user credentials. "
120 "DO NOT TRY IT!\n");
123 isds_DbOwnerInfo_free(&db_owner_info);
124 isds_DbUserInfo_free(&db_user_info);
127 err = isds_logout(ctx);
128 if (err) {
129 printf("isds_logout() failed: %s\n", isds_strerror(err));
133 err = isds_ctx_free(&ctx);
134 if (err) {
135 printf("isds_ctx_free() failed: %s\n", isds_strerror(err));
139 err = isds_cleanup();
140 if (err) {
141 printf("isds_cleanup() failed: %s\n", isds_strerror(err));
144 exit (EXIT_SUCCESS);