Revision 6d3d8a88

View differences:

src/rm/RequestManagerVirtualNetworkDelete.cc
25 25
void RequestManager::VirtualNetworkDelete::execute(
26 26
    xmlrpc_c::paramList const& paramList,
27 27
    xmlrpc_c::value *   const  retval)
28
{ 
28
{
29 29
    string              session;
30 30

  
31 31
    string              name;
......
33 33
    int                 uid;
34 34

  
35 35
    VirtualNetwork *    vn;
36
    
37
    int                 rc;        
36

  
37
    int                 network_owner;
38
    bool                is_public;
39

  
40
    int                 rc;
38 41
    ostringstream       oss;
39
    
42

  
40 43
    const string        method_name = "VirtualNetworkDelete";
41 44

  
42 45
    /*   -- RPC specific vars --  */
......
48 51
    // Get the parameters & host
49 52
    session   = xmlrpc_c::value_string(paramList.getString(0));
50 53
    nid       = xmlrpc_c::value_int   (paramList.getInt   (1));
51
    
52
    // Only oneadmin or the VN owner can perform operations upon the VN
54

  
55
    // First, we need to authenticate the user
53 56
    rc = VirtualNetworkDelete::upool->authenticate(session);
54
    
55
    if ( rc == -1 )                             
56
    {                                            
57
        goto error_authenticate;                     
57

  
58
    if ( rc == -1 )
59
    {
60
        goto error_authenticate;
61
    }
62

  
63
    // Retrieve VN from the pool
64
    vn = vnpool->get(nid,true);
65

  
66
    if ( vn == 0 )
67
    {
68
        goto error_vn_get;
58 69
    }
59
    
70

  
71
    network_owner = vn->get_uid();
72
    is_public     = vn->isPublic();
73

  
74
    vn->unlock();
75

  
76

  
60 77
    //Authorize the operation
61 78
    if ( rc != 0 ) // rc == 0 means oneadmin
62 79
    {
63 80
        AuthRequest ar(rc);
64 81

  
65
        ar.add_auth(AuthRequest::NET,nid,AuthRequest::DELETE,0,false);
82
        ar.add_auth(AuthRequest::NET,
83
                    nid,
84
                    AuthRequest::DELETE,
85
                    network_owner,
86
                    is_public);
66 87

  
67 88
        if (UserPool::authorize(ar) == -1)
68 89
        {
69 90
            goto error_authorize;
70 91
        }
71 92
    }
72
    
73
    // Retrieve VN from the pool 
74
    vn = vnpool->get(nid,true);    
75
   
76
    if ( vn == 0 )                             
77
    {                                            
78
        goto error_vn_get;                     
93

  
94
    // Retrieve VN from the pool
95
    vn = vnpool->get(nid,true);
96

  
97
    if ( vn == 0 )
98
    {
99
        goto error_vn_get;
79 100
    }
80 101

  
81 102
    uid = vn->get_uid();
82
   
103

  
83 104
    rc = vnpool->drop(vn);
84 105

  
85 106
    vn->unlock();
86
   
87
    // All nice, return the host info to the client  
107

  
108
    // All nice, return the host info to the client
88 109
    arrayData.push_back(xmlrpc_c::value_boolean( rc == 0 )); // SUCCESS
89 110
    arrayresult = new xmlrpc_c::value_array(arrayData);
90
   
111

  
91 112
    // Copy arrayresult into retval mem space
92 113
    *retval = *arrayresult;
93 114
    // and get rid of the original
94 115
    delete arrayresult;
95
   
116

  
96 117
    return;
97 118

  
98 119
error_authenticate:
99 120
    oss.str(authenticate_error(method_name));
100 121
    goto error_common;
101
    
122

  
102 123
error_authorize:
103 124
    oss.str(authorization_error(method_name, "DELETE", "NET", rc, nid));
104 125
    goto error_common;
......
106 127
error_vn_get:
107 128
    oss.str(get_error(method_name, "NET", nid));
108 129
    goto error_common;
109
 
130

  
110 131
error_common:
111 132
    NebulaLog::log ("ReM",Log::ERROR,oss);
112
  
133

  
113 134
    arrayData.push_back(xmlrpc_c::value_boolean(false)); // FAILURE
114 135
    arrayData.push_back(xmlrpc_c::value_string(oss.str()));
115
  
136

  
116 137
    xmlrpc_c::value_array arrayresult_error(arrayData);
117
  
138

  
118 139
    *retval = arrayresult_error;
119
  
140

  
120 141
    return;
121 142
}
122 143

  
src/rm/RequestManagerVirtualNetworkPublish.cc
31 31
    string              session;
32 32

  
33 33
    int                 nid;
34
    bool                publish_flag; 
34
    bool                publish_flag;
35 35
    int                 uid;
36
    
36

  
37 37
    VirtualNetwork *    vn;
38 38

  
39
    int                 network_owner;
40
    bool                is_public;
41

  
39 42
    ostringstream       oss;
40 43

  
41 44
    const string  method_name = "VirtualNetworkPublish";
......
57 60
    {
58 61
        goto error_authenticate;
59 62
    }
60
    
63

  
61 64
    // Get virtual network from the VirtualNetworkPool
62
    vn = VirtualNetworkPublish::vnpool->get(nid,true);    
63
                                                 
64
    if ( vn == 0 )                             
65
    {                                            
66
        goto error_vn_get;                     
65
    vn = VirtualNetworkPublish::vnpool->get(nid,true);
66

  
67
    if ( vn == 0 )
68
    {
69
        goto error_vn_get;
67 70
    }
68
    
71

  
72
    network_owner = vn->get_uid();
73
    is_public     = vn->isPublic();
74

  
75
    vn->unlock();
76

  
69 77
    //Authorize the operation
70 78
    if ( uid != 0 ) // uid == 0 means oneadmin
71 79
    {
......
74 82
        ar.add_auth(AuthRequest::NET,
75 83
                    nid,
76 84
                    AuthRequest::MANAGE,
77
                    0,
78
                    vn->isPublic());
85
                    network_owner,
86
                    is_public);
79 87

  
80 88
        if (UserPool::authorize(ar) == -1)
81 89
        {
......
83 91
        }
84 92
    }
85 93

  
94
    // Get virtual network from the VirtualNetworkPool
95
    vn = VirtualNetworkPublish::vnpool->get(nid,true);
96

  
97
    if ( vn == 0 )
98
    {
99
        goto error_vn_get;
100
    }
101

  
86 102
    vn->publish(publish_flag);
87
    
103

  
88 104
    VirtualNetworkPublish::vnpool->update(vn);
89
    
105

  
90 106
    vn->unlock();
91 107

  
92 108
    arrayData.push_back(xmlrpc_c::value_boolean(true));
......
103 119
error_authenticate:
104 120
     oss.str(authenticate_error(method_name));
105 121
    goto error_common;
106
    
122

  
107 123
error_vn_get:
108 124
    oss.str(get_error(method_name, "NET", nid));
109 125
    goto error_common;
110
    
126

  
111 127
error_authorize:
112 128
    oss.str(authorization_error(method_name, "MANAGE", "NET", uid, nid));
113 129
    vn->unlock();

Also available in: Unified diff