Revision 0dbb3330 src/rm/RequestManagerImageAllocate.cc

View differences:

src/rm/RequestManagerImageAllocate.cc
29 29
    xmlrpc_c::value *   const  retval)
30 30
{
31 31
    string              session;
32
    string              image_template;
32
    string              str_template;
33

  
34
    ImageTemplate *     img_template;
33 35

  
34 36
    int                 iid;
35 37
    int                 uid;
36 38
    int                 rc;
39
    char *              error_msg = 0;
37 40

  
38 41
    ostringstream       oss;
39 42

  
......
42 45
    vector<xmlrpc_c::value> arrayData;
43 46
    xmlrpc_c::value_array * arrayresult;
44 47

  
45

  
46 48
    NebulaLog::log("ReM",Log::DEBUG,"ImageAllocate invoked");
47 49

  
48
    session        = xmlrpc_c::value_string(paramList.getString(0));
49
    image_template = xmlrpc_c::value_string(paramList.getString(1));
50
    image_template += "\n";
51

  
50
    session      = xmlrpc_c::value_string(paramList.getString(0));
51
    str_template = xmlrpc_c::value_string(paramList.getString(1));
52
    str_template += "\n";
52 53

  
53
    // First, we need to authenticate the user
54
    //--------------------------------------------------------------------------
55
    //   Authorize this request
56
    //--------------------------------------------------------------------------
54 57
    uid = ImageAllocate::upool->authenticate(session);
55 58

  
56 59
    if ( uid == -1 )
......
58 61
        goto error_authenticate;
59 62
    }
60 63

  
61
    rc = ImageAllocate::ipool->allocate(uid,image_template,&iid);
64
    //--------------------------------------------------------------------------
65
    //   Authorize this request
66
    //--------------------------------------------------------------------------
67
    img_template = new ImageTemplate;
68

  
69
    rc = img_template->parse(str_template,&error_msg);
70

  
71
    if ( rc != 0 )
72
    {
73
        goto error_parse;
74
    }
75

  
76
    if ( uid != 0 )
77
    {
78
        AuthRequest ar(uid);
79
        string      t64;
80

  
81
        ar.add_auth(AuthRequest::IMAGE,
82
                    img_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
    }
92

  
93
    //--------------------------------------------------------------------------
94
    //   Allocate the Image
95
    //--------------------------------------------------------------------------
96
    rc = ImageAllocate::ipool->allocate(uid,img_template,&iid);
62 97

  
63 98
    if ( rc < 0 )
64 99
    {
......
81 116
    oss.str(authenticate_error(method_name));
82 117
    goto error_common;
83 118

  
119
error_authorize:
120
    oss.str(authorization_error(method_name, "CREATE", "IMAGE", uid, -1));
121
    delete img_template;
122
    goto error_common;
123

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

  
132
    delete img_template;
133
    goto error_common;
134

  
84 135
error_allocate:
85 136
    oss.str(action_error(method_name, "CREATE", "IMAGE", -2, rc));
86 137
    goto error_common;

Also available in: Unified diff