Back to index

system-config-printer  1.3.9+20120706
Public Member Functions | Public Attributes
pysmb.AuthContext Class Reference

List of all members.

Public Member Functions

def __init__
def perform_authentication
def initial_authentication
def failed
def callback

Public Attributes

 passes
 has_failed
 auth_called
 tried_guest
 cancel
 use_user
 use_password
 use_workgroup
 dialog_shown
 parent
 for_server
 for_share

Detailed Description

Definition at line 47 of file pysmb.py.


Constructor & Destructor Documentation

def pysmb.AuthContext.__init__ (   self,
  parent = None,
  workgroup = '',
  user = '',
  passwd = '' 
)

Definition at line 48 of file pysmb.py.

00048 
00049     def __init__ (self, parent=None, workgroup='', user='', passwd=''):
00050         self.passes = 0
00051         self.has_failed = False
00052         self.auth_called = False
00053         self.tried_guest = False
00054         self.cancel = False
00055         self.use_user = user
00056         self.use_password = passwd
00057         self.use_workgroup = workgroup
00058         self.dialog_shown = False
00059         self.parent = parent


Member Function Documentation

def pysmb.AuthContext.callback (   self,
  server,
  share,
  workgroup,
  user,
  password 
)

Definition at line 184 of file pysmb.py.

00184 
00185     def callback (self, server, share, workgroup, user, password):
00186         debugprint ("pysmb: got password callback")
00187         self.auth_called = True
00188         self.for_server = server
00189         self.for_share = share
00190         if self.passes == 1:
00191             self.initial_authentication ()
00192 
00193         if self.use_user:
00194             if self.use_workgroup:
00195                 workgroup = self.use_workgroup
00196 
00197             return (workgroup, self.use_user, self.use_password)
00198 
00199         user = ''
00200         password = ''
00201         return (workgroup, user, password)
def pysmb.AuthContext.failed (   self,
  exc = None 
)

Definition at line 172 of file pysmb.py.

00172 
00173     def failed (self, exc=None):
00174         self.has_failed = True
00175         debugprint ("pysmb: operation failed: %s" % repr (exc))
00176 
00177         if exc:
00178             if (self.cancel or
00179                 (type (exc) in [NoEntryError, ExistsError, NotEmptyError,
00180                                 TimedOutError, NoSpaceError]) or
00181                 (type (exc) == RuntimeError and
00182                  not (exc.args[0] in [errno.EACCES, errno.EPERM]))):
00183                     raise exc

Definition at line 165 of file pysmb.py.

00165 
00166     def initial_authentication (self):
00167         try:
00168             context = smbc.Context ()
00169             self.use_workgroup = context.workgroup
00170         except:
00171             pass

Definition at line 60 of file pysmb.py.

