Revision 0dbb3330 src/rm/RequestManagerVirtualNetworkAllocate.cc

View differences:

src/rm/RequestManagerVirtualNetworkAllocate.cc
27 27
    xmlrpc_c::value *   const  retval)
28 28
{
29 29
    string              session;
30
    string              username;
31
    string              password;
32 30
    string              name;
33
    string              stemplate;
31
    string              str_template;
32

  
33
    VirtualNetworkTemplate * vn_template;
34 34

  
35 35
    int                 nid;
36 36
    int                 uid;
37 37
    int                 rc;
38

  
39
    User *              user;
38
    char *              error_msg = 0;
40 39

  
41 40
    ostringstream       oss;
42
    
41

  
43 42
    const string        method_name = "VirtualNetworkAllocate";
44 43

  
45 44
    /*   -- RPC specific vars --  */
......
49 48
    NebulaLog::log("ReM",Log::DEBUG,"VirtualNetworkAllocate method invoked");
50 49

  
51 50
    // Get the parameters & host
52
    session   = xmlrpc_c::value_string(paramList.getString(0));
53
    stemplate = xmlrpc_c::value_string(paramList.getString(1));
51
    session      = xmlrpc_c::value_string(paramList.getString(0));
52
    str_template = xmlrpc_c::value_string(paramList.getString(1));
53

  
54
    //--------------------------------------------------------------------------
55
    //   Authorize this request
56
    //--------------------------------------------------------------------------
57
    uid = VirtualNetworkAllocate::upool->authenticate(session);
54 58

  
55
    if ( User::split_secret(session,username,password) != 0 )
59
    if ( uid == -1 )
56 60
    {
57 61
        goto error_authenticate;
58 62
    }
59 63

  
60
    // Now let's get the user
61
    user = VirtualNetworkAllocate::upool->get(username,true);
64
    //--------------------------------------------------------------------------
65
    //   Authorize this request
66
    //--------------------------------------------------------------------------
67
    vn_template = new VirtualNetworkTemplate;
62 68

  
63
    if ( user == 0 )
69
    rc = vn_template->parse(str_template,&error_msg);
70

  
71
    if ( rc != 0 )
64 72
    {
65
        goto error_get_user;
73
        goto error_parse;
66 74
    }
67 75

  
68
    uid = user->get_uid();
76
    if ( uid != 0 )
77
    {
78
        AuthRequest ar(uid);
79
        string      t64;
80

  
81
        ar.add_auth(AuthRequest::NET,
82
                    vn_template->to_xml(t64),
83
                    AuthRequest::CREATE,
84
                    uid,
85
                    false);
86

  
87
        if (UserPool::authorize(ar) == -1)
88
        {
89
            goto error_authorize;
90
        }
91
    }
69 92

  
70
    user->unlock();
71
    
72
    rc = vnpool->allocate(uid,stemplate,&nid);
93
    //--------------------------------------------------------------------------
94
    //   Allocate the Virtual Network
95
    //--------------------------------------------------------------------------
96
    rc = vnpool->allocate(uid,vn_template,&nid);
73 97

  
74 98
    if ( rc < 0 )
75 99
    {
......
92 116
    oss.str(authenticate_error(method_name));
93 117
    goto error_common;
94 118

  
95
error_get_user:
96
    oss.str(get_error(method_name, "USER", -1));
119
error_authorize:
120
    oss.str(authorization_error(method_name, "CREATE", "VNET", uid, -1));
121
    delete vn_template;
97 122
    goto error_common;
98
    
123

  
124
error_parse:
125
    oss.str(action_error(method_name, "PARSE", "VNET TEMPLATE",-2,rc));
126
    if (error_msg != 0)
127
    {
128
        oss << "Reason: " << error_msg;
129
        free(error_msg);
130
    }
131

  
132
    delete vn_template;
133
    goto error_common;
134

  
99 135
error_vn_allocate:
100 136
    oss.str(action_error(method_name, "CREATE", "NET", -2, rc));
101 137
    goto error_common;

Also available in: Unified diff