Statistics
| Branch: | Tag: | Revision:

one / src / rm / RequestManagerGroupDelete.cc @ ae53d437

History | View | Annotate | Download (4.17 KB)

1
/* -------------------------------------------------------------------------- */
2
/* Copyright 2002-2011, OpenNebula Project Leads (OpenNebula.org)             */
3
/*                                                                            */
4
/* Licensed under the Apache License, Version 2.0 (the "License"); you may    */
5
/* not use this file except in compliance with the License. You may obtain    */
6
/* a copy of the License at                                                   */
7
/*                                                                            */
8
/* http://www.apache.org/licenses/LICENSE-2.0                                 */
9
/*                                                                            */
10
/* Unless required by applicable law or agreed to in writing, software        */
11
/* distributed under the License is distributed on an "AS IS" BASIS,          */
12
/* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.   */
13
/* See the License for the specific language governing permissions and        */
14
/* limitations under the License.                                             */
15
/* -------------------------------------------------------------------------- */
16

    
17
#include "RequestManager.h"
18
#include "NebulaLog.h"
19

    
20
#include "AuthManager.h"
21

    
22
/* -------------------------------------------------------------------------- */
23
/* -------------------------------------------------------------------------- */
24

    
25
void RequestManager::GroupDelete::execute(
26
    xmlrpc_c::paramList const& paramList,
27
    xmlrpc_c::value *   const  retval)
28
{
29
    string          session;
30

    
31
    int             id;
32
    Group *         group;
33
    ostringstream   oss;
34
    int             rc;
35
    int             owner;
36

    
37
    const string    method_name = "GroupDelete";
38

    
39
    /*   -- RPC specific vars --  */
40
    vector<xmlrpc_c::value> arrayData;
41
    xmlrpc_c::value_array * arrayresult;
42

    
43
    NebulaLog::log("ReM",Log::DEBUG,"GroupDelete method invoked");
44

    
45
    // Get the parameters
46
    session      = xmlrpc_c::value_string(paramList.getString(0));
47
    id           = xmlrpc_c::value_int   (paramList.getInt(1));
48

    
49
    //Authenticate the user
50
    rc = GroupDelete::upool->authenticate(session);
51

    
52
    if ( rc == -1 )
53
    {
54
        goto error_authenticate;
55
    }
56

    
57
    // Get template from the pool
58
    group = GroupDelete::gpool->get(id,true);
59

    
60
    if ( group == 0 )
61
    {
62
        goto error_get;
63
    }
64

    
65
    owner = group->get_uid();
66

    
67
    group->unlock();
68

    
69
    //Authorize the operation
70
    if ( rc != 0 ) // rc == 0 means oneadmin
71
    {
72
        AuthRequest ar(rc);
73

    
74
        ar.add_auth(AuthRequest::GROUP,
75
                    id,
76
                    AuthRequest::DELETE,
77
                    owner,
78
                    false);
79

    
80
        if (UserPool::authorize(ar) == -1)
81
        {
82
            goto error_authorize;
83
        }
84
    }
85

    
86
    // Perform the deletion from the pool
87
    group = GroupDelete::gpool->get(id,true);
88

    
89
    if ( group == 0 )
90
    {
91
        goto error_get;
92
    }
93

    
94
    rc = GroupDelete::gpool->drop(group);
95

    
96
    group->unlock();
97

    
98
    if ( rc != 0 )
99
    {
100
        goto error_delete;
101
    }
102

    
103
    // Return success
104
    arrayData.push_back(xmlrpc_c::value_boolean(true)); // SUCCESS
105
    arrayresult = new xmlrpc_c::value_array(arrayData);
106

    
107
    // Copy arrayresult into retval mem space
108
    *retval = *arrayresult;
109
    // and get rid of the original
110
    delete arrayresult;
111

    
112
    return;
113

    
114
error_authenticate:
115
    oss.str(authenticate_error(method_name));
116
    goto error_common;
117

    
118
error_authorize:
119
    oss.str(authorization_error(method_name, "DELETE", "GROUP", rc, id));
120
    goto error_common;
121

    
122
error_get:
123
    oss.str(get_error(method_name, "GROUP", id));
124
    goto error_common;
125

    
126
error_delete:
127
    oss.str(action_error(method_name, "DELETE", "GROUP", id, rc));
128
    goto error_common;
129

    
130
error_common:
131
    NebulaLog::log ("Rem",Log::ERROR,oss);
132

    
133
    arrayData.push_back(xmlrpc_c::value_boolean(false)); // FAILURE
134
    arrayData.push_back(xmlrpc_c::value_string(oss.str()));
135

    
136
    xmlrpc_c::value_array arrayresult_error(arrayData);
137

    
138
    *retval = arrayresult_error;
139

    
140
    return;
141
}
142

    
143
/* -------------------------------------------------------------------------- */
144
/* -------------------------------------------------------------------------- */