Re: [TOMOYO #15 6/8] LSM adapter functions.

Alexey Dobriyan
2009-02-05T17:05:21Z

On Thu, Feb 05, 2009 at 05:18:16PM +0900, Kentaro Takeda wrote:
> +/**
> + * tomoyo_sysctl_path - return the realpath of a ctl_table.
> + * @table: pointer to "struct ctl_table".
> + *
> + * Returns realpath(3) of the @table on success.
> + * Returns NULL on failure.
> + *
> + * This function uses tomoyo_alloc(), so the caller must call tomoyo_free()
> + * if this function didn't return NULL.
> + */
> +static char *tomoyo_sysctl_path(struct ctl_table *table)
> +{
> + int buflen = TOMOYO_MAX_PATHNAME_LEN;
> + char *buf = tomoyo_alloc(buflen);
> + char *end = buf + buflen;
> + int error = -ENOMEM;
> +
> + if (!buf)
> + return NULL;
> +
> + *--end = '\0';
> + buflen--;
> + while (table) {
> + char buf[32];
> + const char *sp = table->procname;
> +
> + if (!sp) {
> + memset(buf, 0, sizeof(buf));
> + snprintf(buf, sizeof(buf) - 1, "=%d=", table->ctl_name);
> + sp = buf;
> + }
> + if (tomoyo_prepend(&end, &buflen, sp) ||
> + tomoyo_prepend(&end, &buflen, "/"))
> + goto out;
> + table = table->parent;
> + }
> + if (tomoyo_prepend(&end, &buflen, "/proc/sys"))

Hardcoded path?

> + goto out;
> + error = tomoyo_encode(buf, end - buf, end);
> + out:
> + if (!error)
> + return buf;
> + tomoyo_free(buf);
> + return NULL;
> +}