summaryrefslogtreecommitdiffstats
path: root/ipa-python/rpcclient.py
blob: 32249fd3cc9e37937f7b810214c204f716eb7497 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
# Authors: Rob Crittenden <rcritten@redhat.com>
#
# Copyright (C) 2007  Red Hat
# see file 'COPYING' for use and warranty information
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License as
# published by the Free Software Foundation; version 2 or later
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#

#!/usr/bin/python

import xmlrpclib
import socket
import config
from krbtransport import KerbTransport
from kerberos import GSSError
from ipa import ipaerror, ipautil
from ipa import config

# Some errors to catch
# http://cvs.fedora.redhat.com/viewcvs/ldapserver/ldap/servers/plugins/pam_passthru/README?root=dirsec&rev=1.6&view=auto

class RPCClient:

    def __init__(self):
        config.init_config()
    
    def server_url(self):
        """Build the XML-RPC server URL from our configuration"""
        return "https://" + config.config.get_server() + "/ipa"
    
    def setup_server(self):
        """Create our XML-RPC server connection using kerberos
           authentication"""
        return xmlrpclib.ServerProxy(self.server_url(), KerbTransport())
    
# Higher-level API

    def get_aci_entry(self, sattrs=None):
        """Returns the entry containing access control ACIs."""
        server = self.setup_server()
        if sattrs is None:
            sattrs = "__NONE__"
        try:
            result = server.get_aci_entry(sattrs)
        except xmlrpclib.Fault, fault:
            raise ipaerror.gen_exception(fault.faultCode, fault.faultString)
        except socket.error, (value, msg):
            raise xmlrpclib.Fault(value, msg)

        return ipautil.unwrap_binary_data(result)


# General searches

    def get_entry_by_dn(self,dn,sattrs=None):
        """Get a specific entry. If sattrs is not None then only those
           attributes will be returned, otherwise all available
           attributes are returned. The result is a dict."""
        server = self.setup_server()
        if sattrs is None:
            sattrs = "__NONE__"
        try:
            result = server.get_entry_by_dn(dn, sattrs)
        except xmlrpclib.Fault, fault:
            raise ipaerror.gen_exception(fault.faultCode, fault.faultString)
        except socket.error, (value, msg):
            raise xmlrpclib.Fault(value, msg)

        return ipautil.unwrap_binary_data(result)

    def get_entry_by_cn(self,cn,sattrs=None):
        """Get a specific entry by cn. If sattrs is not None then only those
           attributes will be returned, otherwise all available
           attributes are returned. The result is a dict."""
        server = self.setup_server()
        if sattrs is None:
            sattrs = "__NONE__"
        try:
            result = server.get_entry_by_cn(cn, sattrs)
        except xmlrpclib.Fault, fault:
            raise ipaerror.gen_exception(fault.faultCode, fault.faultString)
        except socket.error, (value, msg):
            raise xmlrpclib.Fault(value, msg)

        return ipautil.unwrap_binary_data(result)

    def update_entry(self,oldentry,newentry):
        """Update an existing entry. oldentry and newentry are dicts of attributes"""
        server = self.setup_server()

        try:
            result = server.update_entry(ipautil.wrap_binary_data(oldentry),
                    ipautil.wrap_binary_data(newentry))
        except xmlrpclib.Fault, fault:
            raise ipaerror.gen_exception(fault.faultCode, fault.faultString)
        except socket.error, (value, msg):
            raise xmlrpclib.Fault(value, msg)

        return ipautil.unwrap_binary_data(result)


