aboutsummaryrefslogtreecommitdiff
path: root/paludis/repositories/e/ebuild/sydbox.bash
blob: 4d9aa482f79a9abd475c6b48ac655154303ff2a8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
#!/usr/bin/env bash
# vim: set sw=4 sts=4 et :

# Copyright (c) 2009, 2010, 2011 Ali Polatel <alip@exherbo.org>
#
# Based in part upon ebuild.sh from Portage, which is Copyright 1995-2005
# Gentoo Foundation and distributed under the terms of the GNU General
# Public License v2.
#
# This file is part of the Paludis package manager. Paludis is free software;
# you can redistribute it and/or modify it under the terms of the GNU General
# Public License, version 2, as published by the Free Software Foundation.
#
# Paludis 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

sydbox_internal_cmd()
{
    if [[ -e /dev/sydbox ]]; then
        if [[ -n "${2}" ]]; then
            [[ -e /dev/sydbox/${1}/"${2}" ]]
        else
            [[ -e /dev/sydbox/${1} ]]
        fi
    fi
}

sydbox_internal_path()
{
    local cmd="${1}"
    shift
    for path in "${@}"; do
        [[ "${path:0:1}" == '/' ]] || die "${FUNCNAME} expects absolute path, got: ${path}"
        sydbox_internal_cmd "${cmd}" "${path}"
    done
}

sydbox_internal_net()
{
    local cmd="${1}"

    shift
    while [[ ${#} > 0 ]] ; do
        case "${1}" in
        inet6:*)
            sydbox_internal_cmd "${cmd}/inet6://${1##inet6:}"
            ;;
        inet:*)
            sydbox_internal_cmd "${cmd}/inet://${1##inet:}"
            ;;
        unix-abstract:*)
            sydbox_internal_cmd "${cmd}/unix-abstract://${1##unix-abstract:}"
            ;;
        unix:*)
            sydbox_internal_cmd "${cmd}/unix://${1##unix:}"
            ;;
        *)
            die "${FUNCNAME}: unexpected argument \"${1}\""
            ;;
        esac
        shift
    done
}

