Beispiel #1
0
static void print_mode(const char *val)
{
	const char *name;
	unsigned int ival;

	errno = 0;
	ival = strtoul(val, NULL, 8);
	if (errno) {
		printf("conversion error(%s) ", val);
		return;
	}

	// print the file type
	name = audit_ftype_to_name(ival & S_IFMT);
	if (name != NULL)
		printf("%s,", name);
	else {
		unsigned first_ifmt_bit;

		// The lowest-valued "1" bit in S_IFMT
		first_ifmt_bit = S_IFMT & ~(S_IFMT - 1);
		printf("%03o,", (ival & S_IFMT) / first_ifmt_bit);
	}

	// check on special bits
	if (S_ISUID & ival)
		printf("suid,");
	if (S_ISGID & ival)
		printf("sgid,");
	if (S_ISVTX & ival)
		printf("sticky,");

	// and the read, write, execute flags in octal
	printf("%03o ",  (S_IRWXU|S_IRWXG|S_IRWXO) & ival);
}
Beispiel #2
0
static const char *print_mode(const char *val, unsigned int base)
{
        unsigned int ival;
	char *out, buf[48];
	const char *name;

        errno = 0;
        ival = strtoul(val, NULL, base);
        if (errno) {
                asprintf(&out, "conversion error(%s)", val);
                return out;
        }

        // detect the file type
	name = audit_ftype_to_name(ival & S_IFMT);
	if (name != NULL)
		strcpy(buf, name);
	else {
		unsigned first_ifmt_bit;

		// The lowest-valued "1" bit in S_IFMT
		first_ifmt_bit = S_IFMT & ~(S_IFMT - 1);
		sprintf(buf, "%03o", (ival & S_IFMT) / first_ifmt_bit);
	}

        // check on special bits
        if (S_ISUID & ival)
                strcat(buf, ",suid");
        if (S_ISGID & ival)
                strcat(buf, ",sgid");
        if (S_ISVTX & ival)
                strcat(buf, ",sticky");

	// and the read, write, execute flags in octal
        asprintf(&out, "%s,%03o",  buf, (S_IRWXU|S_IRWXG|S_IRWXO) & ival);
	return out;
}