gwenhywfar 5.12.0
gcttool/create.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/base64.h>
21#include <gwenhywfar/ctplugin.h>
22
23
24
25
26int createToken(GWEN_DB_NODE *dbArgs, int argc, char **argv)
27{
28 GWEN_DB_NODE *db;
29 const char *ttype;
30 const char *tname;
32 GWEN_PLUGIN *pl;
34 int rv;
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 {
60 GWEN_ArgsType_Int, /* type */
61 "help", /* name */
62 0, /* minnum */
63 0, /* maxnum */
64 "h", /* short option */
65 "help", /* long option */
66 "Show this help screen", /* short description */
67 "Show this help screen" /* long description */
68 }
69 };
70
71 db=GWEN_DB_GetGroup(dbArgs, GWEN_DB_FLAGS_DEFAULT, "local");
72 rv=GWEN_Args_Check(argc, argv, 1,
74 args,
75 db);
76 if (rv==GWEN_ARGS_RESULT_ERROR) {
77 fprintf(stderr, "ERROR: Could not parse arguments\n");
78 return 1;
79 }
80 else if (rv==GWEN_ARGS_RESULT_HELP) {
81 GWEN_BUFFER *ubuf;
82
83 ubuf=GWEN_Buffer_new(0, 1024, 0, 1);
84 if (GWEN_Args_Usage(args, ubuf, GWEN_ArgsOutType_Txt)) {
85 fprintf(stderr, "ERROR: Could not create help string\n");
86 return 1;
87 }
88 fprintf(stderr, "%s\n", GWEN_Buffer_GetStart(ubuf));
89 GWEN_Buffer_free(ubuf);
90 return 0;
91 }
92
93 ttype=GWEN_DB_GetCharValue(db, "tokenType", 0, 0);
94 assert(ttype);
95
96 tname=GWEN_DB_GetCharValue(db, "tokenName", 0, 0);
97
98 /* get crypt token */
100 if (pm==0) {
101 DBG_ERROR(0, "Plugin manager not found");
102 return 3;
103 }
104
105 pl=GWEN_PluginManager_GetPlugin(pm, ttype);
106 if (pl==0) {
107 DBG_ERROR(0, "Plugin not found");
108 return 3;
109 }
110 DBG_ERROR(0, "Plugin found");
111
113 if (ct==0) {
114 DBG_ERROR(0, "Could not create crypt token");
115 return 3;
116 }
117
118 /* create crypt token */
119 rv=GWEN_Crypt_Token_Create(ct, 0);
120 if (rv) {
121 DBG_ERROR(0, "Could not create token");
122 return 3;
123 }
124
125 /* close crypt token */
126 rv=GWEN_Crypt_Token_Close(ct, 0, 0);
127 if (rv) {
128 DBG_ERROR(0, "Could not close token");
129 return 3;
130 }
131
132 return 0;
133}
134
135
136
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_Create(GWEN_CRYPT_TOKEN *ct, uint32_t gid)
Definition ct.c:246
int GWEN_Crypt_Token_Close(GWEN_CRYPT_TOKEN *ct, int abandon, uint32_t gid)
Definition ct.c:265
struct GWEN_CRYPT_TOKEN GWEN_CRYPT_TOKEN
Definition ct.h:19
GWEN_CRYPT_TOKEN * GWEN_Crypt_Token_Plugin_CreateToken(GWEN_PLUGIN *pl, const char *name)
Definition ctplugin.c:146
#define GWEN_CRYPT_TOKEN_PLUGIN_TYPENAME
Definition ctplugin.h:24
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
#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
int createToken(GWEN_DB_NODE *dbArgs, int argc, char **argv)
struct GWEN_BUFFER GWEN_BUFFER
A dynamically resizeable text buffer.
Definition buffer.h:38
GWEN_PLUGIN_MANAGER * GWEN_PluginManager_FindPluginManager(const char *s)
Definition plugin.c:545
GWEN_PLUGIN * GWEN_PluginManager_GetPlugin(GWEN_PLUGIN_MANAGER *pm, const char *s)
Definition plugin.c:522
struct GWEN_PLUGIN_MANAGER GWEN_PLUGIN_MANAGER
Definition plugin.h:37
struct GWEN_PLUGIN GWEN_PLUGIN
Definition plugin.h:36
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