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