Revision b0ddfd38

View differences:

include/PoolObjectSQL.h
69 69
        return uid;
70 70
    };
71 71

  
72
    // TODO: Check if uid == -1?
73
    // What happens with user, is the user his owner, or uid = -1?
74
    int set_uid(int _uid)
75
    {
76
        uid = _uid;
77
        return 0;
78
    }
79

  
72 80
    int get_gid()
73 81
    {
74 82
        return gid;
75 83
    };
76 84

  
77
    void set_gid(int _gid)
85
    int set_gid(int _gid)
78 86
    {
87
        if( gid == -1 )
88
        {
89
            return -1;
90
        }
91

  
79 92
        gid = _gid;
93
        return 0;
80 94
    };
81 95

  
82 96
    /* --------------------------------------------------------------------- */
include/RequestManager.h
312 312
        return oss.str();
313 313
    }
314 314

  
315

  
316
    // ----------------------------------------------------------------------
317
    // ----------------------------------------------------------------------
318
    //                          Constants
319
    // ----------------------------------------------------------------------
320
    // ----------------------------------------------------------------------
321

  
322
    // TODO: enum of Objects is maintained in AuthManager.h, could be moved
323
    // to Nebula.h
324
    enum Object
325
    {
326
        VM,
327
        HOST,
328
        NET,
329
        IMAGE,
330
        USER,
331
        CLUSTER,
332
        TEMPLATE,
333
        GROUP
334
    };
335

  
336
    PoolSQL * get_pool(Object ob)
337
    {
338
        switch (ob)
339
        {
340
            case VM:       return static_cast<PoolSQL*>(vmpool);
341
            case HOST:     return static_cast<PoolSQL*>(hpool);
342
            case NET:      return static_cast<PoolSQL*>(vnpool);
343
            case IMAGE:    return static_cast<PoolSQL*>(ipool);
344
            case USER:     return static_cast<PoolSQL*>(upool);
345
            case CLUSTER:  return static_cast<PoolSQL*>(cpool);
346
            case TEMPLATE: return static_cast<PoolSQL*>(tpool);
347
            case GROUP:    return static_cast<PoolSQL*>(gpool);
348
        }
349
    };
350

  
351
    string get_method_prefix(Object ob)
352
    {
353
        switch (ob)
354
        {
355
            case VM:       return "VirtualMachine";
356
            case HOST:     return "Host";
357
            case NET:      return "VirtualNetwork";
358
            case IMAGE:    return "Image";
359
            case USER:     return "User";
360
            case CLUSTER:  return "Cluster";
361
            case TEMPLATE: return "Template";
362
            case GROUP:    return "Group";
363
        }
364
    };
365

  
366
    string get_object_name(Object ob)
367
    {
368
        switch (ob)
369
        {
370
            case VM:       return "VM";
371
            case HOST:     return "HOST";
372
            case NET:      return "NET";
373
            case IMAGE:    return "IMAGE";
374
            case USER:     return "USER";
375
            case CLUSTER:  return "CLUSTER";
376
            case TEMPLATE: return "TEMPLATE";
377
            case GROUP:    return "GROUP";
378
        }
379
    };
380

  
315 381
    // ----------------------------------------------------------------------
316 382
    // ----------------------------------------------------------------------
317 383
    //                          XML-RPC Methods
......
319 385
    // ----------------------------------------------------------------------
320 386

  
321 387
    /* ---------------------------------------------------------------------- */
388
    /*                     Generic Helpers                                    */
389
    /* ---------------------------------------------------------------------- */
390

  
391
    class GenericChown: public xmlrpc_c::method
392
    {
393
    public:
394
        GenericChown(RequestManager  *  _rm,
395
                     Object             _ob):
396
                        rm(_rm),
397
                        ob(_ob)
398
        {
399
            _signature="A:siii";
400
            _help="Changes the owner and/or group";
401
        };
402

  
403
        ~GenericChown(){};
404

  
405
        void execute(
406
            xmlrpc_c::paramList const& paramList,
407
            xmlrpc_c::value *   const  retvalP);
408

  
409
    private:
410
        RequestManager *    rm;
411
        Object              ob;
412
    };
