Revision 1035fe77

View differences:

include/ImagePool.h
29 29

  
30 30
using namespace std;
31 31

  
32
class AuthRequest;
33

  
34 32
/**
35 33
 *  The Image Pool class.
36 34
 */
......
170 168
     *    @param disk the disk to be generated
171 169
     *    @return 0 on success, -1 error, -2 not using the pool
172 170
     */
173
    int disk_attribute(VectorAttribute * disk, int * index, AuthRequest * ar);
171
    int disk_attribute(VectorAttribute * disk, int * index);
174 172

  
175 173
    static const string& source_prefix()
176 174
    {
include/VirtualMachine.h
31 31
/* -------------------------------------------------------------------------- */
32 32
/* -------------------------------------------------------------------------- */
33 33

  
34
class AuthRequest;
35

  
36 34
/**
37 35
 *  The Virtual Machine class. It represents a VM...
38 36
 */
......
704 702
     *  Get all network leases for this Virtual Machine
705 703
     *  @return 0 if success
706 704
     */
707
    int get_network_leases(AuthRequest *ar);
705
    int get_network_leases();
708 706

  
709 707
    /**
710 708
     *  Releases all network leases taken by this Virtual Machine
......
715 713
     *  Get all disk images for this Virtual Machine
716 714
     *  @return 0 if success
717 715
     */
718
    int get_disk_images(AuthRequest *ar);
716
    int get_disk_images();
719 717

  
720 718
    /**
721 719
     *  Releases all disk images taken by this Virtual Machine
include/VirtualNetworkPool.h
24 24

  
25 25
using namespace std;
26 26

  
27
class AuthRequest;
28

  
29 27
/**
30 28
 *  The Virtual Network Pool class. ...
31 29
 */
......
88 86
     *    @param vid of the VM requesting the lease
89 87
     *    @return 0 on success, -1 error, -2 not using the pool
90 88
     */
91
    int nic_attribute(VectorAttribute * nic, int vid, AuthRequest *ar);
89
    int nic_attribute(VectorAttribute * nic, int vid);
92 90

  
93 91
    /**
94 92
     *  Updates the template of a VN, adding a new attribute (replacing it if
src/image/Image.cc
210 210

  
211 211
    source = tmp_sourcestream.str();
212 212

  
213
    // ------------------------------------------------------------------------
214
    // Authorize this request
215
    // ------------------------------------------------------------------------
216

  
217
    if ( uid != 0 ) // uid == 0 means oneadmin
218
    {
219
        string      t64;
220
        AuthRequest ar(uid);
221

  
222
        ar.add_auth(AuthRequest::IMAGE,
223
                    image_template.to_xml(t64),
224
                    AuthRequest::CREATE,
225
                    uid,
226
                    public_img);
227

  
228
        if (UserPool::authorize(ar) == -1)
229
        {
230
            goto error_authorize;
231
        }
232
    }
233

  
234 213
    // ------------ INSERT THE TEMPLATE --------------------
235 214

  
236 215
    if ( image_template.id == -1 )
......
270 249
    NebulaLog::log("IMG", Log::ERROR, "Incorrect TYPE in image template");
271 250
    goto error_common;
272 251

  
273
error_authorize:
274
    NebulaLog::log("IMG", Log::ERROR, "Error authorizing Image creation");
275
    goto error_common;
276

  
277 252
error_common:
278 253
    return -1;
279 254
}
......
560 535
{
561 536
    string  overwrite;
562 537
    string  saveas;
563
    string  name;
564 538
    string  bus;
565 539

  
566 540
    ostringstream  iid;
567 541

  
568
    name      = disk->vector_value("NAME");
569 542
    overwrite = disk->vector_value("OVERWRITE");
570 543
    saveas    = disk->vector_value("SAVE_AS");
571 544
    bus       = disk->vector_value("BUS");
......
595 568

  
596 569
    map<string,string> new_disk;
597 570

  
598
    new_disk.insert(make_pair("NAME",name));
599
    new_disk.insert(make_pair("IID", iid.str()));
600

  
601
    new_disk.insert(make_pair("SOURCE", source));
571
    new_disk.insert(make_pair("IMAGE",    name));
572
    new_disk.insert(make_pair("IMAGE_ID", iid.str()));
573
    new_disk.insert(make_pair("SOURCE",   source));
602 574

  
603 575
    if (!overwrite.empty())
604 576
    {
src/image/ImagePool.cc
19 19
/* ************************************************************************** */
20 20

  
21 21
#include "ImagePool.h"
22
#include "AuthManager.h"
23 22

  
24 23
/* -------------------------------------------------------------------------- */
25 24
/* -------------------------------------------------------------------------- */
......
190 189
/* -------------------------------------------------------------------------- */
191 190

  
192 191
int ImagePool::disk_attribute(VectorAttribute * disk,
193
                              int *             index,
194
                              AuthRequest *     ar)
192
                              int *             index)
