1 /***************************************************************************
2 begin : Tue Sep 20 2008
3 copyright : (C) 2008 by Patrick Prasse
4 copyright : (C) 2018 by Martin Preuss
5 email : patrick-oss@prasse.info
6
7 ***************************************************************************
8 * Please see toplevel file COPYING for license details *
9 ***************************************************************************/
10
11 #ifdef HAVE_CONFIG_H
12 # include <config.h>
13 #endif
14
15
16 #include "globals_l.h"
17 #include "aqhbci/banking/user.h"
18
19 #include <gwenhywfar/text.h>
20 #include <gwenhywfar/url.h>
21 #include <gwenhywfar/ct.h>
22 #include <gwenhywfar/ctplugin.h>
23
24
25
26
AH_Control_DelUser(AB_PROVIDER * pro,GWEN_DB_NODE * dbArgs,int argc,char ** argv)27 int AH_Control_DelUser(AB_PROVIDER *pro,
28 GWEN_DB_NODE *dbArgs,
29 int argc,
30 char **argv)
31 {
32 GWEN_DB_NODE *db;
33 AB_USER *u=NULL;
34 uint32_t uid;
35 int rv;
36 uint32_t pretend = 0;
37 const GWEN_ARGS args[]= {
38 {
39 GWEN_ARGS_FLAGS_HAS_ARGUMENT, /* flags */
40 GWEN_ArgsType_Int, /* type */
41 "userId", /* name */
42 0, /* minnum */
43 1, /* maxnum */
44 "u", /* short option */
45 "user", /* long option */
46 "Specify the unique user id", /* short description */
47 "Specify the unique user id" /* long description */
48 },
49 {
50 0, /* flags */
51 GWEN_ArgsType_Int, /* type */
52 "pretend", /* name */
53 0, /* minnum */
54 1, /* maxnum */
55 "p", /* short option */
56 "pretend", /* long option */
57 "Only print user, don't delete", /* short description */
58 "Only print user, don't delete" /* long description */
59 },
60 {
61 GWEN_ARGS_FLAGS_HELP | GWEN_ARGS_FLAGS_LAST, /* flags */
62 GWEN_ArgsType_Int, /* type */
63 "help", /* name */
64 0, /* minnum */
65 0, /* maxnum */
66 "h", /* short option */
67 "help", /* long option */
68 "Show this help screen", /* short description */
69 "Show this help screen" /* long description */
70 }
71 };
72
73 db=GWEN_DB_GetGroup(dbArgs, GWEN_DB_FLAGS_DEFAULT, "local");
74 rv=GWEN_Args_Check(argc, argv, 1,
75 0 /*GWEN_ARGS_MODE_ALLOW_FREEPARAM*/,
76 args,
77 db);
78 if (rv==GWEN_ARGS_RESULT_ERROR) {
79 fprintf(stderr, "ERROR: Could not parse arguments\n");
80 return 1;
81 }
82 else if (rv==GWEN_ARGS_RESULT_HELP) {
83 GWEN_BUFFER *ubuf;
84
85 ubuf=GWEN_Buffer_new(0, 1024, 0, 1);
86 if (GWEN_Args_Usage(args, ubuf, GWEN_ArgsOutType_Txt)) {
87 fprintf(stderr, "ERROR: Could not create help string\n");
88 return 1;
89 }
90 fprintf(stdout, "%s\n", GWEN_Buffer_GetStart(ubuf));
91 GWEN_Buffer_free(ubuf);
92 return 0;
93 }
94
95 uid=(uint32_t) GWEN_DB_GetIntValue(db, "userId", 0, 0);
96 if (uid==0) {
97 fprintf(stderr, "ERROR: Invalid or missing unique user id\n");
98 return 1;
99 }
100
101 pretend=GWEN_DB_GetIntValue(db, "pretend", 0, 0);
102
103 rv=AB_Provider_HasUser(pro, uid);
104 if (rv<0) {
105 fprintf(stderr, "ERROR: User with id %lu not found\n", (unsigned long int) uid);
106 return 2;
107 }
108 rv=AB_Provider_GetUser(pro, uid, 1, 1, &u);
109 if (rv<0) {
110 fprintf(stderr, "ERROR: User with id %lu not found\n", (unsigned long int) uid);
111 return 2;
112 }
113
114 if (pretend) {
115 fprintf(stdout, "User 0: Bank: %s/%s User Id: %s Customer Id: %s Unique Id: %lu\n",
116 AB_User_GetCountry(u),
117 AB_User_GetBankCode(u),
118 AB_User_GetUserId(u),
119 AB_User_GetCustomerId(u),
120 (unsigned long int) AB_User_GetUniqueId(u));
121 }
122 else {
123 rv=AB_Provider_DeleteUser(pro, uid);
124 if (rv<0) {
125 fprintf(stderr, "ERROR: Could not delete user %lu (%d)\n", (unsigned long int) uid, rv);
126 AB_User_free(u);
127 return 2;
128 }
129 }
130 AB_User_free(u);
131
132 return 0;
133 }
134
135
136
137
138
139