aboutsummaryrefslogtreecommitdiff
path: root/tests/data/cmd-fake
blob: 17bbb90b6d15c4b70c52b60344fd6a1e286fbfda (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
#!/bin/sh
# $Id$
#
# This is a fake wallet backend that returns bogus data for verification by
# the client test suite.  It doesn't test any of the wallet server code.
#
# Written by Russ Allbery <rra@stanford.edu>
# Copyright 2007, 2008 Board of Trustees, Leland Stanford Jr. University
# See LICENSE for licensing terms.

command="$1"
shift
type="$1"
shift
if [ "$type" != "keytab" ] && [ "$type" != "file" ] ; then
    echo "Unknown object type $type" >&2
    exit 1
fi

case "$command" in
getattr)
    if [ -n "$3" ] ; then
        echo "Too many arguments" >&2
        exit 1
    fi
    if [ "$type" != "keytab" ] || [ "$2" != sync ] ; then
        echo "Unknown attribute $2" >&2
        exit 1
    fi
    case "$1" in
    service/fake-srvtab)
        if [ -f sync-kaserver ] ; then
            echo "kaserver"
        fi
        ;;
    *)
        echo "Looking at sync attribute of wrong keytab" >&2
        exit 1
        ;;
    esac
    ;;
setattr)
    if [ -n "$4" ] ; then
        echo "Too many arguments" >&2
        exit 1
    fi
    if [ "$type" != "keytab" ] || [ "$2" != sync ] ; then
        echo "Unknown attribute $2" >&2
        exit 1
    fi
    case "$1" in
    service/fake-srvtab)
        if [ "$3" = "kaserver" ] ; then
            touch sync-kaserver
        else
            if [ "$3" = "" ] ; then
                rm sync-kaserver
            else
                echo "Invalid attribute value $3" >&2
                exit 1
            fi
        fi
        ;;
    *)
        echo "Looking at sync attribute of wrong keytab" >&2
        exit 1
        ;;
    esac
    ;;
exists)
    if [ -n "$2" ] ; then
        echo "Too many arguments" >&2
        exit 1
    fi
    case "${type}:${1}" in
    file:fake-test)
        if [ -f autocreated ] ; then
            echo 'yes'
        else
            echo 'no'
        fi
        ;;
    *)
        echo 'yes'
        ;;
    esac
    exit 0
    ;;
autocreate)
    if [ -n "$2" ] ; then
        echo "Too many arguments" >&2
        exit 1
    fi
    case "${type}:${1}" in
    file:fake-test)
        touch autocreated
        exit 0
        ;;
    *)
        echo "Autocreate called for existing object" >&2
        exit 1
        ;;
    esac
    ;;
get)
    if [ -n "$2" ] ; then
        echo "Too many arguments" >&2
        exit 1
    fi
    case "${type}:${1}" in
    file:fake-test)
        cat data/fake-data
        exit 0
        ;;
    keytab:service/fake-srvtab)
        cat data/fake-keytab
        exit 0
        ;;
    keytab:service/fake-keytab)
        cat data/fake-keytab-2
        exit 0
        ;;
    keytab:service/fake-output)
        printf 'This is a fake keytab.'
        exit 0
        ;;
    *)
        echo "Unknown $type $1" >&2
        exit 1
        ;;
    esac
    ;;
show)
    if [ -n "$2" ] ; then
        echo "Too many arguments" >&2
        exit 1
    fi
    if [ "$type" = "file" ] && [ "$1" = "fake-test" ] ; then
        echo "Some stuff about $type $1"
        exit 0
    else
        echo "Unknown $type $1" >&2
        exit 1
    fi
    ;;
expires)
    if [ -n "$2" ] ; then
        echo "Too many arguments" >&2
        exit 1
    fi
    echo "Expiration date of $type $1"
    exit 0
    ;;
*)
    echo "Unknown command $command" >&2
    exit 1
    ;;
esac