/var/lib/pcp/testsuite/src/chkacc3.c is in pcp-testsuite 3.8.12ubuntu1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
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 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 | /*
* Copyright (c) 1997-2001 Silicon Graphics, Inc. All Rights Reserved.
* Copyright (c) 2012-2013 Red Hat.
*/
/* Check access control wildcarding, bad ops etc. */
#include <pcp/pmapi.h>
#include <pcp/impl.h>
#include "localconfig.h"
int a[4] = {0, 37, 235, 126};
int b[4] = {0, 201, 77, 127};
int c[4] = {0, 15, 191, 64};
int d[4] = {0, 1, 127, 254};
int
main(int argc, char **argv)
{
int s, sts, op, i, ai, bi, ci, di;
unsigned int perm;
int ipv4 = -1;
int ipv6 = -1;
int errflag = 0;
int copt;
char name[4*8 + 7 + 1]; /* handles full IPv6 address, if supported */
char *wnames[4] = { ".*", "38.*", "38.202.*", "38.202.16.*" };
#if PCP_VER >= 3611
char *wnames6[4] = { ":*", "26:*", "26:ca:*", "26:ca:10:*" };
__pmSockAddr *inaddr;
#else
__pmInAddr inaddr;
__pmIPAddr ipaddr;
#endif
/* trim cmd name of leading directory components */
__pmSetProgname(argv[0]);
while ((copt = getopt(argc, argv, "46D:?")) != EOF) {
switch (copt) {
case '4': /* ipv4 (default) */
ipv4 = 1;
break;
case '6': /* ipv6 */
ipv6 = 1;
break;
case 'D': /* debug flag */
sts = __pmParseDebug(optarg);
if (sts < 0) {
fprintf(stderr, "%s: unrecognized debug flag specification (%s)\n",
pmProgname, optarg);
errflag++;
}
else
pmDebug |= sts;
break;
case '?':
default:
errflag++;
break;
}
}
if (errflag) {
fprintf(stderr,
"Usage: %s [options]\n\
\n\
Options:\n\
-4 do IPv4 (default)\n\
-6 do IPv6\n",
pmProgname);
return 1;
}
/* defaults */
if (ipv4 == -1) ipv4 = 1;
if (ipv6 == -1) ipv6 = 0;
/* there are 10 ops numbered from 0 to 9 */
sts = 0;
for (op = 0; op < 10; op++)
if ((s = __pmAccAddOp(1 << op)) < 0) {
fprintf(stderr, "Bad op %d: %s\n", op, strerror(errno));
sts = s;
}
if (sts < 0)
return 1;
/* every address except address 0.* and 0:* leaves ops 8 and 9 unspecified */
op = 0;
for (ai = 0; ai < 4; ai++)
for (bi = 0; bi < 4; bi++)
for (ci = 0; ci < 4; ci++)
for (di = 0; di < 4; di++) {
perm = ++op;
if (ipv4) {
sprintf(name, "%d.%d.%d.%d", a[ai], b[bi], c[ci], d[di]);
if (perm >= 1 << 8) {
fprintf(stderr, "expect error, perm=%d (>255):\n", perm);
perm = 1 << 10;
}
if (ai == 0) {
/* 0.0.* gets y,y; 0.201.* gets n,y; 0.77.* gets y,n;
* 0.127.* gets n,n
*/
perm |= (bi << 8);
s = __pmAccAddHost(name, 0x3ff, perm, 0);
}
else
s = __pmAccAddHost(name, 0xff, perm, 0);
if (s < 0) {
fprintf(stderr, "add host for host %s error: %s\n",
name, pmErrStr(s));
continue;
}
fprintf(stderr, "set %03x for host %d.%d.%d.%d\n",
perm, a[ai], b[bi], c[ci], d[di]);
}
#if PCP_VER >= 3611
if (ipv6) {
sprintf(name, "%x:%x:%x:%x:%x:%x:%x:%x",
a[ai], b[bi], c[ci], d[di],
a[ai], b[bi], c[ci], d[di]);
perm = op;
if (perm >= 1 << 8) {
fprintf(stderr, "expect error, perm=%d (>255):\n", perm);
perm = 1 << 10;
}
if (ai == 0) {
/* 0.0.* gets y,y; 0.201.* gets n,y; 0.77.* gets y,n;
* 0.127.* gets n,n
*/
perm |= (bi << 8);
s = __pmAccAddHost(name, 0x3ff, perm, 0);
}
else
s = __pmAccAddHost(name, 0xff, perm, 0);
if (s < 0) {
fprintf(stderr, "add host for host %s error: %s\n",
name, pmErrStr(s));
continue;
}
fprintf(stderr, "set %03x for host %x:%x:%x:%x:%x:%x:%x:%x\n",
perm,
a[ai], b[bi], c[ci], d[di],
a[ai], b[bi], c[ci], d[di]);
}
#endif
}
/* ops 8 and 9 are for wildcard testing:
* hosts matching op8 op9
* * y y
* 38.* y n
* 38.202.* n y
* 38.202.16 n n
* 26:* y n
* 26:ca:* n y
* 26:ca:10:* n n
*/
sts = 0;
for (i = 0; i < 4; i++) {
if (ipv4) {
if ((s = __pmAccAddHost(wnames[i], 0x300, (i << 8), 0)) < 0) {
fprintf(stderr, "cannot add inet host for op%d: %s\n", i, strerror(s));
sts = s;
}
}
#if PCP_VER >= 3611
if (ipv6) {
if ((s = __pmAccAddHost(wnames6[i], 0x300, (i << 8), 0)) < 0) {
fprintf(stderr, "cannot add IPv6 host for op%d: %s\n", i, strerror(s));
sts = s;
}
}
#endif
}
if (sts < 0)
return 1;
#if PCP_VER >= 3801
putc('\n', stderr);
#endif
putc('\n', stderr);
__pmAccDumpHosts(stderr);
#if PCP_VER >= 3801
putc('\n', stderr);
#endif
putc('\n', stderr);
if (ipv4) {
for (i = 0; i < 2; i++)
for (ai = 0; ai < 4; ai++)
for (bi = 0; bi < 4; bi++)
for (ci = 0; ci < 4; ci++)
for (di = 0; di < 4; di++) {
char buf[20];
#if PCP_VER >= 3611
char *host;
sprintf(buf, "%d.%d.%d.%d", a[ai]+i, b[bi]+i, c[ci]+i, d[di]+i);
if ((inaddr =__pmStringToSockAddr(buf)) == NULL) {
printf("insufficient memory\n");
continue;
}
s = __pmAccAddClient(inaddr, &perm);
host = __pmSockAddrToString(inaddr);
__pmSockAddrFree(inaddr);
if (s < 0) {
fprintf(stderr, "from %s error: %s\n", host, pmErrStr(s));
free(host);
continue;
}
fprintf(stderr, "got %03x for host %s\n", perm, host);
free(host);
#else
sprintf(buf, "%d.%d.%d.%d", a[ai]+i, b[bi]+i, c[ci]+i, d[di]+i);
inet_aton(buf, &inaddr);
ipaddr = __pmInAddrToIPAddr(&inaddr);
s = __pmAccAddClient(ipaddr, &perm);
if (s < 0) {
fprintf(stderr, "from %s error: %s\n",
inet_ntoa(inaddr), pmErrStr(s));
continue;
}
fprintf(stderr, "got %03x for host %s\n",
perm, inet_ntoa(inaddr));
#endif
}
}
#if PCP_VER >= 3611
if (ipv6) {
for (i = 0; i < 2; i++)
for (ai = 0; ai < 4; ai++)
for (bi = 0; bi < 4; bi++)
for (ci = 0; ci < 4; ci++)
for (di = 0; di < 4; di++) {
char buf[4*8 + 7 + 1]; /* handles full IPv6 address */
char *host;
sprintf(buf, "%x:%x:%x:%x:%x:%x:%x:%x",
a[ai]+i, b[bi]+i, c[ci]+i, d[di]+i,
a[ai]+i, b[bi]+i, c[ci]+i, d[di]+i);
if ((inaddr =__pmStringToSockAddr(buf)) == NULL) {
printf("insufficient memory\n");
continue;
}
s = __pmAccAddClient(inaddr, &perm);
host = __pmSockAddrToString(inaddr);
__pmSockAddrFree(inaddr);
if (s < 0) {
fprintf(stderr, "from %s error: %s\n", host, pmErrStr(s));
free(host);
continue;
}
fprintf(stderr, "got %03x for host %s\n", perm, host);
free(host);
}
}
#endif
return 0;
}
|