413

  
414
    /* ---------------------------------------------------------------------- */
322 415
    /*                     Virtual Machine Interface                          */
323 416
    /* ---------------------------------------------------------------------- */
324 417
    class VirtualMachineAllocate: public xmlrpc_c::method
src/cli/oneimage
254 254

  
255 255
* nonpersistent (Makes an Image non persistent)
256 256
    oneimage nonpersistent <image_id>
257
    
257

  
258
* chown (Changes the Image owner and group)
259
    oneimage chown <image_id> <owner_id> [<group_id>]
260

  
261
* chgrp (Changes the Image group)
262
    oneimage chgrp <image_id> <group_id>
263

  
258 264
* list (Shows Images in the pool)
259 265
    oneimage list <filter_flag>
260 266
    
......
440 446
    if is_successful?(result)
441 447
        puts "Image made nonpersistent" if ops[:verbose]
442 448
    end
443
    
449

  
450
when "chown"
451
    check_parameters("chown", 2)
452

  
453
    image_id = get_image_id(ARGV[0])
454
    new_uid  = ARGV[1].to_i
455
    new_gid = ( ARGV.length > 2 ) ? ARGV[2].to_i : -1
456

  
457
    image = OpenNebula::Image.new_with_id(image_id, get_one_client)
458

  
459
    result = image.chown( new_uid, new_gid )
460
    if is_successful?(result)
461
        puts "Image user/group changed" if ops[:verbose]
462
    end
463

  
464
when "chgrp"
465
    check_parameters("chgrp", 2)
466

  
467
    image_id = get_image_id(ARGV[0])
468
    new_uid  = -1
469
    new_gid  = ARGV[1].to_i
470

  
471
    image = OpenNebula::Image.new_with_id(image_id, get_one_client)
472

  
473
    result = image.chown( new_uid, new_gid )
474
    if is_successful?(result)
475
        puts "Image group changed" if ops[:verbose]
476
    end
477

  
444 478
when "list"
445 479
    ops.merge!(get_user_flags)
446 480
    if !ops[:xml]
src/cli/onetemplate
195 195
* unpublish (Unpublish an Template)
196 196
    onetemplate unpublish <template_id>
197 197

  
198
* chown (Changes the Template owner and group)
199
    onetemplate chown <template_id> <owner_id> [<group_id>]
200

  
201
* chgrp (Changes the Template group)
202
    onetemplate chgrp <template_id> <group_id>
203

  
198 204
* list (Shows Templates in the pool)
199 205
    onetemplate list <filter_flag>
200 206

  
......
337 343
        puts "Template unpublished" if ops[:verbose]
338 344
    end
339 345

  
346
when "chown"
347
    check_parameters("chown", 2)
348

  
349
    obj_id = get_template_id(ARGV[0])
350
    new_uid  = ARGV[1].to_i
351
    new_gid = ( ARGV.length > 2 ) ? ARGV[2].to_i : -1
352

  
353
    obj = OpenNebula::Template.new_with_id(obj_id, get_one_client)
354

  
355
    result = obj.chown( new_uid, new_gid )
356
    if is_successful?(result)
357
        puts "Template user/group changed" if ops[:verbose]
358
    end
359

  
360
when "chgrp"
361
    check_parameters("chgrp", 2)
362

  
363
    obj_id = get_template_id(ARGV[0])
364
    new_uid  = -1
365
    new_gid  = ARGV[1].to_i
366

  
367
    obj = OpenNebula::Template.new_with_id(obj_id, get_one_client)
368

  
369
    result = obj.chown( new_uid, new_gid )
370
    if is_successful?(result)
371
        puts "Template group changed" if ops[:verbose]
372
    end
373

  
340 374
when "list"
341 375
    ops.merge!(get_user_flags)
342 376
    if !ops[:xml]
