rpm  5.4.15
rpmacl.c
Go to the documentation of this file.
1 
5 #include "system.h"
6 
7 #if defined(HAVE_SYS_ACL_H)
8 #include <sys/acl.h>
9 #endif
10 #include <rpmacl.h>
11 
12 #include "debug.h"
13 
14 #if defined(HAVE_SYS_ACL_H)
15 static inline int __acl_entries(acl_t a)
16 {
17  int count = 0;
18 #if defined(__FreeBSD__) /* XXX others too. HAVE_ACL_ACL_CNT AutoFu? */
19  struct acl * aclp = &a->ats_acl;
20  count = aclp->acl_cnt;
21 #else
22  int id = ACL_FIRST_ENTRY;
23  acl_entry_t ace;
24 
25  while (acl_get_entry(a, id, &ace) > 0) {
26  id = ACL_NEXT_ENTRY;
27  count++;
28  }
29 #endif
30  return count;
31 }
32 #endif /* HAVE_SYS_ACL_H */
33 
35 {
36  rpmRC rc = RPMRC_OK; /* assume success */
37 #if defined(HAVE_SYS_ACL_H)
38  int ifdno = Fileno(ifd);
39  int ofdno = Fileno(ofd);
40  acl_t a = NULL;
41  int count;
42 
43  if (ifdno < 0 || ofdno < 0)
44  goto exit;
45 
46 #if defined(_PC_ACL_EXTENDED)
47  if (fpathconf(ifdno, _PC_ACL_EXTENDED) != 1
48  || fpathconf(ofdno, _PC_ACL_EXTENDED) != 1)
49  goto exit;
50 #endif
51 
52  a = acl_get_fd(ifdno);
53  if (a == NULL)
54  goto exit;
55  count = __acl_entries(a);
56  if (count > 0 && count != 3 && acl_set_fd(ofdno, a) < 0) {
57  rc = RPMRC_FAIL;
58  goto exit;
59  }
60 
61 exit:
62  if (a)
63  acl_free(a);
64 #endif /* HAVE_SYS_ACL_H */
65  return rc;
66 }
67 
68 rpmRC rpmaclCopyDir(const char * sdn, const char * tdn, mode_t mode)
69 {
70  rpmRC rc = RPMRC_OK; /* assume success */
71 #if defined(HAVE_SYS_ACL_H)
72  acl_t (*aclgetf)(const char *, acl_type_t);
73  int (*aclsetf)(const char *, acl_type_t, acl_t);
74  acl_t a = NULL;
75  int count;
76 
77  if (!(sdn && *sdn && tdn && *tdn))
78  goto exit;
79 
80 #if defined(_PC_ACL_EXTENDED)
81  if (pathconf(sdn, _PC_ACL_EXTENDED) != 1
82  || pathconf(tdn, _PC_ACL_EXTENDED) != 1)
83  goto exit;
84 #endif
85 
86 #if defined(__FreeBSD__)
87  /* If the file is a link we will not follow it */
88  if (S_ISLNK(mode)) {
89  aclgetf = acl_get_link_np;
90  aclsetf = acl_set_link_np;
91  } else
92 #endif
93  {
94  aclgetf = acl_get_file;
95  aclsetf = acl_set_file;
96  }
97 
98  /*
99  * Even if there is no ACL_TYPE_DEFAULT entry here, a zero
100  * size ACL will be returned. So it is not safe to simply
101  * check the pointer to see if the default ACL is present.
102  */
103 #if defined(__APPLE__)
104  a = aclgetf(sdn, ACL_TYPE_EXTENDED);
105  if (a == NULL)
106  goto exit;
107 
108  count = __acl_entries(a);
109  if (count > 0 && aclsetf(tdn, ACL_TYPE_DEFAULT, a) < 0) {
110  rc = RPMRC_FAIL;
111  goto exit;
112  }
113 #else
114  a = aclgetf(sdn, ACL_TYPE_DEFAULT);
115  if (a == NULL)
116  goto exit;
117 
118  count = __acl_entries(a);
119  if (count > 0 && aclsetf(tdn, ACL_TYPE_DEFAULT, a) < 0) {
120  rc = RPMRC_FAIL;
121  goto exit;
122  }
123  acl_free(a);
124 
125  a = aclgetf(sdn, ACL_TYPE_ACCESS);
126  if (a == NULL)
127  goto exit;
128  if (aclsetf(tdn, ACL_TYPE_ACCESS, a) < 0) {
129  rc = RPMRC_FAIL;
130  goto exit;
131  }
132 #endif
133 
134 exit:
135  if (a)
136  acl_free(a);
137 #endif /* HAVE_SYS_ACL_H */
138  return rc;
139 }
rpmRC rpmaclCopyDir(const char *sdn, const char *tdn, mode_t mode)
Definition: rpmacl.c:68
#define S_ISLNK(mode)
Definition: system.h:651
rpmRC rpmaclCopyFd(FD_t ifd, FD_t ofd)
Definition: rpmacl.c:34
const char * mode
Definition: mongo.h:440
The FD_t File Handle data structure.
enum rpmRC_e rpmRC
RPM return codes.
int Fileno(FD_t fd)
fileno(3) clone.
Definition: rpmio.c:2998