This file is indexed.

/var/lib/pcp/testsuite/src/chkacc1.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
/*
 * Copyright (c) 2012-2013 Red Hat.
 * Copyright (c) 1997-2001 Silicon Graphics, Inc.  All Rights Reserved.
 */

#include <pcp/pmapi.h>
#include <pcp/impl.h>
#include "localconfig.h"

int
main(int argc, char **argv)
{
    int			s, sts, op, host;
    unsigned int	i;
    char		name[4*8 + 7 + 1]; /* handles full IPv6 address, if supported */
    int			ipv4 = -1;
    int			ipv6 = -1;
    int			errflag = 0;
    int			c;
#if PCP_VER >= 3611
    __pmSockAddr	*inaddr;
#else
    __pmInAddr		inaddr;
    __pmIPAddr		ipaddr;
#endif

    /* trim cmd name of leading directory components */
    __pmSetProgname(argv[0]);

    while ((c = getopt(argc, argv, "46D:?")) != EOF) {
	switch (c) {

	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;

#if PCP_VER < 3611
    if (ipv6) {
	printf("No IPv6 support for this version of PCP\n");
	return 1;
    }
#endif

    sts = 0;
    for (op = 0; op < WORD_BIT; op++) {
	if ((s = __pmAccAddOp(1 << op)) < 0) {
	    printf("Bad op %d: %s\n", op, strerror(errno));
	    sts = s;
	}
	if ((s = __pmAccAddOp(1 << op)) >= 0) {
	    printf("duplicate op test failed for op %d\n", op);
	    sts = -EINVAL;
	}
    }
    if (sts < 0)
	return 1;

    for (host = 0; host < WORD_BIT; host++) {
	if (ipv4) {
	    sprintf(name, "155.%d.%d.%d", host * 3, 17+host, host);
	    if ((s = __pmAccAddHost(name, 1 << host, 1 << host, 0)) < 0) {
		printf("cannot add inet host for op%d: %s\n", host, strerror(s));
		sts = s;
	    }
	}
#if PCP_VER >= 3611
	if (ipv6) {
	    sprintf(name, "fec0::%x:%x:%x:%x:%x:%x",
		    host * 3, 17+host, host,
		    host * 3, 17+host, host);
	    if ((s = __pmAccAddHost(name, 1 << host, 1 << host, 0)) < 0) {
		printf("cannot add IPv6 host for op%d: %s\n", host, 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

    if (ipv4) {
	for (host = 0; host < WORD_BIT; host++) {
	    char	buf[20];

	    sprintf(buf, "%d.%d.%d.%d", 155, host * 3, 17+host, host);
#if PCP_VER >= 3611
	    if ((inaddr =__pmStringToSockAddr(buf)) == NULL) {
		printf("insufficient memory\n");
		continue;
	    }
	    sts = __pmAccAddClient(inaddr, &i);
	    __pmSockAddrFree(inaddr);
#else
	    inet_aton(buf, &inaddr);
	    ipaddr = __pmInAddrToIPAddr(&inaddr);
	    sts = __pmAccAddClient(ipaddr, &i);
#endif

	    if (sts < 0) {
		printf("add inet client from host %d: %s\n", host, pmErrStr(sts));
		continue;
	    }
	    else if (i != (1 << host))
		printf("inet host %d: __pmAccAddClient returns denyOpsResult 0x%x (expected 0x%x)\n",
		       host, i, 1 << host);
	}
    }

#if PCP_VER >= 3611
    if (ipv6) {
	for (host = 0; host < WORD_BIT; host++) {
	    char	buf[4*8 + 7 + 1]; /* handles full IPv6 address */

	    sprintf(buf, "fec0::%x:%x:%x:%x:%x:%x",
		    host * 3, 17+host, host,
		    host * 3, 17+host, host);
	    if ((inaddr =__pmStringToSockAddr(buf)) == NULL) {
		printf("insufficient memory\n");
		continue;
	    }
	    sts = __pmAccAddClient(inaddr, &i);
	    __pmSockAddrFree(inaddr);

	    if (sts < 0) {
		printf("add IPv6 client from host %d: %s\n", host, pmErrStr(sts));
		continue;
	    }
	    else if (i != (1 << host))
		printf("IPv6 host %d: __pmAccAddClient returns denyOpsResult 0x%x (expected 0x%x)\n",
		       host, i, 1 << host);
	}
    }
#endif
    
#if PCP_VER >= 3801
    putc('\n', stderr);
#endif

    putc('\n', stderr);
    __pmAccDumpHosts(stderr);

#if PCP_VER >= 3801
    putc('\n', stderr);
#endif

    return 0;
}