src/cli/oneuser
124 124
* passwd (Changes the given user's password)
125 125
    oneuser passwd <id> password
126 126

  
127
* chgrp (Changes the User group)
128
    oneuser chgrp <id> <group_id>
127 129

  
128 130
Information Columns:
129 131

  
......
265 267
        puts
266 268
    end
267 269

  
270
when "chgrp"
271
    check_parameters("chgrp", 2)
272

  
273
    obj_id = get_user_id(ARGV[0])
274
    new_gid  = ARGV[1].to_i
275

  
276
    obj = OpenNebula::User.new_with_id(obj_id, get_one_client)
277

  
278
    result = obj.chgrp( new_gid )
279
    if is_successful?(result)
280
        puts "User group changed" if ops[:verbose]
281
    end
282

  
268 283
when "list"
269 284
    if !ops[:xml]
270 285
        uplist=UPShow.new
src/cli/onevm
416 416

  
417 417
    States: ANY, except SUSPENDED or DONE
418 418

  
419
* chown (Changes the VM owner and group)
420
    onevm chown <vm_id> <owner_id> [<group_id>]
421

  
422
* chgrp (Changes the VM group)
423
    onevm chgrp <vm_id> <group_id>
424

  
419 425
* list (Shows VMs in the pool)
420 426
    onevm list <filter_flag>
421 427

  
......
770 776
        end
771 777
    end
772 778

  
779
when "chown"
780
    check_parameters("chown", 2)
781

  
782
    obj_id  = get_vm_id(ARGV[0])
783
    new_uid = ARGV[1].to_i
784
    new_gid = ( ARGV.length > 2 ) ? ARGV[2].to_i : -1
785

  
786
    obj = OpenNebula::VirtualMachine.new_with_id(obj_id, get_one_client)
787

  
788
    result = obj.chown( new_uid, new_gid )
789
    if is_successful?(result)
790
        puts "VM user/group changed" if ops[:verbose]
791
    end
792

  
793
when "chgrp"
794
    check_parameters("chgrp", 2)
795

  
796
    obj_id = get_vm_id(ARGV[0])
797
    new_uid  = -1
798
    new_gid  = ARGV[1].to_i
799

  
800
    obj = OpenNebula::VirtualMachine.new_with_id(obj_id, get_one_client)
801

  
802
    result = obj.chown( new_uid, new_gid )
803
    if is_successful?(result)
804
        puts "VM group changed" if ops[:verbose]
805
    end
806

  
773 807
when "list"
774 808
    ops.merge!(get_user_flags)
775 809
    if !ops[:xml]
src/cli/onevnet
186 186
* rmleases (Removes a lease fom the virtual network)
187 187
    onevnet rmleases <network_id> <IP>
188 188

  
189
* chown (Changes the virtual network owner and group)
190
    onevnet chown <network_id> <owner_id> [<group_id>]
191

  
192
* chgrp (Changes the virtual network group)
193
    onevnet chgrp <network_id> <group_id>
194

  
189 195
* list (Lists virtual networks in the pool)
190 196
    onevnet list <filter_flag>
191 197

  
......
342 348
        puts "Leases removed" if ops[:verbose]
343 349
    end
344 350

  
351
when "chown"
352
    check_parameters("chown", 2)
353

  
354
    obj_id  = get_vn_id(ARGV[0])
355
    new_uid = ARGV[1].to_i
356
    new_gid = ( ARGV.length > 2 ) ? ARGV[2].to_i : -1
357

  
358
    obj = OpenNebula::VirtualNetwork.new_with_id(obj_id, get_one_client)
359

  
360
    result = obj.chown( new_uid, new_gid )
361
    if is_successful?(result)
362
        puts "Virtual Network user/group changed" if ops[:verbose]
363
    end
364

  
365
when "chgrp"
366
    check_parameters("chgrp", 2)
367

  
368
    obj_id   = get_vn_id(ARGV[0])
369
    new_uid  = -1
370
    new_gid  = ARGV[1].to_i
371

  
372
    obj = OpenNebula::VirtualNetwork.new_with_id(obj_id, get_one_client)
373

  
374
    result = obj.chown( new_uid, new_gid )
375
    if is_successful?(result)
376
        puts "Virtual Network group changed" if ops[:verbose]
377
    end
378

  
345 379
when "list"
346 380
    if ARGV[0]
347 381
        case ARGV[0]
src/oca/ruby/OpenNebula/Image.rb
30 30
            :enable      => "image.enable",
31 31
            :publish     => "image.publish",
32 32
            :persistent  => "image.persistent",
33
            :delete      => "image.delete"
33
            :delete      => "image.delete",
34
            :chown       => "image.chown"
34 35
        }