esandbox() {
    local cmd="${1}"

    shift
    case "${cmd}" in
    check)
        [[ -e /dev/sydbox ]]
        ;;
    lock)
        sydbox_internal_cmd lock
        ;;
    exec_lock)
        sydbox_internal_cmd exec_lock
        ;;
    wait_all)
        sydbox_internal_cmd wait/all
        ;;
    wait_eldest)
        sydbox_internal_cmd wait/eldest
        ;;
    hack_toolong)
        sydbox_internal_cmd wrap/lstat
        ;;
    nohack_toolong)
        sydbox_internal_cmd nowrap/lstat
        ;;
    enabled|enabled_path)
        sydbox_internal_cmd enabled
        ;;
    enable|enable_path)
        sydbox_internal_cmd on
        ;;
    disable|disable_path)
        sydbox_internal_cmd off
        ;;
    enabled_exec)
        ebuild_notice "warning" "${FUNCNAME} ${cmd} is not implemented for sydbox"
        false;;
    enable_exec)
        sydbox_internal_cmd sandbox/exec
        ;;
    disable_exec)
        sydbox_internal_cmd sandunbox/exec
        ;;
    enabled_net)
        ebuild_notice "warning" "${FUNCNAME} ${cmd} is not implemented for sydbox"
        false;;
    enable_net)
        sydbox_internal_cmd sandbox/net
        ;;
    disable_net)
        sydbox_internal_cmd sandunbox/net
        ;;
    allow|allow_path)
        [[ ${#} < 1 ]] && die "${FUNCNAME} ${cmd} takes at least one extra argument"
        sydbox_internal_path "write" "${@}"
        ;;
    disallow|disallow_path)
        [[ ${#} < 1 ]] && die "${FUNCNAME} ${cmd} takes at least one extra argument"
        sydbox_internal_path "unwrite" "${@}"
        ;;
    allow_exec)
        [[ ${#} < 1 ]] && die "${FUNCNAME} ${cmd} takes at least one extra argument"
        sydbox_internal_path "addexec" "${@}"
        ;;
    disallow_exec)
        [[ ${#} < 1 ]] && die "${FUNCNAME} ${cmd} takes at least one extra argument"
        sydbox_internal_path "rmexec" "${@}"
        ;;
    allow_net)
        local c="net/whitelist/bind"
        [[ "${1}" == "--connect" ]] && c="net/whitelist/connect" && shift
        [[ ${#} < 1 ]] && die "${FUNCNAME} ${cmd} takes at least one extra argument"
        sydbox_internal_net "${c}" "${@}"
        ;;
    disallow_net)
        local c="net/unwhitelist/bind"
        [[ "${1}" == "--connect" ]] && c="net/unwhitelist/connect" && shift
        [[ ${#} < 1 ]] && die "${FUNCNAME} ${cmd} takes at least one extra argument"
        sydbox_internal_net "${c}" "${@}"
        ;;
    addfilter|addfilter_path)
        [[ ${#} < 1 ]] && die "${FUNCTION} ${cmd} takes at least one extra argument"
        sydbox_internal_path "addfilter" "${@}"
        ;;
    rmfilter|rmfilter_path)
        [[ ${#} < 1 ]] && die "${FUNCTION} ${cmd} takes at least one extra argument"
        sydbox_internal_path "rmfilter" "${@}"
        ;;
    addfilter_exec)
        [[ ${#} < 1 ]] && die "${FUNCTION} ${cmd} takes at least one extra argument"
        sydbox_internal_path "addfilter_exec" "${@}"
        ;;
    rmfilter_exec)
        [[ ${#} < 1 ]] && die "${FUNCTION} ${cmd} takes at least one extra argument"
        sydbox_internal_path "rmfilter_exec" "${@}"
        ;;
    addfilter_net)
        [[ ${#} < 1 ]] && die "${FUNCTION} ${cmd} takes at least one extra argument"
        sydbox_internal_net "addfilter_net" "${@}"
        ;;
    rmfilter_net)
        [[ ${#} < 1 ]] && die "${FUNCTION} ${cmd} takes at least one extra argument"
        sydbox_internal_net "rmfilter_net" "${@}"
        ;;
    *)
        die "${FUNCNAME} subcommand ${cmd} unrecognised"
        ;;
    esac
}

sydboxcheck()
{
    ebuild_notice "warning" "${FUNCNAME} is deprecated, use \"esandbox check\" instead"
    esandbox check
}

sydboxcmd()
{
    ebuild_notice "warning" "${FUNCNAME} is deprecated, use \"esandbox <command>\" instead"
    sydbox_internal_cmd "${@}"
}

addread()
{
    die "${FUNCNAME} not implemented for sydbox yet"
}

addwrite()
{
    ebuild_notice "warning" "${FUNCNAME} is deprecated, use \"esandbox allow\" instead"
    esandbox allow "${1}"
}

adddeny()
{
    die "${FUNCNAME} not implemented for sydbox yet"
}

addpredict()
{
    die "${FUNCNAME} is dead, use \"esandbox addfilter\" instead"
}

rmwrite()
{
    ebuild_notice "warning" "${FUNCNAME} is deprecated, use \"esandbox disallow\" instead"
    esandbox disallow "${1}"
}

rmpredict()
{
    die "${FUNCNAME} is dead, use \"esandbox rmfilter\" instead"
}

addfilter()
{
    ebuild_notice "warning" "${FUNCNAME} is deprecated, use \"esandbox addfilter\" instead"
    esandbox addfilter "${1}"
}

rmfilter()
{
    ebuild_notice "warning" "${FUNCNAME} is deprecated, use \"esandbox rmfilter\" instead"
    esandbox rmfilter "${1}"
}