gwenhywfar 5.14.1
changepin.c
Go to the documentation of this file.
1/***************************************************************************
2 $RCSfile$
3 -------------------
4 cvs : $Id: create.c 892 2005-11-03 00:20:45Z aquamaniac $
5 begin : Tue May 03 2005
6 copyright : (C) 2005 by Martin Preuss
7 email : martin@libchipcard.de
8
9 ***************************************************************************
10 * Please see toplevel file COPYING for license details *
11 ***************************************************************************/
12
13#ifdef HAVE_CONFIG_H
14# include <config.h>
15#endif
16
17#include "globals.h"
18
19#include <gwenhywfar/debug.h>
20#include <gwenhywfar/ct.h>
21#include <gwenhywfar/ctplugin.h>
22#include <gwenhywfar/text.h>
23
24
25
26
27int changePin(GWEN_DB_NODE *dbArgs, int argc, char **argv)
28{
29 GWEN_DB_NODE *db;
30 const char *ttype;
31 const char *tname;
33 int rv;
34 int admin;
35 const GWEN_ARGS args[]= {
36 {
38 GWEN_ArgsType_Char, /* type */
39 "tokenType", /* name */
40 1, /* minnum */
41 1, /* maxnum */
42 "t", /* short option */
43 "ttype", /* long option */
44 "Specify the crypt token type", /* short description */
45 "Specify the crypt token type" /* long description */
46 },
47 {
49 GWEN_ArgsType_Char, /* type */
50 "tokenName", /* name */
51 0, /* minnum */
52 1, /* maxnum */
53 "n", /* short option */
54 "tname", /* long option */
55 "Specify the crypt token name", /* short description */
56 "Specify the crypt token name" /* long description */
57 },
58 {
59 0, /* flags */
61 "admin",
62 0,
63 1,
64 "a",
65 "admin",
66 "Change the admin pin instead of the access pin",
67 "Change the admin pin instead of the access pin"
68 },
69 {
71 GWEN_ArgsType_Int, /* type */
72 "help", /* name */
73 0, /* minnum */
74 0, /* maxnum */
75 "h", /* short option */
76 "help", /* long option */
77 "Show this help screen", /* short description */
78 "Show this help screen" /* long description */
79 }
80 };
81
82 db=GWEN_DB_GetGroup(dbArgs, GWEN_DB_FLAGS_DEFAULT, "local");
83 rv=GWEN_Args_Check(argc, argv, 1,
85 args,
86 db);
87 if (rv==GWEN_ARGS_RESULT_ERROR) {
88 fprintf(stderr, "ERROR: Could not parse arguments\n");
89 return 1;
90 }
91 else if (rv==GWEN_ARGS_RESULT_HELP) {
92 GWEN_BUFFER *ubuf;
93
94 ubuf=GWEN_Buffer_new(0, 1024, 0, 1);
95 if (GWEN_Args_Usage(args, ubuf, GWEN_ArgsOutType_Txt)) {
96 fprintf(stderr, "ERROR: Could not create help string\n");
97 return 1;
98 }
99 fprintf(stderr, "%s\n", GWEN_Buffer_GetStart(ubuf));
100 GWEN_Buffer_free(ubuf);
101 return 0;
102 }
103
104 ttype=GWEN_DB_GetCharValue(db, "tokenType", 0, 0);
105 assert(ttype);
106
107 tname=GWEN_DB_GetCharValue(db, "tokenName", 0, 0);
108
109 admin=GWEN_DB_GetIntValue(db, "admin", 0, 0);
110
111 /* get crypt token */
112 ct=getCryptToken(ttype, tname);
113 if (ct==0)
114 return 3;
115
116 if (GWEN_DB_GetIntValue(dbArgs, "forcePin", 0, 0))
118
119 /* open crypt token for use */
120 rv=GWEN_Crypt_Token_Open(ct, 0, 0);
121 if (rv) {
122 DBG_ERROR(0, "Could not open token");
123 return 3;
124 }
125
126 /* change pin */
127 rv=GWEN_Crypt_Token_ChangePin(ct, admin, 0);
128 if (rv) {
129 DBG_ERROR(0, "Could not change pin");
130 return 3;
131 }
132
133 /* close crypt token */
134 rv=GWEN_Crypt_Token_Close(ct, 0, 0);
135 if (rv) {
136 DBG_ERROR(0, "Could not close token");
137 return 3;
138 }
139
140 fprintf(stderr, "Crypt Token updated.\n");
141
142 return 0;
143}
144
145
146
GWEN_BUFFER * GWEN_Buffer_new(char *buffer, uint32_t size, uint32_t used, int take)
Definition buffer.c:42
void GWEN_Buffer_free(GWEN_BUFFER *bf)
Definition buffer.c:89
char * GWEN_Buffer_GetStart(const GWEN_BUFFER *bf)
Definition buffer.c:235
int changePin(GWEN_DB_NODE *dbArgs, int argc, char **argv)
Definition changepin.c:27
int GWEN_Crypt_Token_Open(GWEN_CRYPT_TOKEN *ct, int admin, uint32_t gid)
Definition ct.c:222
int GWEN_Crypt_Token_Close(GWEN_CRYPT_TOKEN *ct, int abandon, uint32_t gid)
Definition ct.c:265
int GWEN_Crypt_Token_ChangePin(GWEN_CRYPT_TOKEN *ct, int admin, uint32_t gid)
Definition ct.c:534
void GWEN_Crypt_Token_AddModes(GWEN_CRYPT_TOKEN *ct, uint32_t f)
Definition ct.c:202
#define GWEN_CRYPT_TOKEN_MODE_FORCE_PIN_ENTRY
Definition ct.h:59
struct GWEN_CRYPT_TOKEN GWEN_CRYPT_TOKEN
Definition ct.h:19
const char * GWEN_DB_GetCharValue(GWEN_DB_NODE *n, const char *path, int idx, const char *defVal)
Definition db.c:971
GWEN_DB_NODE * GWEN_DB_GetGroup(GWEN_DB_NODE *n, uint32_t flags, const char *path)
Definition db.c:1381
int GWEN_DB_GetIntValue(GWEN_DB_NODE *n, const char *path, int idx, int defVal)
Definition db.c:1163
#define GWEN_DB_FLAGS_DEFAULT
Definition db.h:168
struct GWEN_DB_NODE GWEN_DB_NODE
Definition db.h:228
#define DBG_ERROR(dbg_logger, format,...)
Definition debug.h:97
GWEN_CRYPT_TOKEN * getCryptToken(const char *ttype, const char *tname)
struct GWEN_BUFFER GWEN_BUFFER
A dynamically resizeable text buffer.
Definition buffer.h:38
int GWEN_Args_Check(int argc, char **argv, int startAt, uint32_t mode, const GWEN_ARGS *args, GWEN_DB_NODE *db)
int GWEN_Args_Usage(const GWEN_ARGS *args, GWEN_BUFFER *ubuf, GWEN_ARGS_OUTTYPE ot)
#define GWEN_ARGS_FLAGS_HAS_ARGUMENT
#define GWEN_ARGS_RESULT_ERROR
#define GWEN_ARGS_MODE_ALLOW_FREEPARAM
#define GWEN_ARGS_FLAGS_HELP
#define GWEN_ARGS_FLAGS_LAST
@ GWEN_ArgsOutType_Txt
@ GWEN_ArgsType_Int
@ GWEN_ArgsType_Char
#define GWEN_ARGS_RESULT_HELP