gwenhywfar 5.12.0
update.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
27
28
29int updateToken(GWEN_DB_NODE *dbArgs, int argc, char **argv)
30{
31 GWEN_DB_NODE *db;
32 const char *ttype;
33 const char *tname;
35 int rv;
36 const GWEN_ARGS args[]= {
37 {
39 GWEN_ArgsType_Char, /* type */
40 "tokenType", /* name */
41 1, /* minnum */
42 1, /* maxnum */
43 "t", /* short option */
44 "ttype", /* long option */
45 "Specify the crypt token type", /* short description */
46 "Specify the crypt token type" /* long description */
47 },
48 {
50 GWEN_ArgsType_Char, /* type */
51 "tokenName", /* name */
52 0, /* minnum */
53 1, /* maxnum */
54 "n", /* short option */
55 "tname", /* long option */
56 "Specify the crypt token name", /* short description */
57 "Specify the crypt token name" /* long description */
58 },
59 {
61 GWEN_ArgsType_Int, /* type */
62 "help", /* name */
63 0, /* minnum */
64 0, /* maxnum */
65 "h", /* short option */
66 "help", /* long option */
67 "Show this help screen", /* short description */
68 "Show this help screen" /* long description */
69 }
70 };
71
72 db=GWEN_DB_GetGroup(dbArgs, GWEN_DB_FLAGS_DEFAULT, "local");
73 rv=GWEN_Args_Check(argc, argv, 1,
75 args,
76 db);
77 if (rv==GWEN_ARGS_RESULT_ERROR) {
78 fprintf(stderr, "ERROR: Could not parse arguments\n");
79 return 1;
80 }
81 else if (rv==GWEN_ARGS_RESULT_HELP) {
82 GWEN_BUFFER *ubuf;
83
84 ubuf=GWEN_Buffer_new(0, 1024, 0, 1);
85 if (GWEN_Args_Usage(args, ubuf, GWEN_ArgsOutType_Txt)) {
86 fprintf(stderr, "ERROR: Could not create help string\n");
87 return 1;
88 }
89 fprintf(stderr, "%s\n", GWEN_Buffer_GetStart(ubuf));
90 GWEN_Buffer_free(ubuf);
91 return 0;
92 }
93
94 ttype=GWEN_DB_GetCharValue(db, "tokenType", 0, 0);
95 assert(ttype);
96
97 tname=GWEN_DB_GetCharValue(db, "tokenName", 0, 0);
98
99 /* get crypt token */
100 ct=getCryptToken(ttype, tname);
101 if (ct==0)
102 return 3;
103
104 if (GWEN_DB_GetIntValue(dbArgs, "forcePin", 0, 0))
106
107 /* allow update of key file */
109
110 /* open crypt token for use */
111 rv=GWEN_Crypt_Token_Open(ct, 0, 0);
112 if (rv) {
113 DBG_ERROR(0, "Could not open token");
114 return 3;
115 }
116
117 /* close crypt token */
118 rv=GWEN_Crypt_Token_Close(ct, 0, 0);
119 if (rv) {
120 DBG_ERROR(0, "Could not close token");
121 return 3;
122 }
123
124 fprintf(stderr, "Crypt Token updated.\n");
125
126 return 0;
127}
128
129
130
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 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
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
#define GWEN_CRYPT_TOKEN_MODE_ALLOW_UPDATE
Definition ct.h:61
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
int updateToken(GWEN_DB_NODE *dbArgs, int argc, char **argv)
Definition update.c:29