~willem-impilinux/network-authentication/authtool

« back to all changes in this revision

Viewing changes to auth_methods/ad/ad.py

  • Committer: Andrew Mitchell
  • Date: 2007-04-11 09:55:51 UTC
  • Revision ID: ajmitch@ubuntu.com-20070411095551-nwq19fngufvf039m
More configuration UI for AD method
Handle joining better & testing for joins
Use temporary file for winbind configuration
Inform auth methods of domain changes

Show diffs side-by-side

added added

removed removed

Lines of Context:
54
54
        # setup /etc/nsswitch.conf (libnss_winbind for passwd & group)
55
55
        pass
56
56
 
57
 
    def gtk_config(self, container, domain, params, func_config_changed=None):
 
57
    def gtk_config(self, container, domain_entry, params, func_config_changed=None):
58
58
        """Draw own config UI into the supplied container"""
59
59
        import gtk
60
60
 
63
63
        for widget in kids:
64
64
            container.remove(widget)
65
65
 
66
 
        domain = domain.get_text()
 
66
        self.domain = domain_entry.get_text()
67
67
        # detect if host is already in configured domain
68
 
        if self.check_join_status(domain, params):
 
68
        if (params.has_key('skip_join') and params['skip_join'] == True) and self.check_join_status(params):
69
69
            #
70
 
            pass
71
 
            
 
70
            tb = gtk.Table(rows=4, columns=2)
 
71
            info_hb = gtk.HBox(False, 1)
 
72
            info_img = gtk.Image()
 
73
            info_img.set_from_stock( gtk.STOCK_NETWORK,gtk.ICON_SIZE_DIALOG)
 
74
 
 
75
            info_label = gtk.Label("Enter the settings for your Active Directory configuration")
 
76
            info_label.set_line_wrap(True)
 
77
            info_hb.pack_start(info_img)
 
78
            info_hb.pack_start(info_label)
 
79
 
 
80
 
 
81
            wkgrp_label = gtk.Label("Workgroup")
 
82
            wkgrp_entry = gtk.Entry(60)
 
83
            wkgrp_entry = gtk.Entry(60)
 
84
 
 
85
 
 
86
            tb.attach(info_hb, 0, 2, 0, 1)
 
87
            tb.attach(wkgrp_label, 0, 1, 1, 2)
 
88
            tb.attach(wkgrp_entry, 1, 2, 1, 2)
 
89
            container.pack_start(tb)
 
90
 
 
91
            #Try & use the boring default
 
92
            authtools.IAuthConfig.gtk_config(self, container, domain_entry, params, func_config_changed)
72
93
        else:
73
94
            # show join box
74
95
 
104
125
            join_img.set_from_stock( gtk.STOCK_CONNECT, gtk.ICON_SIZE_BUTTON)
105
126
            join_btn.set_image( join_img )
106
127
 
107
 
            params = {'domain':domain, 'user':admin_entry, 'passwd':passwd_entry}
108
 
            join_btn.connect('clicked', self.gtk_join, params)
 
128
            join_params = {'domain':self.domain, 'user':admin_entry, 'passwd':passwd_entry,'container':container, 'domain_entry':domain_entry,'changed':func_config_changed, 'params': params }
 
129
            join_btn.connect('clicked', self.gtk_join, join_params)
109
130
            join_hb.pack_start(join_btn, expand=False, fill=False, padding=6)
110
131
 
111
 
            container.add(tb)
112
 
            container.add(join_hb)
 
132
            container.pack_start(tb)
 
133
            container.pack_start(join_hb)
113
134
 
114
135
        container.show_all()
115
136
        #print container
116
137
 
117
 
    def check_join_status(self, domain, params):
 
138
    def check_join_status(self, params):
118
139
        """Check with 'net ads' whether the system is joined to the domain
119
140
        already"""
120
 
        return False
 
141
        # bypass this pile for now
 
142
        return True
 
143
        
 
144
        import os, subprocess
 
145
        realm = self.domain.upper()
 
146
        print "Testing join with realm %s" % realm
 
147
        wb = self.at.get_method_obj('Winbind')
 
148
 
 
149
        if params.has_key('user') and params['user'] != '':
 
150
            user = "-U %s%%%s" % (params['user'], params['passwd'])
 
151
        else:
 
152
            user ='-U root%%foo'
 
153
        
 
154
        smb_conf = wb.skeleton_conf( {'global':{'security':'ads','workgroup':self.domain,'realm':realm}})
 
155
 
 
156
        r = os.system("net ads testjoin -s %s %s" % smb_conf.name, user)
 
157
        if r == 0:
 
158
            print "Machine is in domain"
 
159
            return True
 
160
        else:
 
161
            return False
121
162
 
122
163
    def gtk_join(self, widget, params):
123
164
        """Wrapper for the generic join method"""
124
 
        self.join(params['domain'],
 
165
        self.join(self.domain,
125
166
                  {'user':   params['user'].get_text(),
126
167
                   'passwd': params['passwd'].get_text()
127
168
                   })
128
 
        
 
169
 
 
170
        #refresh the window
 
171
        params['params']['skip_join'] = True
 
172
        #print params['domain_entry']
 
173
        self.gtk_config(params['container'], params['domain_entry'], params['params'], params['changed'])
129
174
 
130
175
    def join(self, domain, params):
131
176
        """By request, this needs to handle joining sub-OUs with
138
183
        """
139
184
        import os
140
185
        if params.has_key('user') and params['user'] != '':
141
 
            user = "-U %s" % params['user']
 
186
            user = "-U %s%%%s" % (params['user'], params['passwd'])
142
187
        else:
143
 
            user =''
144
 
 
145
 
 
146
 
        os.system("net ads join %s" % user)
 
188
            #dummy password to stop UI blocking
 
189
            user ='-U root%%foo'
147
190
 
148
191
        # get a handle on the winbind auth method, so we can play with it
149
192
        wb = self.at.get_method_obj('Winbind')
 
193
        print dir(wb)
 
194
        # Create a new config file with 'security=ads', workgroup=domain and 'realm=domain'
 
195
        realm = domain.upper()
 
196
        smb_conf = wb.skeleton_conf( {'global':{'security':'ads','workgroup':domain,'realm':realm}})
 
197
        print "net ads join -s %s %s" % (smb_conf.name, user)
 
198
        os.system("net ads join -s %s %s" % (smb_conf.name, user))
 
199
 
150
200
        
151
201
    def detect(self, params):
152
202
        # does this params['domain'] match a kerberos service?
158
208
        self.ldap_server = self.dns.SRV('ldap', domain=params['domain'])['host']
159
209
        if self.krb_tgt_server != '' and self.ldap_server != '':
160
210
            self.discovery = True
161
 
            print "Matches AD domain"
 
211
            #print "Matches AD domain"
162
212
            return True