1
/* $Id: change_hat.c 13 2006-04-12 21:43:34Z steve-beattie $
3
Copyright (c) 2003, 2004, 2005, 2006 Novell, Inc. (All rights reserved)
5
The libapparmor library is licensed under the terms of the GNU
6
Lesser General Public License, version 2.1. Please see the file
11
#define _GNU_SOURCE /* for asprintf */
17
#include <sys/types.h>
19
#include <sys/syscall.h>
24
int change_hat(char *subprofile, unsigned int token)
27
int fd, ret, len = 0, ctlerr = 0;
29
const char *cmd = "changehat";
31
pid_t tid = syscall(SYS_gettid);
33
/* both may not be null */
34
if (!(token || subprofile)) {
39
if (subprofile && strnlen(subprofile, PATH_MAX + 1) > PATH_MAX) {
44
len = asprintf(&buf, "%s %08x^%s", cmd, token,
45
subprofile ? subprofile : "");
50
ctlerr = asprintf(&ctl, "/proc/%d/attr/current", tid);
55
fd = open(ctl, O_WRONLY);
60
ret = write(fd, buf, len);
77
/* clear local copy of magic token before freeing */
78
memset(buf, '\0', len);