35 36

  
36 37
        IMAGE_STATES=%w{INIT READY USED DISABLED LOCKED ERROR}
......
142 143
        def delete()
143 144
            super(IMAGE_METHODS[:delete])
144 145
        end
145
    
146

  
147
        # Changes the owner/group
148
        # uid:: _Integer_ the new owner id. Set to -1 to leave the current one
149
        # gid:: _Integer_ the new group id. Set to -1 to leave the current one
150
        # [return] nil in case of success or an Error object
151
        def chown(uid, gid)
152
            super(IMAGE_METHODS[:chown], uid, gid)
153
        end
146 154

  
147 155
        #######################################################################
148 156
        # Helpers to get Image information
src/oca/ruby/OpenNebula/Pool.rb
173 173
            return rc
174 174
        end
175 175

  
176
        # Calls to the corresponding chown method to modify
177
        # the object's owner and group
178
        # xml_method:: _String_ the name of the XML-RPC method
179
        # uid:: _Integer_ the new owner id. Set to -1 to leave the current one
180
        # gid:: _Integer_ the new group id. Set to -1 to leave the current one
181
        # [return] nil in case of success or an Error object
182
        def chown(xml_method, uid, gid)
183
            return Error.new('ID not defined') if !@pe_id
184

  
185
            rc = @client.call(xml_method,@pe_id, uid, gid)
186
            rc = nil if !OpenNebula.is_error?(rc)
187

  
188
            return rc
189
        end
190

  
176 191
    public
177 192

  
178 193
        # Creates new element specifying its id
src/oca/ruby/OpenNebula/Template.rb
27 27
            :update      => "template.update",
28 28
            :rmattr      => "template.rmattr",
29 29
            :publish     => "template.publish",
30
            :delete      => "template.delete"
30
            :delete      => "template.delete",
31
            :chown       => "template.chown"
31 32
        }
32 33

  
33 34
        # Creates a Template description with just its identifier
......
103 104
            set_publish(false)
104 105
        end
105 106

  
107
        # Changes the owner/group
108
        # uid:: _Integer_ the new owner id. Set to -1 to leave the current one
109
        # gid:: _Integer_ the new group id. Set to -1 to leave the current one
110
        # [return] nil in case of success or an Error object
111
        def chown(uid, gid)
112
            super(TEMPLATE_METHODS[:chown], uid, gid)
113
        end
114

  
106 115
        # ---------------------------------------------------------------------
107 116
        # Helpers to get Template information
108 117
        # ---------------------------------------------------------------------
src/oca/ruby/OpenNebula/User.rb
25 25
            :info     => "user.info",
26 26
            :allocate => "user.allocate",
27 27
            :delete   => "user.delete",
28
            :passwd   => "user.passwd"
28
            :passwd   => "user.passwd",
29
            :chown    => "user.chown"
29 30
        }
30 31

  
31 32
        # Creates a User description with just its identifier
......
89 90
            return rc
90 91
        end
91 92

  
93
        # Changes the owner/group
94
        # gid:: _Integer_ the new group id. Set to -1 to leave the current one
95
        # [return] nil in case of success or an Error object
96
        def chgrp(gid)
97
            chown(USER_METHODS[:chown], -1, gid)
98
        end
99

  
92 100
        # ---------------------------------------------------------------------
93 101
        # Helpers to get User information
94 102
        # ---------------------------------------------------------------------
src/oca/ruby/OpenNebula/VirtualMachine.rb
27 27
            :action   => "vm.action",
28 28
            :migrate  => "vm.migrate",