# User support

    def get_user_by_uid(self,uid,sattrs=None):
        """Get a specific user. If sattrs is not None then only those
           attributes will be returned, otherwise all available
           attributes are returned. The result is a dict."""
        server = self.setup_server()
        if sattrs is None:
            sattrs = "__NONE__"
        try:
            result = server.get_user_by_uid(uid, sattrs)
        except xmlrpclib.Fault, fault:
            raise ipaerror.gen_exception(fault.faultCode, fault.faultString)
        except socket.error, (value, msg):
            raise xmlrpclib.Fault(value, msg)

        return ipautil.unwrap_binary_data(result)

    def get_user_by_principal(self,principal,sattrs=None):
        """Get a specific user. If sattrs is not None then only those
           attributes will be returned, otherwise all available
           attributes are returned. The result is a dict."""
        server = self.setup_server()
        if sattrs is None:
            sattrs = "__NONE__"
        try:
            result = server.get_user_by_principal(principal, sattrs)
        except xmlrpclib.Fault, fault:
            raise ipaerror.gen_exception(fault.faultCode, fault.faultString)
        except socket.error, (value, msg):
            raise xmlrpclib.Fault(value, msg)

        return ipautil.unwrap_binary_data(result)

    def get_user_by_email(self,email,sattrs=None):
        """Get a specific user's entry. Return as a dict of values.
           Multi-valued fields are represented as lists. The result is a
           dict.
        """
        server = self.setup_server()
        if sattrs is None:
            sattrs = "__NONE__"
        try:
            result = server.get_user_by_email(email, sattrs)
        except xmlrpclib.Fault, fault:
            raise ipaerror.gen_exception(fault.faultCode, fault.faultString)
        except socket.error, (value, msg):
            raise xmlrpclib.Fault(value, msg)

        return ipautil.unwrap_binary_data(result)

    def get_users_by_manager(self,manager_dn,sattrs=None):
        """Gets the users that report to a manager.
           If sattrs is not None then only those
           attributes will be returned, otherwise all available
           attributes are returned. The result is a list of dicts."""
        server = self.setup_server()
        if sattrs is None:
            sattrs = "__NONE__"
        try:
            result = server.get_users_by_manager(manager_dn, sattrs)
        except xmlrpclib.Fault, fault:
            raise ipaerror.gen_exception(fault.faultCode, fault.faultString)
        except socket.error, (value, msg):
            raise xmlrpclib.Fault(value, msg)

        return ipautil.unwrap_binary_data(result)

    def add_user(self,user,user_container=None):
        """Add a new user. Takes as input a dict where the key is the
           attribute name and the value is either a string or in the case
           of a multi-valued field a list of values"""
        server = self.setup_server()

        if user_container is None:
            user_container = "__NONE__"
    
        try:
            result = server.add_user(ipautil.wrap_binary_data(user),
                    user_container)
        except xmlrpclib.Fault, fault:
            raise ipaerror.gen_exception(fault.faultCode, fault.faultString)
        except socket.error, (value, msg):
            raise xmlrpclib.Fault(value, msg)

        return ipautil.unwrap_binary_data(result)
        
    def get_custom_fields(self):
        """Get custom user fields."""
        server = self.setup_server()
        
        try:
            result = server.get_custom_fields()
        except xmlrpclib.Fault, fault:
            raise ipaerror.gen_exception(fault.faultCode, fault.faultString)
        except socket.error, (value, msg):
            raise xmlrpclib.Fault(value, msg)
      
        return ipautil.unwrap_binary_data(result)

    def set_custom_fields(self, schema):
        """Set custom user fields."""
        server = self.setup_server()
        
        try:
            result = server.set_custom_fields(schema)
        except xmlrpclib.Fault, fault:
            raise ipaerror.gen_exception(fault.faultCode, fault.faultString)
        except socket.error, (value, msg):
            raise xmlrpclib.Fault(value, msg)

        return ipautil.unwrap_binary_data(result)
      
    def get_all_users (self):
        """Return a list containing a dict for each existing user."""
    
        server = self.setup_server()
        try:
            result = server.get_all_users()
        except xmlrpclib.Fault, fault:
            raise ipaerror.gen_exception(fault.faultCode, fault.faultString)
        except socket.error, (value, msg):
            raise xmlrpclib.Fault(value, msg)
    
        return ipautil.unwrap_binary_data(result)

    def find_users (self, criteria, sattrs=None, searchlimit=0, timelimit=-1):
        """Return a list: counter followed by a dict for each user that
           matches the criteria. If the results are truncated, counter will
           be set to -1"""
    
        server = self.setup_server()
        try:
            # None values are not allowed in XML-RPC
            if sattrs is None:
                sattrs = "__NONE__"
            result = server.find_users(criteria, sattrs, searchlimit, timelimit)
        except xmlrpclib.Fault, fault:
            raise ipaerror.gen_exception(fault.faultCode, fault.faultString)
        except socket.error, (value, msg):
            raise xmlrpclib.Fault(value, msg)
    
        return ipautil.unwrap_binary_data(result)

    def update_user(self,olduser,newuser):
        """Update an existing user. olduser and newuser are dicts of attributes"""
        server = self.setup_server()
    
        try:
            result = server.update_user(ipautil.wrap_binary_data(olduser),
                    ipautil.wrap_binary_data(newuser))
        except xmlrpclib.Fault, fault:
            raise ipaerror.gen_exception(fault.faultCode, fault.faultString)
        except socket.error, (value, msg):
            raise xmlrpclib.Fault(value, msg)

        return ipautil.unwrap_binary_data(result)

    def delete_user(self,uid):
        """Delete a user. uid is the uid of the user to delete."""
        server = self.setup_server()
    
        try:
            result = server.delete_user(uid)
        except xmlrpclib.Fault, fault:
            raise ipaerror.gen_exception(fault.faultCode, fault.faultString)
        except socket.error, (value, msg):
            raise xmlrpclib.Fault(value, msg)

        return result

    def modifyPassword(self,principal,oldpass,newpass):
        """Modify a user's password"""
        server = self.setup_server()

        if oldpass is None:
            oldpass = "__NONE__"
    
        try:
            result = server.modifyPassword(principal,oldpass,newpass)
        except xmlrpclib.Fault, fault:
            raise ipaerror.gen_exception(fault.faultCode, fault.faultString)
        except socket.error, (value, msg):
            raise xmlrpclib.Fault(value, msg)

        return result

    def mark_user_active(self,uid):
        """Mark a user as active"""
        server = self.setup_server()
    
        try:
            result = server.mark_user_active(uid)
        except xmlrpclib.Fault, fault:
            raise ipaerror.gen_exception(fault.faultCode, fault.faultString)
        except socket.error, (value, msg):
            raise xmlrpclib.Fault(value, msg)

        return ipautil.unwrap_binary_data(result)

    def mark_user_inactive(self,uid):
        """Mark a user as inactive"""
        server = self.setup_server()
    
        try:
            result = server.mark_user_inactive(uid)
        except xmlrpclib.Fault, fault:
            raise ipaerror.gen_exception(fault.faultCode, fault.faultString)
        except socket.error, (value, msg):
            raise xmlrpclib.Fault(value, msg)

        return ipautil.unwrap_binary_data(result)