195 193
{
196 194
    string  source;
197
    Image * img;
195
    Image * img = 0;
198 196

  
199
    source = disk->vector_value("NAME");
197
    source = disk->vector_value("IMAGE");
200 198

  
201 199
    if (source.empty())
202 200
    {
203
        return -2;
204
    }
201
        istringstream   is;
202
        int             image_id;
203

  
204
        source = disk->vector_value("IMAGE_ID");
205 205

  
206
    img = get(source,true);
206
        if (source.empty())
207
        {
208
            return -2;
209
        }
210

  
211
        is.str(source);
212
        is >> image_id;
213

  
214
        if( !is.fail() )
215
        {
216
            img = get(image_id,true);
217
        }
218
    }
219
    else
220
    {
221
        img = get(source,true);
222
    }
207 223

  
208 224
    if (img == 0)
209 225
    {
......
212 228

  
213 229
    int rc = img->disk_attribute(disk,index);
214 230

  
215
    ar->add_auth(AuthRequest::IMAGE,
216
                 img->get_iid(),
217
                 AuthRequest::USE,
218
                 img->get_uid(),
219
                 img->isPublic());
220

  
221 231
    img->unlock();
222 232

  
223 233
    return rc;
src/vm/VirtualMachine.cc
26 26
#include "VirtualMachine.h"
27 27
#include "VirtualNetworkPool.h"
28 28
#include "NebulaLog.h"
29
#include "AuthManager.h"
30 29

  
31 30
#include "Nebula.h"
32 31

  
......
268 267
    string              value;
269 268
    ostringstream       oss;
270 269

  
271
    AuthRequest ar(uid);
272

  
273 270
    // -----------------------------------------------------------------------
274 271
    // Set a template ID if it wasn't already assigned
275 272
    // ------------------------------------------------------------------------
......
306 303
    // Get network leases
307 304
    // ------------------------------------------------------------------------
308 305

  
309
    rc = get_network_leases(&ar);
306
    rc = get_network_leases();
310 307

  
311 308
    if ( rc != 0 )
312 309
    {
......
317 314
    // Get disk images
318 315
    // ------------------------------------------------------------------------
319 316

  
320
    rc = get_disk_images(&ar);
317
    rc = get_disk_images();
321 318

  
322 319
    if ( rc != 0 )
323 320
    {
......
345 342
    parse_graphics();
346 343

  
347 344
    // ------------------------------------------------------------------------
348
    // Authorize this request
349
    // ------------------------------------------------------------------------
350

  
351
    if ( uid != 0 ) // uid == 0 means oneadmin
352
    {
353
        string t64;
354

  
355
        ar.add_auth(AuthRequest::VM,
356
                    vm_template.to_xml(t64),
357
                    AuthRequest::CREATE,
358
                    uid,
359
                    false);
360

  
361
        if (UserPool::authorize(ar) == -1)
362
        {
363
            goto error_authorize;
364
        }
365
    }
366

  
367
    // ------------------------------------------------------------------------
368 345
    // Insert the template first, so we get a valid template ID. Then the VM
369 346
    // ------------------------------------------------------------------------
370 347

  
......
410 387
    NebulaLog::log("ONE",Log::ERROR, "Could not parse REQUIREMENTS for VM");
411 388
    goto error_common;
412 389

  
413
error_authorize:
414
    NebulaLog::log("ONE",Log::ERROR, "Error authorizing VM creation");
415

  
416 390
error_common:
417 391
    release_network_leases();
418 392
    release_disk_images();
......
819 793
/* -------------------------------------------------------------------------- */
820 794
/* -------------------------------------------------------------------------- */
821 795

  
822
int VirtualMachine::get_disk_images(AuthRequest *ar)
796
int VirtualMachine::get_disk_images()
823 797
{
824 798
    int                   num_disks, rc;
825 799
    vector<Attribute  * > disks;
......
841 815
            continue;
842 816
        }
843 817

  
844
        rc = ipool->disk_attribute(disk, &index, ar);
818
        rc = ipool->disk_attribute(disk, &index);
845 819

  
846 820
        if (rc == -1) // 0 OK, -2 not using the Image pool
847 821
        {
......
879 853
            continue;
880 854
        }
881 855

  
882
        iid = disk->vector_value("IID");
856
        iid = disk->vector_value("IMAGE_ID");
883 857

  
884 858
        if ( iid.empty() )
885 859
        {
......
902 876
/* -------------------------------------------------------------------------- */
903 877
/* -------------------------------------------------------------------------- */
904 878

  
905
int VirtualMachine::get_network_leases(AuthRequest *ar)
879
int VirtualMachine::get_network_leases()
906 880
{
907 881
    int                   num_nics, rc;
908 882
    vector<Attribute  * > nics;
......
923 897
            continue;
924 898
        }
925 899

  
926
        rc = vnpool->nic_attribute(nic, oid, ar);
900
        rc = vnpool->nic_attribute(nic, oid);
927 901

  
928 902
        if (rc == -1)
929 903
        {
......
962 936
            continue;
963 937
        }
964 938

  
965
        vnid = nic->vector_value("VNID");
939
        vnid = nic->vector_value("NETWORK_ID");
966 940

  
967 941
        if ( vnid.empty() )
968 942
        {
src/vnm/VirtualNetwork.cc
317 317

  
318 318
    vn_template.erase("PUBLIC");
319 319

  
320
    // ------------------------------------------------------------------------
321
    // Authorize this request
322
    // ------------------------------------------------------------------------
323

  
324
    if ( uid != 0 ) // uid == 0 means oneadmin
325
    {
326
        string      t64;
327
        AuthRequest ar(uid);
328

  
329
        ar.add_auth(AuthRequest::NET,
330
                    vn_template.to_xml(t64),
331
                    AuthRequest::CREATE,
332
                    uid,
333
                    public_vnet);
334

  
335
        if (UserPool::authorize(ar) == -1)
336
        {
337
            goto error_authorize;
338
        }
339
    }
340

  
341 320
    // ------------ INSERT THE TEMPLATE --------------------
342 321

  
343 322
    if ( vn_template.id == -1 )
......
440 419
    ose << "No BRIDGE in template for Virtual Network id " << oid;
441 420
    goto error_common;
442 421

  
443
error_authorize:
444
    ose << "Error authorizing Virtual Network creation";
445
    goto error_common;
446

  
447 422
error_template:
448 423
    ose << "Can not insert in DB template for Virtual Network id " << oid;
449 424
    goto error_common;
......
640 615
{
641 616
    int rc;
642 617

  
643
    string  network;
644 618
    string  model;
645 619
    string  ip;
646 620
    string  mac;
......
649 623

  
650 624
    map<string,string> new_nic;
651 625

  
652
    network = nic->vector_value("NETWORK");
653 626
    model   = nic->vector_value("MODEL");
654 627
    ip      = nic->vector_value("IP");
655 628
    vnid   << oid;
......
676 649
    //                       NEW NIC ATTRIBUTES
677 650
    //--------------------------------------------------------------------------
678 651

  
679
    new_nic.insert(make_pair("NETWORK",network));
680
    new_nic.insert(make_pair("MAC"    ,mac));
681
    new_nic.insert(make_pair("BRIDGE" ,bridge));
682
    new_nic.insert(make_pair("VNID"   ,vnid.str()));
683
    new_nic.insert(make_pair("IP"     ,ip));
652
    new_nic.insert(make_pair("NETWORK"   ,name));
653
    new_nic.insert(make_pair("MAC"       ,mac));
654
    new_nic.insert(make_pair("BRIDGE"    ,bridge));
655
    new_nic.insert(make_pair("NETWORK_ID",vnid.str()));
656
    new_nic.insert(make_pair("IP"        ,ip));
684 657

  
685 658
    if (!model.empty())
686 659
    {
src/vnm/VirtualNetworkPool.cc
16 16

  
17 17
#include "VirtualNetworkPool.h"
18 18
#include "NebulaLog.h"
19
#include "AuthManager.h"
20 19

  
21 20
#include <sstream>
22 21
#include <ctype.h>
......
220 219
/* -------------------------------------------------------------------------- */
221 220

  
222 221
int VirtualNetworkPool::nic_attribute(VectorAttribute * nic,
223
                                      int               vid,
224
                                      AuthRequest *     ar)
222
                                      int               vid)
225 223
{
226 224
    string           network;
227
    VirtualNetwork * vnet;
225
    VirtualNetwork * vnet = 0;
228 226

  
229 227
    network = nic->vector_value("NETWORK");
230 228

  
231 229
    if (network.empty())
232 230
    {
231
        istringstream   is;
232
        int             network_id;
233

  
234
        network = nic->vector_value("NETWORK_ID");
235

  
236
        if(network.empty())
237
        {
238
            return -2;
239
        }
240

  
241
        is.str(network);
242
        is >> network_id;
243

  
244
        if( !is.fail() )
245
        {
246
            vnet = get(network_id,true);
247
        }
248

  
233 249
        return -2;
234 250
    }
235

  
236
    vnet = get(network,true);
251
    else
252
    {
253
        vnet = get(network,true);
254
    }
237 255

  
238 256
    if (vnet == 0)
239 257
    {
......
242 260

  
243 261
    int rc = vnet->nic_attribute(nic,vid);
244 262

  
245
    ar->add_auth(AuthRequest::NET,
246
                 vnet->get_vnid(),
247
                 AuthRequest::USE,
248
                 vnet->get_uid(),
249
                 vnet->isPublic());
250

  
251 263
    vnet->unlock();
252 264

  
253 265
    return rc;
254
}
266
}
267

  

Also available in: Unified diff