29 29
            :deploy   => "vm.deploy",
30
            :savedisk => "vm.savedisk"
30
            :savedisk => "vm.savedisk",
31
            :chown    => "vm.chown"
31 32
        }
32 33

  
33 34
        VM_STATE=%w{INIT PENDING HOLD ACTIVE STOPPED SUSPENDED DONE FAILED}
......
224 225
            return rc
225 226
        end
226 227

  
228
        # Changes the owner/group
229
        # uid:: _Integer_ the new owner id. Set to -1 to leave the current one
230
        # gid:: _Integer_ the new group id. Set to -1 to leave the current one
231
        # [return] nil in case of success or an Error object
232
        def chown(uid, gid)
233
            super(VM_METHODS[:chown], uid, gid)
234
        end
235

  
227 236
        #######################################################################
228 237
        # Helpers to get VirtualMachine information
229 238
        #######################################################################
src/oca/ruby/OpenNebula/VirtualNetwork.rb
27 27
            :publish    => "vn.publish",
28 28
            :delete     => "vn.delete",
29 29
            :addleases  => "vn.addleases",
30
            :rmleases   => "vn.rmleases"
30
            :rmleases   => "vn.rmleases",
31
            :chown      => "vn.chown"
31 32
        }
32 33

  
33 34
        # Creates a VirtualNetwork description with just its identifier
......
111 112
            return rc
112 113
        end
113 114

  
115
        # Changes the owner/group
116
        # uid:: _Integer_ the new owner id. Set to -1 to leave the current one
117
        # gid:: _Integer_ the new group id. Set to -1 to leave the current one
118
        # [return] nil in case of success or an Error object
119
        def chown(uid, gid)
120
            super(VN_METHODS[:chown], uid, gid)
121
        end
122

  
114 123
        # ---------------------------------------------------------------------
115 124
        # Helpers to get VirtualNetwork information
116 125
        # ---------------------------------------------------------------------
src/rm/RequestManager.cc
231 231
    xmlrpc_c::methodPtr vm_info(new 
232 232
        RequestManager::VirtualMachineInfo(vmpool,upool));
233 233

  
234
    xmlrpc_c::methodPtr vm_chown(new
235
        RequestManager::GenericChown(this,VM));
236

  
234 237
    xmlrpc_c::methodPtr vm_pool_info(new
235 238
        RequestManager::VirtualMachinePoolInfo(vmpool,upool));
236 239

  
......
252 255
    xmlrpc_c::methodPtr template_publish(new
253 256
        RequestManager::TemplatePublish(tpool, upool));
254 257

  
258
    xmlrpc_c::methodPtr template_chown(new
259
        RequestManager::GenericChown(this,TEMPLATE));
260

  
255 261
    xmlrpc_c::methodPtr template_pool_info(new
256 262
        RequestManager::TemplatePoolInfo(tpool,upool));
257 263

  
......
321 327
    xmlrpc_c::methodPtr vn_rmleases(new
322 328
        RequestManager::VirtualNetworkRemoveLeases(vnpool, upool));
323 329

  
330
    xmlrpc_c::methodPtr vn_chown(new
331
        RequestManager::GenericChown(this,NET));
332

  
324 333
    xmlrpc_c::methodPtr user_allocate(new    
325 334
        RequestManager::UserAllocate(upool));
326 335

  
......
333 342
    xmlrpc_c::methodPtr user_change_password(new
334 343
        RequestManager::UserChangePassword(upool));
335 344

  
345
    xmlrpc_c::methodPtr user_chown(new
346
        RequestManager::GenericChown(this,USER));
347

  
336 348
    xmlrpc_c::methodPtr userpool_info(new    
337 349
        RequestManager::UserPoolInfo(upool));
338 350
        
......
359 371
        
360 372
    xmlrpc_c::methodPtr image_enable(new    
361 373
        RequestManager::ImageEnable(ipool, upool));
362
        
374

  
375
    xmlrpc_c::methodPtr image_chown(new
376
        RequestManager::GenericChown(this,IMAGE));
377

  
363 378
    xmlrpc_c::methodPtr imagepool_info(new    
364 379
        RequestManager::ImagePoolInfo(ipool, upool));
365 380

  
......
371 386
    RequestManagerRegistry.addMethod("one.vm.migrate", vm_migrate);
372 387
    RequestManagerRegistry.addMethod("one.vm.info", vm_info);
373 388
    RequestManagerRegistry.addMethod("one.vm.savedisk", vm_savedisk);
389
    RequestManagerRegistry.addMethod("one.vm.chown", vm_chown);
374 390

  
375 391
    RequestManagerRegistry.addMethod("one.vmpool.info", vm_pool_info);
376 392

  
......
382 398
    RequestManagerRegistry.addMethod("one.template.update", template_update);
383 399
    RequestManagerRegistry.addMethod("one.template.rmattr", template_rm_attribute);
384 400
    RequestManagerRegistry.addMethod("one.template.publish", template_publish);
401
    RequestManagerRegistry.addMethod("one.template.chown", template_chown);
385 402

  
386 403
    RequestManagerRegistry.addMethod("one.templatepool.info",template_pool_info);
387 404

  
......
420 437
    RequestManagerRegistry.addMethod("one.vn.delete", vn_delete);
421 438
    RequestManagerRegistry.addMethod("one.vn.addleases", vn_addleases);
422 439
    RequestManagerRegistry.addMethod("one.vn.rmleases", vn_rmleases);
440
    RequestManagerRegistry.addMethod("one.vn.chown", vn_chown);
423 441

  
424 442
    RequestManagerRegistry.addMethod("one.vnpool.info", vnpool_info); 
425 443
    
......
430 448
    RequestManagerRegistry.addMethod("one.user.delete", user_delete);
431 449
    RequestManagerRegistry.addMethod("one.user.info", user_info);
432 450
    RequestManagerRegistry.addMethod("one.user.passwd", user_change_password);
451
    RequestManagerRegistry.addMethod("one.user.chown", user_chown);
433 452

  
434 453
    RequestManagerRegistry.addMethod("one.userpool.info", userpool_info);
435 454
    
......
443 462
    RequestManagerRegistry.addMethod("one.image.publish", image_publish);
444 463
    RequestManagerRegistry.addMethod("one.image.persistent", image_persistent);
445 464
    RequestManagerRegistry.addMethod("one.image.enable", image_enable);    
465
    RequestManagerRegistry.addMethod("one.image.chown", image_chown);
446 466

  
447 467
    RequestManagerRegistry.addMethod("one.imagepool.info", imagepool_info);
448 468
    
src/rm/RequestManagerChown.cc
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 "RequestManager.h"
18

  
19
#include "NebulaLog.h"
20
#include "Nebula.h"
21

  
22
#include "AuthManager.h"
23

  
24
/* -------------------------------------------------------------------------- */
25
/* -------------------------------------------------------------------------- */
26

  
27
void RequestManager::GenericChown::execute(
28
    xmlrpc_c::paramList const& paramList,
29
    xmlrpc_c::value *   const  retval)
