X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=tests%2Ftestipc.cc;fp=tests%2Ftestipc.cc;h=0000000000000000000000000000000000000000;hb=780710c3d80b8776944dd1fc65a0fda64f399db0;hp=10b2382ab43f36d8e0a52fb543ee1bddde68bcce;hpb=8cf13bb177d92c93eb73dc8939777150536c2d00;p=util-vserver.git diff --git a/tests/testipc.cc b/tests/testipc.cc deleted file mode 100644 index 10b2382..0000000 --- a/tests/testipc.cc +++ /dev/null @@ -1,127 +0,0 @@ -// $Id: testipc.cc,v 1.1 2003/09/29 22:01:57 ensc Exp $ - -// Copyright (C) 2003 Enrico Scholz -// based on tests/testipc.cc by Jacques Gelinas -// -// This program is free software; you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation; either version 2, or (at your option) -// any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with this program; if not, write to the Free Software -// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - -/* - Test to see isolation of the various IPC resources - between security context -*/ -#include -#include -#include -#include -#include -#include -#include - -int main (int argc, char *argv[]) -{ - int ret = -1; - if (argc < 2){ - fprintf (stderr, - "testipc createshm\n" - ); - }else if(strcmp(argv[1],"createshm")==0){ - int id = shmget (1,1024,IPC_CREAT|0666); - if (id == -1){ - fprintf (stderr,"shmget failed (%s)\n",strerror(errno)); - }else{ - printf ("shmget id %d\n",id); - void *pt = shmat (id,NULL,0); - if (pt == NULL){ - fprintf (stderr,"can't shmat to id %d (%s)\n",id,strerror(errno)); - }else{ - strcpy ((char*)pt,"original string"); - - printf ("Letting a sub-program attach to this memory\n"); - char tmp[100]; - sprintf (tmp,"./testipc accessshm %d",id); - int ok = system (tmp); - printf ("\tSub-program returned %d\n",ok); - - printf ("\tThe segment now hold :%s:\n",(char*)pt); - shmdt (pt); - - printf ("A sub-program in another context can't attach\n"); - sprintf (tmp,"/usr/sbin/chcontext ./testipc accessshm %d",id); - ok = system (tmp); - printf ("\tSub-program returned %d\n",ok); - - printf ("Executing a sub-shell\n"); - system ("/bin/sh"); - } - printf ("Delete the share memory segment\n"); - if (shmctl (id,IPC_RMID,NULL)==-1){ - fprintf (stderr,"shmctl failed (%s)\n",strerror(errno)); - }else{ - ret = 0; - } - } - }else if(strcmp(argv[1],"accessshm")==0){ - int id = atoi(argv[2]); - void *pt = shmat (id,NULL,0); - if (pt == (void*)-1){ - fprintf (stderr,"can't shmat to id %d (%s)\n",id,strerror(errno)); - }else{ - printf ("\tWriting hello in share memory\n"); - strcpy ((char*)pt,"hello"); - ret = 0; - } - }else if(strcmp(argv[1],"createsem")==0){ - int id = semget (1,1,IPC_CREAT|0666); - if (id == -1){ - fprintf (stderr,"semget failed (%s)\n",strerror(errno)); - }else{ - printf ("semget id %d\n",id); - - printf ("Letting a sub-program play with this semaphore\n"); - char tmp[100]; - sprintf (tmp,"./testipc accesssem %d",id); - int ok = system (tmp); - printf ("\tSub-program returned %d\n",ok); - - printf ("A sub-program in another context can't use the semaphore\n"); - sprintf (tmp,"/usr/sbin/chcontext ./testipc accesssem %d",id); - ok = system (tmp); - printf ("\tSub-program returned %d\n",ok); - - printf ("Executing a sub-shell\n"); - system ("/bin/sh"); - - printf ("Delete the semaphore\n"); - if (semctl (id,0,IPC_RMID,NULL)==-1){ - fprintf (stderr,"semctl failed (%s)\n",strerror(errno)); - }else{ - ret = 0; - } - } - }else if(strcmp(argv[1],"accesssem")==0){ - int id = atoi(argv[2]); - struct sembuf ops[]={ - {0,0,0} - }; - if (semop (id,ops,1) == -1){ - fprintf (stderr,"can't semop with id %d (%s)\n",id,strerror(errno)); - }else{ - ret = 0; - } - } - return ret; -} - -