gwenhywfar  4.99.8beta
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  GWEN_DB_NODE *db;
31  const char *folder;
32  GWEN_MDIGEST *md;
33  int rv;
34  const GWEN_ARGS args[]={
35  {
36  GWEN_ARGS_FLAGS_HAS_ARGUMENT, /* flags */
37  GWEN_ArgsType_Char, /* type */
38  "folder", /* name */
39  1, /* minnum */
40  1, /* maxnum */
41  "d", /* short option */
42  "dir", /* long option */
43  "Specify folder to check", /* short description */
44  "Specify folder to check" /* long description */
45  },
46  {
48  GWEN_ArgsType_Int, /* type */
49  "help", /* name */
50  0, /* minnum */
51  0, /* maxnum */
52  "h", /* short option */
53  "help", /* long option */
54  "Show this help screen", /* short description */
55  "Show this help screen" /* long description */
56  }
57  };
58 
59  db=GWEN_DB_GetGroup(dbArgs, GWEN_DB_FLAGS_DEFAULT, "local");
60  rv=GWEN_Args_Check(argc, argv, 1,
62  args,
63  db);
64  if (rv==GWEN_ARGS_RESULT_ERROR) {
65  fprintf(stderr, "ERROR: Could not parse arguments\n");
66  return 1;
67  }
68  else if (rv==GWEN_ARGS_RESULT_HELP) {
69  GWEN_BUFFER *ubuf;
70 
71  ubuf=GWEN_Buffer_new(0, 1024, 0, 1);
72  if (GWEN_Args_Usage(args, ubuf, GWEN_ArgsOutType_Txt)) {
73  fprintf(stderr, "ERROR: Could not create help string\n");
74  return 1;
75  }
76  fprintf(stderr, "%s\n", GWEN_Buffer_GetStart(ubuf));
77  GWEN_Buffer_free(ubuf);
78  return 0;
79  }
80 
81  folder=GWEN_DB_GetCharValue(db, "folder", 0, NULL);
82  assert(folder);
83 
84  /* check hash list */
86  rv=GWEN_MDigest_CheckFileTree(md, folder, "checksums.rmd", 0, 0);
87  if (rv<0) {
88  fprintf(stderr, "ERROR: Integrity check failed");
90  return 2;
91  }
93 
94  fprintf(stdout, "All files found (passed)\n");
95 
96  return 0;
97 }
98 
99 
100 
char * GWEN_Buffer_GetStart(const GWEN_BUFFER *bf)
Definition: buffer.c:223
void GWEN_MDigest_free(GWEN_MDIGEST *md)
Definition: mdigest.c:53
struct GWEN_DB_NODE GWEN_DB_NODE
Definition: db.h:228
#define NULL
Definition: binreloc.c:290
#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:38
#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:152
int GWEN_MDigest_CheckFileTree(GWEN_MDIGEST *md, const char *folder, const char *checksumFile, int strictCheck, uint32_t pid)
Definition: mdigest.c:478
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:897
GWEN_DB_NODE * GWEN_DB_GetGroup(GWEN_DB_NODE *n, uint32_t flags, const char *path)
Definition: db.c:1260
void GWEN_Buffer_free(GWEN_BUFFER *bf)
Definition: buffer.c:83
struct GWEN_BUFFER GWEN_BUFFER
A dynamically resizeable text buffer.
Definition: buffer.h:41
#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