30
{
31
    string              session;
32

  
33
    int                 uid, obj_owner;
34
    int                 oid, ownid, gid;
35
    int                 rc;
36

  
37
    PoolObjectSQL *     obj;
38

  
39
    vector<xmlrpc_c::value> arrayData;
40
    xmlrpc_c::value_array * arrayresult;
41

  
42
    ostringstream       oss;
43

  
44
    PoolSQL *   pool = rm->get_pool(ob);
45
    string      method_name = rm->get_method_prefix(ob) + "Chown";
46
    string      obj_name = rm->get_object_name(ob);
47

  
48

  
49
    oss << method_name << " invoked";
50

  
51
    NebulaLog::log("ReM",Log::DEBUG,oss);
52
    oss.str("");
53

  
54
    session      = xmlrpc_c::value_string (paramList.getString(0));
55
    oid          = xmlrpc_c::value_int    (paramList.getInt(1));
56
    ownid        = xmlrpc_c::value_int    (paramList.getInt(2));
57
    gid          = xmlrpc_c::value_int    (paramList.getInt(3));
58

  
59
    // TODO: check destination owner and/or group exist
60

  
61
    // First, we need to authenticate the user
62
    uid = rm->upool->authenticate(session);
63

  
64
    if ( uid == -1 )
65
    {
66
        goto error_authenticate;
67
    }
68

  
69
    // Get object from the pool
70
    obj = pool->get(oid,true);
71

  
72
    if ( obj == 0 )
73
    {
74
        goto error_get;
75
    }
76

  
77
    obj_owner = obj->get_uid();
78

  
79
    obj->unlock();
80

  
81
    //Authorize the operation
82
    if ( uid != 0 ) // uid == 0 means oneadmin
83
    {
84
        goto error_authorize;
85
    }
86

  
87
    // TODO use auth manager
88
/*
89
    if ( uid != 0 ) // uid == 0 means oneadmin
90
    {
91
        AuthRequest ar(uid);
92

  
93
//      ar.add_auth(..);
94

  
95
        if (UserPool::authorize(ar) == -1)
96
        {
97
            goto error_authorize;
98
        }
99
    }
100
*/
101

  
102
    // Get the object locked again
103
    obj = pool->get(oid,true);
104

  
105
    if ( obj == 0 )
106
    {
107
        goto error_get;
108
    }
109

  
110
    if( ownid > -1 )
111
    {
112
        rc = obj->set_uid(ownid);
113

  
114
        if( rc != 0 )
115
        {
116
            goto error_set_uid;
117
        }
118
    }
119
    if( gid > -1 )
120
    {
121
        rc = obj->set_gid(gid);
122

  
123
        if( rc != 0 )
124
        {
125
            goto error_set_gid;
126
        }
127
    }
128

  
129
    pool->update(obj);
130

  
131
    obj->unlock();
132

  
133
    arrayData.push_back(xmlrpc_c::value_boolean(true));
134

  
135
    // Copy arrayresult into retval mem space
136
    arrayresult = new xmlrpc_c::value_array(arrayData);
137
    *retval = *arrayresult;
138

  
139
    delete arrayresult; // and get rid of the original
140

  
141
    return;
142

  
143
error_authenticate:
144
    oss.str(authenticate_error(method_name));
145
    goto error_common;
146

  
147
error_get:
148
    oss.str(get_error(method_name, obj_name, oid));
149
    goto error_common;
150

  
151
error_authorize:
152
    // TODO: delete development comment
153
    oss << authorization_error(method_name, "MANAGE", obj_name, uid, oid) <<
154
    " Development functionality, only oneamdin can perform chown.";
155
    goto error_common;
156

  
157
error_set_uid:
158
    oss.str(action_error(method_name, "SET_UID", obj_name, oid, rc));
159

  
160
    obj->unlock();
161
    goto error_common;
162

  
163
error_set_gid:
164
    oss.str(action_error(method_name, "SET_GID", obj_name, oid, rc));
165

  
166
    if( ownid > -1 )   // restore owner user
167
    {
168
        obj->set_uid(obj_owner);
169
    }
170

  
171
    obj->unlock();
172
    goto error_common;
173

  
174
error_common:
175
    arrayData.push_back(xmlrpc_c::value_boolean(false));  // FAILURE
176
    arrayData.push_back(xmlrpc_c::value_string(oss.str()));
177

  
178
    NebulaLog::log("ReM",Log::ERROR,oss);
179

  
180
    xmlrpc_c::value_array arrayresult_error(arrayData);
181

  
182
    *retval = arrayresult_error;
183

  
184
    return;
185
}
186

  
187
/* -------------------------------------------------------------------------- */
188
/* -------------------------------------------------------------------------- */
src/rm/SConstruct
73 73
    'RequestManagerTemplateRemoveAttribute.cc',
74 74
    'RequestManagerTemplatePublish.cc',
75 75
    'RequestManagerTemplatePoolInfo.cc',
76
    'RequestManagerChown.cc',
76 77
]
77 78

  
78 79
# Build library

Also available in: Unified diff