00060 
00061     def perform_authentication (self):
00062         self.passes += 1
00063         if self.passes == 1:
00064             return 1
00065 
00066         if not self.has_failed:
00067             return 0
00068 
00069         debugprint ("pysmb: authentication pass: %d" % self.passes)
00070         if not self.auth_called:
00071             debugprint ("pysmb: auth callback not called?!")
00072             self.cancel = True
00073             return 0
00074 
00075         self.has_failed = False
00076         if self.auth_called and not self.tried_guest:
00077             self.use_user = 'guest'
00078             self.use_password = ''
00079             self.tried_guest = True
00080             debugprint ("pysmb: try auth as guest")
00081             return 1
00082 
00083         self.auth_called = False
00084 
00085         if self.dialog_shown:
00086             d = gtk.MessageDialog (self.parent,
00087                                    gtk.DIALOG_MODAL |
00088                                    gtk.DIALOG_DESTROY_WITH_PARENT,
00089                                    gtk.MESSAGE_ERROR,
00090                                    gtk.BUTTONS_CLOSE)
00091             d.set_title (_("Not authorized"))
00092             d.set_markup ('<span weight="bold" size="larger">' +
00093                           _("Not authorized") + '</span>\n\n' +
00094                           _("The password may be incorrect."))
00095             d.run ()
00096             d.destroy ()
00097 
00098         # After that, prompt
00099         d = gtk.Dialog (_("Authentication"), self.parent,
00100                         gtk.DIALOG_MODAL | gtk.DIALOG_NO_SEPARATOR,
00101                         (gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL,
00102                          gtk.STOCK_OK, gtk.RESPONSE_OK))
00103         d.set_default_response (gtk.RESPONSE_OK)
00104         d.set_border_width (6)
00105         d.set_resizable (False)
00106         hbox = gtk.HBox (False, 12)
00107         hbox.set_border_width (6)
00108         image = gtk.Image ()
00109         image.set_from_stock (gtk.STOCK_DIALOG_AUTHENTICATION,
00110                               gtk.ICON_SIZE_DIALOG)
00111         hbox.pack_start (image, False, False, 0)
00112         vbox = gtk.VBox (False, 12)
00113         label = gtk.Label ('<span weight="bold" size="larger">' +
00114                            _("You must log in to access %s.") % self.for_server +
00115                            '</span>')
00116         label.set_use_markup (True)
00117         label.set_alignment (0, 0)
00118         label.set_line_wrap (True)
00119         vbox.pack_start (label, False, False, 0)
00120 
00121         table = gtk.Table (3, 2)
00122         table.set_row_spacings (6)
00123         table.set_col_spacings (6)
00124         table.attach (gtk.Label (_("Username:")), 0, 1, 0, 1, 0, 0)
00125         username_entry = gtk.Entry ()
00126         table.attach (username_entry, 1, 2, 0, 1, 0, 0)
00127         table.attach (gtk.Label (_("Domain:")), 0, 1, 1, 2, 0, 0)
00128         domain_entry = gtk.Entry ()
00129         table.attach (domain_entry, 1, 2, 1, 2, 0, 0)
00130         table.attach (gtk.Label (_("Password:")), 0, 1, 2, 3, 0, 0)
00131         password_entry = gtk.Entry ()
00132         password_entry.set_activates_default (True)
00133         password_entry.set_visibility (False)
00134         table.attach (password_entry, 1, 2, 2, 3, 0, 0)
00135         vbox.pack_start (table, False, False, 0)
00136         hbox.pack_start (vbox, False, False, 0)
00137         d.vbox.pack_start (hbox)
00138         self.dialog_shown = True
00139         d.show_all ()
00140         d.show_now ()
00141 
00142         if self.use_user == 'guest':
00143             self.use_user = pwd.getpwuid (os.getuid ())[0]
00144             debugprint ("pysmb: try as %s" % self.use_user)
00145         username_entry.set_text (self.use_user)
00146         domain_entry.set_text (self.use_workgroup)
00147 
00148         d.set_keep_above (True)
00149         gtk.gdk.pointer_grab (d.window, True)
00150         gtk.gdk.keyboard_grab (d.window, True)
00151         response = d.run ()
00152         gtk.gdk.keyboard_ungrab ()
00153         gtk.gdk.pointer_ungrab ()
00154 
00155         if response == gtk.RESPONSE_CANCEL:
00156             self.cancel = True
00157             d.destroy ()
00158             return -1
00159 
00160         self.use_user = username_entry.get_text ()
00161         self.use_password = password_entry.get_text ()
00162         self.use_workgroup = domain_entry.get_text ()
00163         d.destroy ()
00164         return 1


Member Data Documentation

Definition at line 51 of file pysmb.py.

Definition at line 53 of file pysmb.py.

Definition at line 57 of file pysmb.py.

Definition at line 187 of file pysmb.py.

Definition at line 188 of file pysmb.py.

Definition at line 50 of file pysmb.py.

Definition at line 58 of file pysmb.py.

Definition at line 49 of file pysmb.py.

Definition at line 52 of file pysmb.py.

Definition at line 55 of file pysmb.py.

Definition at line 54 of file pysmb.py.

Definition at line 56 of file pysmb.py.


The documentation for this class was generated from the following file: