linux-old/ipc/util.c
<<
>>
Prefs
   1/*
   2 * linux/ipc/util.c
   3 * Copyright (C) 1992 Krishna Balasubramanian
   4 *
   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 */
  10
  11#include <linux/config.h>
  12#include <linux/mm.h>
  13#include <linux/shm.h>
  14#include <linux/init.h>
  15#include <linux/msg.h>
  16
  17#if defined(CONFIG_SYSVIPC)
  18
  19extern void sem_init (void), msg_init (void), shm_init (void);
  20
  21void __init ipc_init (void)
  22{
  23        sem_init();
  24        msg_init();
  25        shm_init();
  26        return;
  27}
  28
  29/* 
  30 * Check user, group, other permissions for access
  31 * to ipc resources. return 0 if allowed
  32 */
  33int ipcperms (struct ipc_perm *ipcp, short flag)
  34{       /* flag will most probably be 0 or S_...UGO from <linux/stat.h> */
  35        int requested_mode, granted_mode;
  36
  37        requested_mode = (flag >> 6) | (flag >> 3) | flag;
  38        granted_mode = ipcp->mode;
  39        if (current->euid == ipcp->cuid || current->euid == ipcp->uid)
  40                granted_mode >>= 6;
  41        else if (in_group_p(ipcp->cgid) || in_group_p(ipcp->gid))
  42                granted_mode >>= 3;
  43        /* is there some bit set in requested_mode but not in granted_mode? */
  44        if ((requested_mode & ~granted_mode & 0007) && 
  45            !capable(CAP_IPC_OWNER))
  46                return -1;
  47
  48        return 0;
  49}
  50
  51#else
  52/*
  53 * Dummy functions when SYSV IPC isn't configured
  54 */
  55
  56void sem_exit (void)
  57{
  58    return;
  59}
  60
  61int shm_swap (int prio, int gfp_mask)
  62{
  63    return 0;
  64}
  65
  66asmlinkage int sys_semget (key_t key, int nsems, int semflg)
  67{
  68        return -ENOSYS;
  69}
  70
  71asmlinkage int sys_semop (int semid, struct sembuf *sops, unsigned nsops)
  72{
  73        return -ENOSYS;
  74}
  75
  76asmlinkage int sys_semctl (int semid, int semnum, int cmd, union semun arg)
  77{
  78        return -ENOSYS;
  79}
  80
  81asmlinkage int sys_msgget (key_t key, int msgflg)
  82{
  83        return -ENOSYS;
  84}
  85
  86asmlinkage int sys_msgsnd (int msqid, struct msgbuf *msgp, size_t msgsz, int msgflg)
  87{
  88        return -ENOSYS;
  89}
  90
  91asmlinkage int sys_msgrcv (int msqid, struct msgbuf *msgp, size_t msgsz, long msgtyp,
  92                       int msgflg)
  93{
  94        return -ENOSYS;
  95}
  96
  97asmlinkage int sys_msgctl (int msqid, int cmd, struct msqid_ds *buf)
  98{
  99        return -ENOSYS;
 100}
 101
 102asmlinkage int sys_shmget (key_t key, int size, int flag)
 103{
 104        return -ENOSYS;
 105}
 106
 107asmlinkage int sys_shmat (int shmid, char *shmaddr, int shmflg, ulong *addr)
 108{
 109        return -ENOSYS;
 110}
 111
 112asmlinkage int sys_shmdt (char *shmaddr)
 113{
 114        return -ENOSYS;
 115}
 116
 117asmlinkage int sys_shmctl (int shmid, int cmd, struct shmid_ds *buf)
 118{
 119        return -ENOSYS;
 120}
 121
 122void shm_unuse(unsigned long entry, unsigned long page)
 123{
 124}
 125
 126#endif /* CONFIG_SYSVIPC */
 127
lxr.linux.no kindly hosted by Redpill Linpro AS, provider of Linux consulting and operations services since 1995.