Statistics
| Branch: | Tag: | Revision:

one / src / rm / RequestManagerPoolInfoFilter.cc @ 01d932ad

History | View | Annotate | Download (3.45 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 "RequestManagerPoolInfoFilter.h"
18

    
19
using namespace std;
20

    
21
/* ------------------------------------------------------------------------- */
22
/* ------------------------------------------------------------------------- */
23

    
24
const int RequestManagerPoolInfoFilter::ALL = -2;
25

    
26
const int RequestManagerPoolInfoFilter::MINE = -3;      
27

    
28
const int RequestManagerPoolInfoFilter::MINE_GROUP = -1; 
29

    
30
/* ------------------------------------------------------------------------- */
31
/* ------------------------------------------------------------------------- */
32

    
33
void RequestManagerPoolInfoFilter::request_execute(
34
    int uid, 
35
    int gid,
36
    xmlrpc_c::paramList const& paramList)
37
{
38
    int filter_flag = xmlrpc_c::value_int(paramList.getInt(1));
39

    
40
    ostringstream oss, where_string;
41

    
42
    int rc;
43
 
44
    switch(filter_flag)
45
    {
46
        case MINE:
47
            where_string << "UID=" << uid;
48
            break;
49

    
50
        case ALL:
51
            break;
52

    
53
        case MINE_GROUP:
54
            where_string << "UID=" << uid << " OR GID=" << gid;
55
            break;
56

    
57
        default:
58
            if ( filter_flag >= 0 )
59
            {
60
                where_string << "UID=" << filter_flag;
61
            }
62
            else
63
            {
64
                goto error_filter;
65
            }
66
            break;
67
    }
68

    
69
    //Authorize the operation
70
    if ( uid != 0 && (filter_flag == ALL || filter_flag >= 0) ) // uid == 0 means oneadmin
71
    {
72
        AuthRequest ar(uid);
73

    
74
        ar.add_auth(auth_object,
75
                    -1,
76
                    AuthRequest::INFO_POOL,
77
                    0,
78
                    false);
79

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

    
86
    // Call the template pool dump
87
    rc = pool->dump(oss,where_string.str());
88

    
89
    if ( rc != 0 )
90
    {
91
        goto error_dump;
92
    }
93

    
94
    success_response(oss.str());
95

    
96
    return;
97

    
98
error_filter:
99
    failure_response(XML_RPC_API, "Incorrect filter_flag, must be >= -3.");
100
    return;
101

    
102
//TODO Get the object name from the AuthRequest Class
103
error_authorize:
104
    failure_response(AUTHORIZATION,
105
                     authorization_error("INFO","USER",uid,-1));
106
    return;
107

    
108
error_dump: //TBD Improve Error messages for DUMP
109
    oss.str();
110
    failure_response(INTERNAL,"Internal Error");
111
    return;
112
}
113