lib.c (2d679f3cb0eaa6afa0dc97fe6ad3b797e1c1899a) lib.c (a1bd627b46d169268a0ee5960899fb5be960a317)
1/*
2 * AppArmor security module
3 *
4 * This file contains basic common functions used in AppArmor
5 *
6 * Copyright (C) 1998-2008 Novell/SUSE
7 * Copyright 2009-2010 Canonical Ltd.
8 *

--- 120 unchanged lines hidden (view full) ---

129 DEFINE_AUDIT_DATA(sa, LSM_AUDIT_DATA_NONE, NULL);
130
131 aad(&sa)->info = str;
132 aa_audit_msg(AUDIT_APPARMOR_STATUS, &sa, NULL);
133 }
134 printk(KERN_INFO "AppArmor: %s\n", str);
135}
136
1/*
2 * AppArmor security module
3 *
4 * This file contains basic common functions used in AppArmor
5 *
6 * Copyright (C) 1998-2008 Novell/SUSE
7 * Copyright 2009-2010 Canonical Ltd.
8 *

--- 120 unchanged lines hidden (view full) ---

129 DEFINE_AUDIT_DATA(sa, LSM_AUDIT_DATA_NONE, NULL);
130
131 aad(&sa)->info = str;
132 aa_audit_msg(AUDIT_APPARMOR_STATUS, &sa, NULL);
133 }
134 printk(KERN_INFO "AppArmor: %s\n", str);
135}
136
137__counted char *aa_str_alloc(int size, gfp_t gfp)
138{
139 struct counted_str *str;
140
141 str = kmalloc(sizeof(struct counted_str) + size, gfp);
142 if (!str)
143 return NULL;
144
145 kref_init(&str->count);
146 return str->name;
147}
148
149void aa_str_kref(struct kref *kref)
150{
151 kfree(container_of(kref, struct counted_str, count));
152}
153
154
137const char aa_file_perm_chrs[] = "xwracd km l ";
138const char *aa_file_perm_names[] = {
139 "exec",
140 "write",
141 "read",
142 "append",
143
144 "create",

--- 146 unchanged lines hidden (view full) ---

291// perms->xindex = dfa_user_xindex(dfa, state);
292}
293
294/**
295 * aa_policy_init - initialize a policy structure
296 * @policy: policy to initialize (NOT NULL)
297 * @prefix: prefix name if any is required. (MAYBE NULL)
298 * @name: name of the policy, init will make a copy of it (NOT NULL)
155const char aa_file_perm_chrs[] = "xwracd km l ";
156const char *aa_file_perm_names[] = {
157 "exec",
158 "write",
159 "read",
160 "append",
161
162 "create",

--- 146 unchanged lines hidden (view full) ---

309// perms->xindex = dfa_user_xindex(dfa, state);
310}
311
312/**
313 * aa_policy_init - initialize a policy structure
314 * @policy: policy to initialize (NOT NULL)
315 * @prefix: prefix name if any is required. (MAYBE NULL)
316 * @name: name of the policy, init will make a copy of it (NOT NULL)
317 * @gfp: allocation mode
299 *
300 * Note: this fn creates a copy of strings passed in
301 *
302 * Returns: true if policy init successful
303 */
304bool aa_policy_init(struct aa_policy *policy, const char *prefix,
305 const char *name, gfp_t gfp)
306{
318 *
319 * Note: this fn creates a copy of strings passed in
320 *
321 * Returns: true if policy init successful
322 */
323bool aa_policy_init(struct aa_policy *policy, const char *prefix,
324 const char *name, gfp_t gfp)
325{
326 char *hname;
327
307 /* freed by policy_free */
308 if (prefix) {
328 /* freed by policy_free */
329 if (prefix) {
309 policy->hname = kmalloc(strlen(prefix) + strlen(name) + 3,
310 gfp);
311 if (policy->hname)
312 sprintf((char *)policy->hname, "%s//%s", prefix, name);
313 } else
314 policy->hname = kstrdup(name, gfp);
315 if (!policy->hname)
330 hname = aa_str_alloc(strlen(prefix) + strlen(name) + 3, gfp);
331 if (hname)
332 sprintf(hname, "%s//%s", prefix, name);
333 } else {
334 hname = aa_str_alloc(strlen(name) + 1, gfp);
335 if (hname)
336 strcpy(hname, name);
337 }
338 if (!hname)
316 return false;
339 return false;
340 policy->hname = hname;
317 /* base.name is a substring of fqname */
318 policy->name = basename(policy->hname);
319 INIT_LIST_HEAD(&policy->list);
320 INIT_LIST_HEAD(&policy->profiles);
321
322 return true;
323}
324
325/**
326 * aa_policy_destroy - free the elements referenced by @policy
327 * @policy: policy that is to have its elements freed (NOT NULL)
328 */
329void aa_policy_destroy(struct aa_policy *policy)
330{
331 AA_BUG(on_list_rcu(&policy->profiles));
332 AA_BUG(on_list_rcu(&policy->list));
333
334 /* don't free name as its a subset of hname */
341 /* base.name is a substring of fqname */
342 policy->name = basename(policy->hname);
343 INIT_LIST_HEAD(&policy->list);
344 INIT_LIST_HEAD(&policy->profiles);
345
346 return true;
347}
348
349/**
350 * aa_policy_destroy - free the elements referenced by @policy
351 * @policy: policy that is to have its elements freed (NOT NULL)
352 */
353void aa_policy_destroy(struct aa_policy *policy)
354{
355 AA_BUG(on_list_rcu(&policy->profiles));
356 AA_BUG(on_list_rcu(&policy->list));
357
358 /* don't free name as its a subset of hname */
335 kzfree(policy->hname);
359 aa_put_str(policy->hname);
336}
360}