-
Notifications
You must be signed in to change notification settings - Fork 76
/
Copy pathextrameta.c
166 lines (157 loc) · 3.1 KB
/
extrameta.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
#include "../burp.h"
#include "../alloc.h"
#include "../bfile.h"
#include "../cmd.h"
#include "../conf.h"
#include "../log.h"
#include "acl.h"
#include "cvss.h"
#include "extrameta.h"
#include "xattr.h"
int has_extrameta(const char *path, enum cmd cmd,
int enable_acl, int enable_xattr)
{
#if defined(WIN32_VSS)
return 1;
#endif
#if defined(HAVE_LINUX_OS) || \
defined(HAVE_FREEBSD_OS) || \
defined(HAVE_NETBSD_OS)
#ifdef HAVE_ACL
if(enable_acl && has_acl(path, cmd))
return 1;
#endif
#endif
#if defined(HAVE_LINUX_OS) || \
defined(HAVE_FREEBSD_OS) || \
defined(HAVE_NETBSD_OS) || \
defined(HAVE_DARWIN_OS)
#ifdef HAVE_XATTR
if(enable_xattr && has_xattr(path))
return 1;
#endif
#endif
return 0;
}
int get_extrameta(struct asfd *asfd,
#ifdef HAVE_WIN32
struct BFILE *bfd,
#endif
const char *path,
int isdir,
char **extrameta,
size_t *elen,
struct cntr *cntr)
{
#if defined (WIN32_VSS)
if(get_vss(bfd, extrameta, elen))
return -1;
#endif
// Important to do xattr directly after acl, because xattr is excluding
// some entries if acls were set.
#if defined(HAVE_LINUX_OS) || \
defined(HAVE_FREEBSD_OS) || \
defined(HAVE_NETBSD_OS)
#ifdef HAVE_ACL
if(get_acl(asfd, path, isdir, extrameta, elen, cntr))
return -1;
#endif
#endif
#if defined(HAVE_LINUX_OS) || \
defined(HAVE_FREEBSD_OS) || \
defined(HAVE_NETBSD_OS) || \
defined(HAVE_DARWIN_OS)
#ifdef HAVE_XATTR
if(get_xattr(asfd, path, extrameta, elen, cntr))
return -1;
#endif
#endif
return 0;
}
int set_extrameta(struct asfd *asfd,
#ifdef HAVE_WIN32
struct BFILE *bfd,
#endif
const char *path,
const char *extrameta,
size_t metalen,
struct cntr *cntr)
{
size_t l=0;
char cmdtmp='\0';
unsigned int s=0;
const char *metadata=NULL;
int errors=0;
metadata=extrameta;
l=metalen;
while(l>0)
{
char *m=NULL;
if((sscanf(metadata, "%c%08X", &cmdtmp, &s))!=2)
{
logw(asfd, cntr,
"sscanf of metadata failed for %s: %s\n",
path, metadata);
return -1;
}
metadata+=9;
l-=9;
if(!(m=(char *)malloc_w(s+1, __func__)))
return -1;
memcpy(m, metadata, s);
m[s]='\0';
metadata+=s;
l-=s;
switch(cmdtmp)
{
#if defined(HAVE_WIN32)
case META_VSS:
if(set_vss(bfd, m, s))
errors++;
break;
#endif
#if defined(HAVE_LINUX_OS) || \
defined(HAVE_FREEBSD_OS) || \
defined(HAVE_NETBSD_OS)
#ifdef HAVE_ACL
case META_ACCESS_ACL:
if(set_acl(asfd, path, m, cmdtmp, cntr))
errors++;
break;
case META_DEFAULT_ACL:
if(set_acl(asfd, path, m, cmdtmp, cntr))
errors++;
break;
#endif
#endif
#if defined(HAVE_LINUX_OS) || \
defined(HAVE_DARWIN_OS)
#ifdef HAVE_XATTR
case META_XATTR:
if(set_xattr(asfd,
path, m, s, cmdtmp, cntr))
errors++;
break;
#endif
#endif
#if defined(HAVE_FREEBSD_OS) || \
defined(HAVE_NETBSD_OS)
#ifdef HAVE_XATTR
case META_XATTR_BSD:
if(set_xattr(asfd,
path, m, s, cmdtmp, cntr))
errors++;
break;
#endif
#endif
default:
logp("unknown metadata: %c\n", cmdtmp);
logw(asfd, cntr,
"unknown metadata: %c\n", cmdtmp);
errors++;
break;
}
free_w(&m);
}
return errors;
}