~ubuntu-branches/debian/squeeze/util-vserver/squeeze

« back to all changes in this revision

Viewing changes to tests/chrootsafe.c

  • Committer: Bazaar Package Importer
  • Author(s): Micah Anderson
  • Date: 2010-04-13 12:36:17 UTC
  • Revision ID: james.westby@ubuntu.com-20100413123617-ve6wgautfmwfhnkc
Tags: 0.30.216-pre2864-2
* Switch to dpkg-source 3.0 (quilt) format
* Fix bashisms in helper scripts (Closes: #530995)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
// $Id: chrootsafe.c 268 2003-10-21 13:54:59Z ensc $    --*- c++ -*--
 
2
 
 
3
// Copyright (C) 2003 Enrico Scholz <enrico.scholz@informatik.tu-chemnitz.de>
 
4
// based on tests/chrootsafe.cc by Jacques Gelinas
 
5
//  
 
6
// This program is free software; you can redistribute it and/or modify
 
7
// it under the terms of the GNU General Public License as published by
 
8
// the Free Software Foundation; either version 2, or (at your option)
 
9
// any later version.
 
10
//  
 
11
// This program is distributed in the hope that it will be useful,
 
12
// but WITHOUT ANY WARRANTY; without even the implied warranty of
 
13
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
14
// GNU General Public License for more details.
 
15
//  
 
16
// You should have received a copy of the GNU General Public License
 
17
// along with this program; if not, write to the Free Software
 
18
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 
19
 
 
20
/*
 
21
        Test the chrootsafe command.
 
22
        Pass the path of a vserver as the only argument
 
23
 
 
24
        chrootsafe /vservers/test
 
25
*/
 
26
#ifdef HAVE_CONFIG_H
 
27
#  include <config.h>
 
28
#endif
 
29
 
 
30
#include <stdio.h>
 
31
#include <string.h>
 
32
#include <fcntl.h>
 
33
#include <pwd.h>
 
34
#include <grp.h>
 
35
#include <errno.h>
 
36
#include <unistd.h>
 
37
#include <stdlib.h>
 
38
 
 
39
#include "compat.h"
 
40
#include "vserver.h"
 
41
 
 
42
int main (int UNUSED argc, char *argv[])
 
43
{
 
44
        // This test must fail
 
45
        int fd = open ("/",O_RDONLY);
 
46
        if (fd != -1){
 
47
                if (vc_chrootsafe(argv[1])==-1){
 
48
                        fprintf (stderr,"Ok, chrootsafe failed with one open directory errno=%s\n",strerror(errno));
 
49
                }else{
 
50
                        fprintf (stderr,"Hum, chrootsafe succeed with one open directory\n");
 
51
                        system ("/bin/sh");
 
52
                }
 
53
                close (fd);
 
54
        }
 
55
        // Now it should work
 
56
        if (vc_chrootsafe(argv[1])!=-1){
 
57
                fprintf (stderr,"Ok, chrootsafe worked\n");
 
58
                system ("/bin/sh");
 
59
        }else{
 
60
                fprintf (stderr,"chrootsafe failed errno=%s\n",strerror(errno));
 
61
        }
 
62
        return 0;
 
63
}       
 
64