# Group support

    def get_groups_by_member(self,member_dn,sattrs=None):
        """Gets the groups that member_dn belongs to.
           If sattrs is not None then only those
           attributes will be returned, otherwise all available
           attributes are returned. The result is a list of dicts."""
        server = self.setup_server()
        if sattrs is None:
            sattrs = "__NONE__"
        try:
            result = server.get_groups_by_member(member_dn, sattrs)
        except xmlrpclib.Fault, fault:
            raise ipaerror.gen_exception(fault.faultCode, fault.faultString)
        except socket.error, (value, msg):
            raise xmlrpclib.Fault(value, msg)

        return ipautil.unwrap_binary_data(result)

    def add_group(self,group,group_container=None):
        """Add a new group. Takes as input a dict where the key is the
           attribute name and the value is either a string or in the case
           of a multi-valued field a list of values"""
        server = self.setup_server()

        if group_container is None:
            group_container = "__NONE__"
    
        try:
            result = server.add_group(ipautil.wrap_binary_data(group),
                    group_container)
        except xmlrpclib.Fault, fault:
            raise ipaerror.gen_exception(fault.faultCode, fault.faultString)
        except socket.error, (value, msg):
            raise xmlrpclib.Fault(value, msg)

        return ipautil.unwrap_binary_data(result)

    def find_groups (self, criteria, sattrs=None, searchlimit=0, timelimit=-1):
        """Return a list containing a Group object for each group that matches
           the criteria."""
    
        server = self.setup_server()
        try:
            # None values are not allowed in XML-RPC
            if sattrs is None:
                sattrs = "__NONE__"
            result = server.find_groups(criteria, sattrs, searchlimit, timelimit)
        except xmlrpclib.Fault, fault:
            raise ipaerror.gen_exception(fault.faultCode, fault.faultString)
        except socket.error, (value, msg):
            raise xmlrpclib.Fault(value, msg)
    
        return ipautil.unwrap_binary_data(result)

    def add_member_to_group(self, member_dn, group_dn):
        """Add a new member to an existing group.
        """
        server = self.setup_server()
        try:
            result = server.add_member_to_group(member_dn, group_dn)
        except xmlrpclib.Fault, fault:
            raise ipaerror.gen_exception(fault.faultCode, fault.faultString)
        except socket.error, (value, msg):
            raise xmlrpclib.Fault(value, msg)

        return ipautil.unwrap_binary_data(result)

    def add_members_to_group(self, member_dns, group_dn):
        """Add several members to an existing group.
           member_dns is a list of the dns to add

           Returns a list of the dns that were not added.
        """
        server = self.setup_server()
        try:
            result = server.add_members_to_group(member_dns, group_dn)
        except xmlrpclib.Fault, fault:
            raise ipaerror.gen_exception(fault.faultCode, fault.faultString)
        except socket.error, (value, msg):
            raise xmlrpclib.Fault(value, msg)

        return ipautil.unwrap_binary_data(result)

    def remove_member_from_group(self, member_dn, group_dn):
        """Remove a member from an existing group.
        """
        server = self.setup_server()
        try:
            result = server.remove_member_from_group(member_dn, group_dn)
        except xmlrpclib.Fault, fault:
            raise ipaerror.gen_exception(fault.faultCode, fault.faultString)
        except socket.error, (value, msg):
            raise xmlrpclib.Fault(value, msg)

        return ipautil.unwrap_binary_data(result)

    def remove_members_from_group(self, member_dns, group_dn):
        """Remove several members from an existing group.

           Returns a list of the dns that were not removed.
        """
        server = self.setup_server()
        try:
            result = server.remove_members_from_group(member_dns, group_dn)
        except xmlrpclib.Fault, fault:
            raise ipaerror.gen_exception(fault.faultCode, fault.faultString)
        except socket.error, (value, msg):
            raise xmlrpclib.Fault(value, msg)

        return ipautil.unwrap_binary_data(result)

    def add_user_to_group(self, user_uid, group_dn):
        """Add a user to an existing group.
        """
        server = self.setup_server()
        try:
            result = server.add_user_to_group(user_uid, group_dn)
        except xmlrpclib.Fault, fault:
            raise ipaerror.gen_exception(fault.faultCode, fault.faultString)
        except socket.error, (value, msg):
            raise xmlrpclib.Fault(value, msg)

        return ipautil.unwrap_binary_data(result)

    def add_users_to_group(self, user_uids, group_dn):
        """Add several users to an existing group.
           user_uids is a list of the uids of the users to add

           Returns a list of the user uids that were not added.
        """
        server = self.setup_server()
        try:
            result = server.add_users_to_group(user_uids, group_dn)
        except xmlrpclib.Fault, fault:
            raise ipaerror.gen_exception(fault.faultCode, fault.faultString)
        except socket.error, (value, msg):
            raise xmlrpclib.Fault(value, msg)

        return ipautil.unwrap_binary_data(result)

    def remove_user_from_group(self, user_uid, group_dn):
        """Remove a user from an existing group.
        """
        server = self.setup_server()
        try:
            result = server.remove_user_from_group(user_uid, group_dn)
        except xmlrpclib.Fault, fault:
            raise ipaerror.gen_exception(fault.faultCode, fault.faultString)
        except socket.error, (value, msg):
            raise xmlrpclib.Fault(value, msg)
    
        return ipautil.unwrap_binary_data(result)

    def remove_users_from_group(self, user_uids, group_dn):
        """Remove several users from an existing group.
           user_uids is a list of the uids of the users to remove

           Returns a list of the user uids that were not removed.
        """
        server = self.setup_server()
        try:
            result = server.remove_users_from_group(user_uids, group_dn)
        except xmlrpclib.Fault, fault:
            raise ipaerror.gen_exception(fault.faultCode, fault.faultString)
        except socket.error, (value, msg):
            raise xmlrpclib.Fault(value, msg)
    
        return ipautil.unwrap_binary_data(result)

    def add_groups_to_user(self, group_dns, user_dn):
        """Given a list of group dn's add them to the user.

           Returns a list of the group dns that were not added.
        """
        server = self.setup_server()
        try:
            result = server.add_groups_to_user(group_dns, user_dn)
        except xmlrpclib.Fault, fault:
            raise ipaerror.gen_exception(fault.faultCode, fault.faultString)
        except socket.error, (value, msg):
            raise xmlrpclib.Fault(value, msg)

        return ipautil.unwrap_binary_data(result)

    def remove_groups_from_user(self, group_dns, user_dn):
        """Given a list of group dn's remove them from the user.

           Returns a list of the group dns that were not removed.
        """
        server = self.setup_server()
        try:
            result = server.remove_groups_from_user(group_dns, user_dn)
        except xmlrpclib.Fault, fault:
            raise ipaerror.gen_exception(fault.faultCode, fault.faultString)
        except socket.error, (value, msg):
            raise xmlrpclib.Fault(value, msg)

        return ipautil.unwrap_binary_data(result)

    def update_group(self,oldgroup,newgroup):
        """Update an existing group. oldgroup and newgroup are dicts of attributes"""
        server = self.setup_server()
    
        try:
            result = server.update_group(ipautil.wrap_binary_data(oldgroup),
                    ipautil.wrap_binary_data(newgroup))
        except xmlrpclib.Fault, fault:
            raise ipaerror.gen_exception(fault.faultCode, fault.faultString)
        except socket.error, (value, msg):
            raise xmlrpclib.Fault(value, msg)

        return ipautil.unwrap_binary_data(result)

    def delete_group(self,group_dn):
        """Delete a group. group_dn is the dn of the group to be deleted."""
        server = self.setup_server()
    
        try:
            result = server.delete_group(group_dn)
        except xmlrpclib.Fault, fault:
            raise ipaerror.gen_exception(fault.faultCode, fault.faultString)
        except socket.error, (value, msg):
            raise xmlrpclib.Fault(value, msg)

        return ipautil.unwrap_binary_data(result)

    def add_group_to_group(self, group_cn, tgroup_cn):
        """Add a group to an existing group.
           group_cn is a cn of the group to add
           tgroup_cn is the cn of the group to be added to
        """
        server = self.setup_server()
        try:
            result = server.add_group_to_group(group_cn, tgroup_cn)
        except xmlrpclib.Fault, fault:
            raise ipaerror.gen_exception(fault.faultCode, fault.faultString)
        except socket.error, (value, msg):
            raise xmlrpclib.Fault(value, msg)
    
        return ipautil.unwrap_binary_data(result)

    def attrs_to_labels(self,attrs):
        """Convert a list of LDAP attributes into a more readable form."""

        server = self.setup_server()
        try:
            result = server.attrs_to_labels(attrs)
        except xmlrpclib.Fault, fault:
            raise ipaerror.gen_exception(fault.faultCode, fault.faultString)
        except socket.error, (value, msg):
            raise xmlrpclib.Fault(value, msg)

        return ipautil.unwrap_binary_data(result)

    def get_all_attrs(self, opts=None):
        """We have a list of hardcoded attributes -> readable labels. Return
           that complete list if someone wants it.
        """

        server = self.setup_server()
        try:
            result = server.get_all_attrs()
        except xmlrpclib.Fault, fault:
            raise ipaerror.gen_exception(fault.faultCode, fault.faultString)
        except socket.error, (value, msg):
            raise xmlrpclib.Fault(value, msg)

        return ipautil.unwrap_binary_data(result)

    def group_members(self, groupdn, attr_list=None):
        """Do a memberOf search of groupdn and return the attributes in
           attr_list (an empty list returns everything)."""

        if attr_list is None:
            attr_list = "__NONE__"

        server = self.setup_server()
        try:
            result = server.group_members(groupdn, attr_list)
        except xmlrpclib.Fault, fault:
            raise ipaerror.gen_exception(fault.faultCode, fault.faultString)
        except socket.error, (value, msg):
            raise xmlrpclib.Fault(value, msg)

        return ipautil.unwrap_binary_data(result)

    def mark_group_active(self,cn):
        """Mark a group as active"""
        server = self.setup_server()
    
        try:
            result = server.mark_group_active(cn)
        except xmlrpclib.Fault, fault:
            raise ipaerror.gen_exception(fault.faultCode, fault.faultString)
        except socket.error, (value, msg):
            raise xmlrpclib.Fault(value, msg)

        return ipautil.unwrap_binary_data(result)

    def mark_group_inactive(self,cn):
        """Mark a group as inactive"""
        server = self.setup_server()
    
        try:
            result = server.mark_group_inactive(cn)
        except xmlrpclib.Fault, fault:
            raise ipaerror.gen_exception(fault.faultCode, fault.faultString)
        except socket.error, (value, msg):
            raise xmlrpclib.Fault(value, msg)

        return ipautil.unwrap_binary_data(result)

