Import 2.1.119pre1
[davej-history.git] / ipc / util.c
blob1938d0be3f85aa5e49275da7febfddbaf8294b16
1 /*
2 * linux/ipc/util.c
3 * Copyright (C) 1992 Krishna Balasubramanian
5 * Sep 1997 - Call suser() last after "normal" permission checks so we
6 * get BSD style process accounting right.
7 * Occurs in several places in the IPC code.
8 * Chris Evans, <chris@ferret.lmh.ox.ac.uk>
9 */
11 #include <linux/config.h>
12 #include <linux/errno.h>
13 #include <linux/sched.h>
14 #include <linux/mm.h>
15 #include <linux/sem.h>
16 #include <linux/msg.h>
17 #include <linux/shm.h>
18 #include <linux/stat.h>
19 #include <linux/init.h>
21 #include <asm/uaccess.h>
23 #if defined(CONFIG_SYSVIPC)
25 extern void sem_init (void), msg_init (void), shm_init (void);
27 void __init ipc_init (void)
29 sem_init();
30 msg_init();
31 shm_init();
32 return;
35 /*
36 * Check user, group, other permissions for access
37 * to ipc resources. return 0 if allowed
39 int ipcperms (struct ipc_perm *ipcp, short flag)
40 { /* flag will most probably be 0 or S_...UGO from <linux/stat.h> */
41 int requested_mode, granted_mode;
43 requested_mode = (flag >> 6) | (flag >> 3) | flag;
44 granted_mode = ipcp->mode;
45 if (current->euid == ipcp->cuid || current->euid == ipcp->uid)
46 granted_mode >>= 6;
47 else if (in_group_p(ipcp->cgid) || in_group_p(ipcp->gid))
48 granted_mode >>= 3;
49 /* is there some bit set in requested_mode but not in granted_mode? */
50 if ((requested_mode & ~granted_mode & 0007) &&
51 !capable(CAP_IPC_OWNER))
52 return -1;
54 return 0;
57 #else
59 * Dummy functions when SYSV IPC isn't configured
62 void sem_exit (void)
64 return;
67 int shm_swap (int prio, int gfp_mask)
69 return 0;
72 asmlinkage int sys_semget (key_t key, int nsems, int semflg)
74 return -ENOSYS;
77 asmlinkage int sys_semop (int semid, struct sembuf *sops, unsigned nsops)
79 return -ENOSYS;
82 asmlinkage int sys_semctl (int semid, int semnum, int cmd, union semun arg)
84 return -ENOSYS;
87 asmlinkage int sys_msgget (key_t key, int msgflg)
89 return -ENOSYS;
92 asmlinkage int sys_msgsnd (int msqid, struct msgbuf *msgp, size_t msgsz, int msgflg)
94 return -ENOSYS;
97 asmlinkage int sys_msgrcv (int msqid, struct msgbuf *msgp, size_t msgsz, long msgtyp,
98 int msgflg)
100 return -ENOSYS;
103 asmlinkage int sys_msgctl (int msqid, int cmd, struct msqid_ds *buf)
105 return -ENOSYS;
108 asmlinkage int sys_shmget (key_t key, int size, int flag)
110 return -ENOSYS;
113 asmlinkage int sys_shmat (int shmid, char *shmaddr, int shmflg, ulong *addr)
115 return -ENOSYS;
118 asmlinkage int sys_shmdt (char *shmaddr)
120 return -ENOSYS;
123 asmlinkage int sys_shmctl (int shmid, int cmd, struct shmid_ds *buf)
125 return -ENOSYS;
128 #endif /* CONFIG_SYSVIPC */