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