# Configuration support

    def get_ipa_config(self):
        """Get the IPA configuration"""
        server = self.setup_server()
        try:
            result = server.get_ipa_config()
        except xmlrpclib.Fault, fault:
            raise ipaerror.gen_exception(fault.faultCode, fault.faultString)
        except socket.error, (value, msg):
            raise xmlrpclib.Fault(value, msg)

        return ipautil.unwrap_binary_data(result)

    def update_ipa_config(self, oldconfig, newconfig):
        """Update the IPA configuration"""
        server = self.setup_server()
        try:
            result = server.update_ipa_config(oldconfig, newconfig)
        except xmlrpclib.Fault, fault:
            raise ipaerror.gen_exception(fault.faultCode, fault.faultString)
        except socket.error, (value, msg):
            raise xmlrpclib.Fault(value, msg)

        return ipautil.unwrap_binary_data(result)

    def get_password_policy(self):
        """Get the IPA password policy"""
        server = self.setup_server()
        try:
            result = server.get_password_policy()
        except xmlrpclib.Fault, fault:
            raise ipaerror.gen_exception(fault.faultCode, fault.faultString)
        except socket.error, (value, msg):
            raise xmlrpclib.Fault(value, msg)

        return ipautil.unwrap_binary_data(result)

    def update_password_policy(self, oldpolicy, newpolicy):
        """Update the IPA password policy"""
        server = self.setup_server()
        try:
            result = server.update_password_policy(oldpolicy, newpolicy)
        except xmlrpclib.Fault, fault:
            raise ipaerror.gen_exception(fault.faultCode, fault.faultString)
        except socket.error, (value, msg):
            raise xmlrpclib.Fault(value, msg)

        return ipautil.unwrap_binary_data(result)

    def add_service_principal(self, princ_name):
        server = self.setup_server()
    
        try:
            result = server.add_service_principal(princ_name)
        except xmlrpclib.Fault, fault:
            raise ipaerror.gen_exception(fault.faultCode, fault.faultString)
        except socket.error, (value, msg):
            raise xmlrpclib.Fault(value, msg)

        return ipautil.unwrap_binary_data(result)

    def find_service_principal (self, criteria, sattrs=None, searchlimit=0, timelimit=-1):
        """Return a list: counter followed by a Entity object for each host that
           matches the criteria. If the results are truncated, counter will
           be set to -1"""
    
        server = self.setup_server()
        try:
            # None values are not allowed in XML-RPC
            if sattrs is None:
                sattrs = "__NONE__"
            result = server.find_service_principal(criteria, sattrs, searchlimit, timelimit)
        except xmlrpclib.Fault, fault:
            raise ipaerror.gen_exception(fault.faultCode, fault.faultString)
        except socket.error, (value, msg):
            raise xmlrpclib.Fault(value, msg)
    
        return ipautil.unwrap_binary_data(result)

    def get_keytab(self, princ_name):
        server = self.setup_server()
    
        try:
            result = server.get_keytab(princ_name)
        except xmlrpclib.Fault, fault:
            raise ipaerror.gen_exception(fault.faultCode, fault.faultString)
        except socket.error, (value, msg):
            raise xmlrpclib.Fault(value, msg)

        return ipautil.unwrap_binary_data(result)

