Statistics
| Branch: | Tag: | Revision:

one / src / rm / RequestManagerGroupAllocate.cc @ ae53d437

History | View | Annotate | Download (3.95 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::GroupAllocate::execute(
26
    xmlrpc_c::paramList const& paramList,
27
    xmlrpc_c::value *   const  retval)
28
{
29
    string              session;
30
    string              error_str;
31

    
32
    string              name;
33
    int                 id;
34

    
35
    const string        method_name = "GroupAllocate";
36

    
37
    int                 rc, uid;
38
    ostringstream       oss;
39

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

    
44
    NebulaLog::log("ReM",Log::DEBUG,"GroupAllocate method invoked");
45

    
46
    // Get the parameters
47
    session      = xmlrpc_c::value_string(paramList.getString(0));
48
    name         = xmlrpc_c::value_string(paramList.getString(1));
49

    
50
    //Authenticate the user
51
    uid = GroupAllocate::upool->authenticate(session);
52

    
53
    if ( uid == -1 )
54
    {
55
        goto error_authenticate;
56
    }
57

    
58
    //Authorize the operation
59
    if ( uid != 0 ) // uid == 0 means oneadmin
60
    {
61
        AuthRequest ar(uid);
62

    
63
        ar.add_auth(AuthRequest::GROUP,
64
                    -1,
65
                    AuthRequest::CREATE,
66
                    uid,
67
                    false);
68

    
69
        if (UserPool::authorize(ar) == -1)
70
        {
71
            goto error_authorize;
72
        }
73
    }
74

    
75
    // Perform the allocation in the pool
76
    rc = GroupAllocate::gpool->allocate(uid, name, &id, error_str);
77

    
78
    if ( rc == -1 )
79
    {
80
        goto error_allocate;
81
    }
82

    
83
    // All nice, return the new id to client
84
    arrayData.push_back(xmlrpc_c::value_boolean(true)); // SUCCESS
85
    arrayData.push_back(xmlrpc_c::value_int(id));
86
    arrayresult = new xmlrpc_c::value_array(arrayData);
87
    // Copy arrayresult into retval mem space
88
    *retval = *arrayresult;
89
    // and get rid of the original
90
    delete arrayresult;
91

    
92
    return;
93

    
94
error_authenticate:
95
    oss.str(authenticate_error(method_name));
96
    goto error_common;
97

    
98
error_authorize:
99
    oss.str(authorization_error(method_name, "CREATE", "GROUP", uid, -1));
100
    goto error_common;
101

    
102
error_allocate:
103
    oss << action_error(method_name, "CREATE", "GROUP", -2, 0);
104
    oss << " " << error_str;
105
    goto error_common;
106

    
107
error_common:
108

    
109
    arrayData.push_back(xmlrpc_c::value_boolean(false));  // FAILURE
110
    arrayData.push_back(xmlrpc_c::value_string(oss.str()));
111

    
112
    NebulaLog::log("ReM",Log::ERROR,oss);
113

    
114
    xmlrpc_c::value_array arrayresult_error(arrayData);
115

    
116
    *retval = arrayresult_error;
117

    
118
    return;
119
}
120

    
121
/* -------------------------------------------------------------------------- */
122
/* -------------------------------------------------------------------------- */