root/ipc/util.c

/* [previous][next][first][last][top][bottom][index][help] */

DEFINITIONS

This source file includes following definitions.
  1. ipc_init
  2. ipcperms
  3. sys_ipc
  4. sys_ipc
  5. sem_exit
  6. shm_swap
  7. shm_no_page

   1 /*
   2  * linux/ipc/util.c
   3  * Copyright (C) 1992 Krishna Balasubramanian
   4  */
   5 
   6 #include <linux/config.h>
   7 #include <linux/errno.h>
   8 #include <asm/segment.h>
   9 #include <linux/sched.h>
  10 #include <linux/sem.h>
  11 #include <linux/msg.h>
  12 #include <linux/shm.h>
  13 #include <linux/stat.h>
  14 
  15 void ipc_init (void);
  16 asmlinkage int sys_ipc (uint call, int first, int second, int third, void *ptr);
  17 
  18 #ifdef CONFIG_SYSVIPC
  19 
  20 int ipcperms (struct ipc_perm *ipcp, short flag);
  21 extern void sem_init (void), msg_init (void), shm_init (void);
  22 extern int sys_semget (key_t key, int nsems, int semflg);
  23 extern int sys_semop (int semid, struct sembuf *sops, unsigned nsops);
  24 extern int sys_semctl (int semid, int semnum, int cmd, union semun arg);
  25 extern int sys_msgget (key_t key, int msgflg);
  26 extern int sys_msgsnd (int msqid, struct msgbuf *msgp, int msgsz, int msgflg);
  27 extern int sys_msgrcv (int msqid, struct msgbuf *msgp, int msgsz, long msgtyp,
  28                        int msgflg);
  29 extern int sys_msgctl (int msqid, int cmd, struct msqid_ds *buf);
  30 extern int sys_shmget (key_t key, int size, int flag);
  31 extern int sys_shmat (int shmid, char *shmaddr, int shmflg, ulong *addr);
  32 extern int sys_shmdt (char *shmaddr);
  33 extern int sys_shmctl (int shmid, int cmd, struct shmid_ds *buf);
  34 
  35 void ipc_init (void)
     /* [previous][next][first][last][top][bottom][index][help] */
  36 {
  37         sem_init();
  38         msg_init();
  39         shm_init();
  40         return;
  41 }
  42 
  43 /* 
  44  * Check user, group, other permissions for access
  45  * to ipc resources. return 0 if allowed
  46  */
  47 int ipcperms (struct ipc_perm *ipcp, short flag)
     /* [previous][next][first][last][top][bottom][index][help] */
  48 {       /* flag will most probably be 0 or S_...UGO from <linux/stat.h> */
  49         int requested_mode, granted_mode;
  50 
  51         if (suser())
  52                 return 0;
  53         requested_mode = (flag >> 6) | (flag >> 3) | flag;
  54         granted_mode = ipcp->mode;
  55         if (current->euid == ipcp->cuid || current->euid == ipcp->uid)
  56                 granted_mode >>= 6;
  57         else if (in_group_p(ipcp->cgid) || in_group_p(ipcp->gid))
  58                 granted_mode >>= 3;
  59         /* is there some bit set in requested_mode but not in granted_mode? */
  60         if (requested_mode & ~granted_mode & 0007)
  61                 return -1;
  62         return 0;
  63 }
  64 
  65 asmlinkage int sys_ipc (uint call, int first, int second, int third, void *ptr) 
     /* [previous][next][first][last][top][bottom][index][help] */
  66 {
  67         
  68         if (call <= SEMCTL)
  69                 switch (call) {
  70                 case SEMOP:
  71                         return sys_semop (first, (struct sembuf *)ptr, second);
  72                 case SEMGET:
  73                         return sys_semget (first, second, third);
  74                 case SEMCTL: {
  75                         union semun fourth;
  76                         int err;
  77                         if (!ptr)
  78                                 return -EINVAL;
  79                         if ((err = verify_area (VERIFY_READ, ptr, sizeof(long))))
  80                                 return err;
  81                         fourth.__pad = (void *) get_fs_long(ptr);
  82                         return sys_semctl (first, second, third, fourth);
  83                         }
  84                 default:
  85                         return -EINVAL;
  86                 }
  87         if (call <= MSGCTL) 
  88                 switch (call) {
  89                 case MSGSND:
  90                         return sys_msgsnd (first, (struct msgbuf *) ptr, 
  91                                            second, third);
  92                 case MSGRCV: {
  93                         struct ipc_kludge tmp;
  94                         int err;
  95                         if (!ptr)
  96                                 return -EINVAL;
  97                         if ((err = verify_area (VERIFY_READ, ptr, sizeof(tmp))))
  98                                 return err;
  99                         memcpy_fromfs (&tmp,(struct ipc_kludge *) ptr,
 100                                        sizeof (tmp));
 101                         return sys_msgrcv (first, tmp.msgp, second, tmp.msgtyp,
 102                                                 third);
 103                         }
 104                 case MSGGET:
 105                         return sys_msgget ((key_t) first, second);
 106                 case MSGCTL:
 107                         return sys_msgctl (first, second, (struct msqid_ds *) ptr);
 108                 default:
 109                         return -EINVAL;
 110                 }
 111         if (call <= SHMCTL) 
 112                 switch (call) {
 113                 case SHMAT:
 114                         return sys_shmat (first, (char *) ptr, second, 
 115                                                         (ulong *) third);
 116                 case SHMDT: 
 117                         return sys_shmdt ((char *)ptr);
 118                 case SHMGET:
 119                         return sys_shmget (first, second, third);
 120                 case SHMCTL:
 121                         return sys_shmctl (first, second, (struct shmid_ds *) ptr);
 122                 default:
 123                         return -EINVAL;
 124                 }
 125         return -EINVAL;
 126 }
 127 
 128 #else /* not CONFIG_SYSVIPC */
 129 
 130 asmlinkage int sys_ipc (uint call, int first, int second, int third, void *ptr) 
     /* [previous][next][first][last][top][bottom][index][help] */
 131 {
 132     return -ENOSYS;
 133 }
 134 
 135 void sem_exit (void)
     /* [previous][next][first][last][top][bottom][index][help] */
 136 {
 137     return;
 138 }
 139 
 140 int shm_swap (int prio)
     /* [previous][next][first][last][top][bottom][index][help] */
 141 {
 142     return 0;
 143 }
 144 
 145 void shm_no_page (unsigned long *ptent)
     /* [previous][next][first][last][top][bottom][index][help] */
 146 {
 147     return;
 148 }
 149 
 150 #endif /* CONFIG_SYSVIPC */

/* [previous][next][first][last][top][bottom][index][help] */