gwenhywfar  5.10.1
checktree.c
Go to the documentation of this file.
1 /***************************************************************************
2  begin : Tue Jun 01 2010
3  copyright : (C) 2010 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 #include "globals.h"
15 
16 #include <gwenhywfar/debug.h>
17 #include <gwenhywfar/ct.h>
18 #include <gwenhywfar/ctplugin.h>
19 #include <gwenhywfar/text.h>
20 #include <gwenhywfar/mdigest.h>
21 #include <gwenhywfar/syncio.h>
22 #include <gwenhywfar/syncio_file.h>
23 #include <gwenhywfar/syncio_buffered.h>
24 
25 
26 
27 
28 
29 int checkTree(GWEN_DB_NODE *dbArgs, int argc, char **argv)
30 {
31  GWEN_DB_NODE *db;
32  const char *folder;
33  GWEN_MDIGEST *md;
34  int rv;
35  const GWEN_ARGS args[]= {
36  {
37  GWEN_ARGS_FLAGS_HAS_ARGUMENT, /* flags */
38  GWEN_ArgsType_Char, /* type */
39  "folder", /* name */
40  1, /* minnum */
41  1, /* maxnum */
42  "d", /* short option */
43  "dir", /* long option */
44  "Specify folder to check", /* short description */
45  "Specify folder to check" /* long description */
46  },
47  {
49  GWEN_ArgsType_Int, /* type */
50  "help", /* name */
51  0, /* minnum */
52  0, /* maxnum */
53  "h", /* short option */
54  "help", /* long option */
55  "Show this help screen", /* short description */
56  "Show this help screen" /* long description */
57  }
58  };
59 
60  db=GWEN_DB_GetGroup(dbArgs, GWEN_DB_FLAGS_DEFAULT, "local");
61  rv=GWEN_Args_Check(argc, argv, 1,
63  args,
64  db);
65  if (rv==GWEN_ARGS_RESULT_ERROR) {
66  fprintf(stderr, "ERROR: Could not parse arguments\n");
67  return 1;
68  }
69  else if (rv==GWEN_ARGS_RESULT_HELP) {
70  GWEN_BUFFER *ubuf;
71 
72  ubuf=GWEN_Buffer_new(0, 1024, 0, 1);
73  if (GWEN_Args_Usage(args, ubuf, GWEN_ArgsOutType_Txt)) {
74  fprintf(stderr, "ERROR: Could not create help string\n");
75  return 1;
76  }
77  fprintf(stderr, "%s\n", GWEN_Buffer_GetStart(ubuf));
78  GWEN_Buffer_free(ubuf);
79  return 0;
80  }
81 
82  folder=GWEN_DB_GetCharValue(db, "folder", 0, NULL);
83  assert(folder);
84 
85  /* check hash list */
87  rv=GWEN_MDigest_CheckFileTree(md, folder, "checksums.rmd", 0, 0);
88  if (rv<0) {
89  fprintf(stderr, "ERROR: Integrity check failed");
91  return 2;
92  }
94 
95  fprintf(stdout, "All files found (passed)\n");
96 
97  return 0;
98 }
99 
100 
101 
char * GWEN_Buffer_GetStart(const GWEN_BUFFER *bf)
Definition: buffer.c:235
void GWEN_MDigest_free(GWEN_MDIGEST *md)
Definition: mdigest.c:54
struct GWEN_DB_NODE GWEN_DB_NODE
Definition: db.h:228
#define NULL
Definition: binreloc.c:300
#define GWEN_ARGS_FLAGS_HELP
Definition: src/base/args.h:52
GWEN_BUFFER * GWEN_Buffer_new(char *buffer, uint32_t size, uint32_t used, int take)
Definition: buffer.c:42
#define GWEN_ARGS_RESULT_HELP
Definition: src/base/args.h:58
#define GWEN_ARGS_RESULT_ERROR
Definition: src/base/args.h:57
GWENHYWFAR_API GWEN_MDIGEST * GWEN_MDigest_Rmd160_new(void)
Definition: mdigestgc.c:158
int GWEN_MDigest_CheckFileTree(GWEN_MDIGEST *md, const char *folder, const char *checksumFile, int strictCheck, uint32_t pid)
Definition: mdigest.c:543
int GWEN_Args_Usage(const GWEN_ARGS *args, GWEN_BUFFER *ubuf, GWEN_ARGS_OUTTYPE ot)
struct GWEN_MDIGEST GWEN_MDIGEST
Definition: mdigest.h:25
#define GWEN_ARGS_MODE_ALLOW_FREEPARAM
Definition: src/base/args.h:54
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
void GWEN_Buffer_free(GWEN_BUFFER *bf)
Definition: buffer.c:89
struct GWEN_BUFFER GWEN_BUFFER
A dynamically resizeable text buffer.
Definition: buffer.h:38
#define GWEN_ARGS_FLAGS_LAST
Definition: src/base/args.h:51
int GWEN_Args_Check(int argc, char **argv, int startAt, uint32_t mode, const GWEN_ARGS *args, GWEN_DB_NODE *db)
Definition: src/base/args.c:45
int checkTree(GWEN_DB_NODE *dbArgs, int argc, char **argv)
Definition: checktree.c:29
#define GWEN_ARGS_FLAGS_HAS_ARGUMENT
Definition: src/base/args.h:50
#define GWEN_DB_FLAGS_DEFAULT
Definition: db.h:168