-
Notifications
You must be signed in to change notification settings - Fork 0
/
extattr_delete_file.c
78 lines (62 loc) · 1.67 KB
/
extattr_delete_file.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
/*
* Copyright 2022-2024 Gaël PORTAY
*
* SPDX-License-Identifier: LGPL-2.1-or-later
*/
#if defined __FreeBSD__ || defined __NetBSD__
#include <stdio.h>
#include <errno.h>
#include <string.h>
#include <limits.h>
#include <fcntl.h>
#include <dlfcn.h>
#if defined __NetBSD__
#include <sys/param.h>
#endif
#include <sys/types.h>
#include <sys/extattr.h>
#include "iamroot.h"
#ifndef EXTATTR_MAXNAMELEN
#define EXTATTR_MAXNAMELEN 255
#endif
static int (*sym)(const char *, int, const char *);
hidden int next_extattr_delete_file(const char *path, int attrnamespace,
const char *attrname)
{
if (!sym)
sym = dlsym(RTLD_NEXT, "extattr_delete_file");
if (!sym)
return __dl_set_errno_and_perror(ENOSYS, -1);
return sym(path, attrnamespace, attrname);
}
int extattr_delete_file(const char *path, int attrnamespace,
const char *attrname)
{
char extbuf[EXTATTR_MAXNAMELEN+1]; /* NULL-terminated */
const int oldattrnamespace = attrnamespace;
const char *oldattrname = attrname;
char buf[PATH_MAX];
int ret = -1;
ssize_t siz;
(void)oldattrnamespace;
(void)oldattrname;
siz = path_resolution(AT_FDCWD, path, buf, sizeof(buf), 0);
if (siz == -1)
goto exit;
if (attrnamespace == EXTATTR_NAMESPACE_SYSTEM) {
int n;
n = _snprintf(extbuf, sizeof(extbuf), "%s%s",
IAMROOT_EXTATTR_PREFIX, attrname);
if (n == -1)
goto exit;
attrnamespace = EXTATTR_NAMESPACE_USER;
attrname = extbuf;
}
ret = next_extattr_delete_file(buf, attrnamespace, attrname);
exit:
__debug("%s(path: '%s' -> '%s', attrnamespace: %i -> %i, attrname: '%s' -> '%s') -> %i\n",
__func__, path, buf, oldattrnamespace, attrnamespace,
oldattrname, attrname, ret);
return ret;
}
#endif