1 #define _XOPEN_SOURCE 500
10 void reset_password(struct isds_ctx
*ctx
,
11 const struct isds_DbOwnerInfo
*box
, const struct isds_DbUserInfo
*user
,
12 const _Bool paid
, char **token
) {
13 char *refnumber
= NULL
;
15 printf("Resetting password\n");
16 isds_error err
= isds_reset_password(ctx
, box
, user
, paid
, NULL
, token
,
19 printf("isds_reset_password() failed: %s: %s\n",
20 isds_strerror(err
), isds_long_message(ctx
));
22 printf("isds_reset_password() succeeded as request #%s.\n"
23 "This should not happen\n", refnumber
);
24 if (token
) printf("token = %s\n", *token
);
30 int main(int argc
, char **argv
) {
31 struct isds_ctx
*ctx
= NULL
;
33 struct isds_DbOwnerInfo
*db_owner_info
= NULL
;
34 struct isds_DbUserInfo
*db_user_info
= NULL
;
36 setlocale(LC_ALL
, "");
40 printf("isds_init() failed: %s\n", isds_strerror(err
));
44 isds_set_logging(ILF_ALL
& ~ILF_HTTP
, ILL_ALL
);
46 ctx
= isds_ctx_create();
48 printf("isds_ctx_create() failed");
51 err
= isds_set_timeout(ctx
, 10000);
53 printf("isds_set_timeout() failed: %s\n", isds_strerror(err
));
56 /* err = isds_set_tls(ctx, ITLS_VERIFY_SERVER, 0);
58 printf("isds_set_tls(ITLS_VERIFY_SERVER) failed: %s\n",
62 err = isds_set_tls(ctx, ITLS_CA_FILE, "/etc/ssl/certs/ca-certificates.crt");
64 printf("isds_set_tls(ITLS_CA_FILE) failed: %s\n",
68 err
= isds_login(ctx
, url
, username
, password
, NULL
);
70 printf("isds_login() failed: %s: %s\n", isds_strerror(err
),
71 isds_long_message(ctx
));
73 printf("Logged in :)\n");
78 /* Get info about my box */
79 printf("Getting info about my box:\n");
80 err
= isds_GetOwnerInfoFromLogin(ctx
, &db_owner_info
);
82 printf("isds_GetOwnerInfoFromLogin() failed: %s: %s\n",
83 isds_strerror(err
), isds_long_message(ctx
));
85 printf("isds_GetOwnerInfoFromLogin() succeeded\n");
87 print_DbOwnerInfo(db_owner_info
);
91 /* Get info about my account */
92 printf("Getting info about my account:\n");
93 err
= isds_GetUserInfoFromLogin(ctx
, &db_user_info
);
95 printf("isds_GetUserInfoFromLogin() failed: %s: %s\n",
96 isds_strerror(err
), isds_long_message(ctx
));
98 printf("isds_GetUserInfoFromLogin() succeeded\n");
99 print_DbUserInfo(db_user_info
);
103 if (db_owner_info
&& db_user_info
) {
105 /* Try some invalid invocation that should fail */
107 reset_password(ctx
, db_owner_info
, db_user_info
, 0, NULL
);
108 reset_password(ctx
, db_owner_info
, db_user_info
, 1, NULL
);
109 reset_password(ctx
, db_owner_info
, db_user_info
, 1, &token
);
111 fprintf(stderr
, "This function can lose current user credentials. "
116 isds_DbOwnerInfo_free(&db_owner_info
);
117 isds_DbUserInfo_free(&db_user_info
);
120 err
= isds_logout(ctx
);
122 printf("isds_logout() failed: %s\n", isds_strerror(err
));
126 err
= isds_ctx_free(&ctx
);
128 printf("isds_ctx_free() failed: %s\n", isds_strerror(err
));
132 err
= isds_cleanup();
134 printf("isds_cleanup() failed: %s\n", isds_strerror(err
));