# radius support

    def get_radius_client_by_ip_addr(self, ip_addr, container, sattrs=None):
        server = self.setup_server()
        if container is None: container = "__NONE__"
        if sattrs is None: sattrs = "__NONE__"
        try:
            result = server.get_radius_client_by_ip_addr(ip_addr, container, sattrs)
        except xmlrpclib.Fault, fault:
            raise ipaerror.gen_exception(fault.faultCode, fault.faultString)
        except socket.error, (value, msg):
            raise xmlrpclib.Fault(value, msg)

        return ipautil.unwrap_binary_data(result)

    def add_radius_client(self, client, container=None):
        server = self.setup_server()

        if container is None: container = "__NONE__"

        try:
            result = server.add_radius_client(ipautil.wrap_binary_data(client), container)
        except xmlrpclib.Fault, fault:
            raise ipaerror.gen_exception(fault.faultCode, fault.faultString)
        except socket.error, (value, msg):
            raise xmlrpclib.Fault(value, msg)

        return ipautil.unwrap_binary_data(result)

    def update_radius_client(self, oldclient, newclient):
        server = self.setup_server()
    
        try:
            result = server.update_radius_client(ipautil.wrap_binary_data(oldclient),
                                                 ipautil.wrap_binary_data(newclient))
        except xmlrpclib.Fault, fault:
            raise ipaerror.gen_exception(fault.faultCode, fault.faultString)
        except socket.error, (value, msg):
            raise xmlrpclib.Fault(value, msg)

        return ipautil.unwrap_binary_data(result)

        
    def delete_radius_client(self, ip_addr, container=None):
        server = self.setup_server()
        if container is None: container = "__NONE__"
    
        try:
            result = server.delete_radius_client(ip_addr, container)
        except xmlrpclib.Fault, fault:
            raise ipaerror.gen_exception(fault.faultCode, fault.faultString)
        except socket.error, (value, msg):
            raise xmlrpclib.Fault(value, msg)

        return ipautil.unwrap_binary_data(result)

    def find_radius_clients(self, criteria, container=None, sattrs=None, searchlimit=0, timelimit=-1):
        server = self.setup_server()
        if container is None: container = "__NONE__"
        try:
            # None values are not allowed in XML-RPC
            if sattrs is None:
                sattrs = "__NONE__"
            result = server.find_radius_clients(criteria, container, sattrs, searchlimit, timelimit)
        except xmlrpclib.Fault, fault:
            raise ipaerror.gen_exception(fault.faultCode, fault.faultString)
        except socket.error, (value, msg):
            raise xmlrpclib.Fault(value, msg)
    
        return ipautil.unwrap_binary_data(result)

    def get_radius_profile_by_uid(self, ip_addr, user_profile, sattrs=None):
        server = self.setup_server()
        if user_profile is None: user_profile = "__NONE__"
        if sattrs is None: sattrs = "__NONE__"
        try:
            result = server.get_radius_profile_by_uid(ip_addr, user_profile, sattrs)
        except xmlrpclib.Fault, fault:
            raise ipaerror.gen_exception(fault.faultCode, fault.faultString)
        except socket.error, (value, msg):
            raise xmlrpclib.Fault(value, msg)

        return ipautil.unwrap_binary_data(result)

    def add_radius_profile(self, profile, user_profile=None):
        server = self.setup_server()

        if user_profile is None: user_profile = "__NONE__"

        try:
            result = server.add_radius_profile(ipautil.wrap_binary_data(profile), user_profile)
        except xmlrpclib.Fault, fault:
            raise ipaerror.gen_exception(fault.faultCode, fault.faultString)
        except socket.error, (value, msg):
            raise xmlrpclib.Fault(value, msg)

        return ipautil.unwrap_binary_data(result)

    def update_radius_profile(self, oldprofile, newprofile):
        server = self.setup_server()
    
        try:
            result = server.update_radius_profile(ipautil.wrap_binary_data(oldprofile),
                                                 ipautil.wrap_binary_data(newprofile))
        except xmlrpclib.Fault, fault:
            raise ipaerror.gen_exception(fault.faultCode, fault.faultString)
        except socket.error, (value, msg):
            raise xmlrpclib.Fault(value, msg)

        return ipautil.unwrap_binary_data(result)

        
    def delete_radius_profile(self, ip_addr, user_profile=None):
        server = self.setup_server()
        if user_profile is None: user_profile = "__NONE__"
    
        try:
            result = server.delete_radius_profile(ip_addr, user_profile)
        except xmlrpclib.Fault, fault:
            raise ipaerror.gen_exception(fault.faultCode, fault.faultString)
        except socket.error, (value, msg):
            raise xmlrpclib.Fault(value, msg)

        return ipautil.unwrap_binary_data(result)

    def find_radius_profiles(self, criteria, user_profile=None, sattrs=None, searchlimit=0, timelimit=-1):
        server = self.setup_server()
        if user_profile is None: user_profile = "__NONE__"
        try:
            # None values are not allowed in XML-RPC
            if sattrs is None:
                sattrs = "__NONE__"
            result = server.find_radius_profiles(criteria, user_profile, sattrs, searchlimit, timelimit)
        except xmlrpclib.Fault, fault:
            raise ipaerror.gen_exception(fault.faultCode, fault.faultString)
        except socket.error, (value, msg):
            raise xmlrpclib.Fault(value, msg)
    
        return ipautil.unwrap_binary_data(result)