]>
git.proxmox.com Git - mirror_ubuntu-artful-kernel.git/blob - security/apparmor/include/af_unix.h
2 * AppArmor security module
4 * This file contains AppArmor af_unix fine grained mediation
6 * Copyright 2014 Canonical Ltd.
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License as
10 * published by the Free Software Foundation, version 2 of the
13 #ifndef __AA_AF_UNIX_H
15 #include <net/af_unix.h>
18 //#include "include/net.h"
20 #define unix_addr_len(L) ((L) - sizeof(sa_family_t))
21 #define unix_abstract_name_len(L) (unix_addr_len(L) - 1)
22 #define unix_abstract_len(U) (unix_abstract_name_len((U)->addr->len))
23 #define addr_unix_abstract_name(B) ((B)[0] == 0)
24 #define addr_unix_anonymous(U) (addr_unix_len(U) <= 0)
25 #define addr_unix_abstract(U) (!addr_unix_anonymous(U) && addr_unix_abstract_name((U)->addr))
26 //#define unix_addr_fs(U) (!unix_addr_anonymous(U) && !unix_addr_abstract_name((U)->addr))
28 #define unix_addr(A) ((struct sockaddr_un *)(A))
29 #define unix_addr_anon(A, L) ((A) && unix_addr_len(L) <= 0)
30 #define unix_addr_fs(A, L) (!unix_addr_anon(A, L) && !addr_unix_abstract_name(unix_addr(A)->sun_path))
32 #define UNIX_ANONYMOUS(U) (!unix_sk(U)->addr)
33 /* from net/unix/af_unix.c */
34 #define UNIX_ABSTRACT(U) (!UNIX_ANONYMOUS(U) && \
35 unix_sk(U)->addr->hash < UNIX_HASH_SIZE)
36 #define UNIX_FS(U) (!UNIX_ANONYMOUS(U) && unix_sk(U)->addr->name->sun_path[0])
37 #define unix_peer(sk) (unix_sk(sk)->peer)
38 #define unix_connected(S) ((S)->state == SS_CONNECTED)
40 static inline void print_unix_addr(struct sockaddr_un
*A
, int L
)
42 char *buf
= (A
) ? (char *) &(A
)->sun_path
: NULL
;
43 int len
= unix_addr_len(L
);
45 printk(" <anonymous>");
49 /* abstract name len includes leading \0 */
50 printk(" %d @%.*s", len
- 1, len
- 1, buf
+1);
54 printk("%s: %s: f %d, t %d, p %d", __FUNCTION__, \
57 #define print_unix_sk(SK) \
59 struct unix_sock *u = unix_sk(SK); \
60 printk("%s: f %d, t %d, p %d", #SK , \
61 (SK)->sk_family, (SK)->sk_type, (SK)->sk_protocol); \
63 print_unix_addr(u->addr->name, u->addr->len); \
65 print_unix_addr(NULL, sizeof(sa_family_t)); \
69 #define print_sk(SK) \
72 printk("%s: %s is null\n", __FUNCTION__, #SK); \
73 } else if ((SK)->sk_family == PF_UNIX) { \
77 printk("%s: %s: family %d\n", __FUNCTION__, #SK , \
82 #define print_sock_addr(U) \
84 printk("%s:\n", __FUNCTION__); \
85 printk(" sock %s:", sock_ctx && sock_ctx->label ? aa_label_printk(sock_ctx->label, GFP_ATOMIC); : "<null>"); print_sk(sock); \
86 printk(" other %s:", other_ctx && other_ctx->label ? aa_label_printk(other_ctx->label, GFP_ATOMIC); : "<null>"); print_sk(other); \
87 printk(" new %s", new_ctx && new_ctx->label ? aa_label_printk(new_ctx->label, GFP_ATOMIC); : "<null>"); print_sk(newsk); \
93 int aa_unix_peer_perm(struct aa_label
*label
, const char *op
, u32 request
,
94 struct sock
*sk
, struct sock
*peer_sk
,
95 struct aa_label
*peer_label
);
96 int aa_unix_label_sk_perm(struct aa_label
*label
, const char *op
, u32 request
,
98 int aa_unix_sock_perm(const char *op
, u32 request
, struct socket
*sock
);
99 int aa_unix_create_perm(struct aa_label
*label
, int family
, int type
,
101 int aa_unix_bind_perm(struct socket
*sock
, struct sockaddr
*address
,
103 int aa_unix_connect_perm(struct socket
*sock
, struct sockaddr
*address
,
105 int aa_unix_listen_perm(struct socket
*sock
, int backlog
);
106 int aa_unix_accept_perm(struct socket
*sock
, struct socket
*newsock
);
107 int aa_unix_msg_perm(const char *op
, u32 request
, struct socket
*sock
,
108 struct msghdr
*msg
, int size
);
109 int aa_unix_opt_perm(const char *op
, u32 request
, struct socket
*sock
, int level
,
111 int aa_unix_file_perm(struct aa_label
*label
, const char *op
, u32 request
,
112 struct socket
*sock
);
114 #endif /* __AA_AF_UNIX_H */