1 /***************************************************************************
2 begin : Thu May 06 2010
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_SetTanMediumId(AB_PROVIDER * pro,GWEN_DB_NODE * dbArgs,int argc,char ** argv)23 int AH_Control_SetTanMediumId(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 const char *tanMediumId;
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_Char, /* type */
48 "tanMediumId", /* name */
49 1, /* minnum */
50 1, /* maxnum */
51 "m", /* short option */
52 "tanmediumid", /* long option */
53 "Specify the TAN medium id", /* short description */
54 "Specify the TAN medium id" /* 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 uid=(uint32_t) GWEN_DB_GetIntValue(db, "userId", 0, 0);
93 if (uid==0) {
94 fprintf(stderr, "ERROR: Invalid or missing unique user id\n");
95 return 1;
96 }
97
98 tanMediumId=GWEN_DB_GetCharValue(db, "tanMediumId", 0, "none");
99
100
101 /* doit */
102 rv=AB_Provider_HasUser(pro, uid);
103 if (rv<0) {
104 fprintf(stderr, "ERROR: User with id %lu not found\n", (unsigned long int) uid);
105 return 2;
106 }
107 rv=AB_Provider_GetUser(pro, uid, 1, 0, &u); /* don't lock to allow for AH_Provider_EndExclUseUser */
108 if (rv<0) {
109 fprintf(stderr, "ERROR: User with id %lu not found\n", (unsigned long int) uid);
110 return 2;
111 }
112 else {
113 /* modify */
114 if (strcasecmp(tanMediumId, "none")==0)
115 AH_User_SetTanMediumId(u, NULL);
116 else
117 AH_User_SetTanMediumId(u, tanMediumId);
118
119 /* unlock user */
120 rv=AB_Provider_EndExclUseUser(pro, u, 0);
121 if (rv<0) {
122 fprintf(stderr, "ERROR: Could not unlock user (%d)\n", rv);
123 AB_Provider_EndExclUseUser(pro, u, 1); /* abort */
124 AB_User_free(u);
125 return 4;
126 }
127 }
128 AB_User_free(u);
129
130 return 0;
131 }
132
133
134
135
136