Esempio n. 1
0
 def test_password_3_generage(self):
     p = bacula_tools.PasswordStore(self.client, self.director)
     p.password = bacula_tools.GENERATE
     p.store()
     p = bacula_tools.PasswordStore(self.client, self.director)
     self.bc.do_sql('delete from pwords')
     self.assertNotEquals(p.password, bacula_tools.GENERATE)
     return
Esempio n. 2
0
 def _cli_special_do_parse(self, args):
     '''When setting the password, ensure that a Director is referenced.  If
     that's the case, make the appropriate updates.'''
     if (args.password == None) and (args.director == None):
         return  # Nothing to do!
     if (args.password == None) ^ (args.director == None):
         logger.warning(
             'You must specify both a password and a director to change a password.  No change.'
         )
         # Bail on any password changes, but otherwise continue
         return
     the_director = bacula_tools.Director().search(args.director)
     if not the_director[bacula_tools.ID]:
         logger.warning('Unable to find a director using "%s".  No change.',
                        args.director)
         return
     password = bacula_tools.PasswordStore(self, the_director)
     password.password = args.password
     if args.monitor:
         if args.monitor.lower() in bacula_tools.TRUE_VALUES:
             password.monitor = 1
         else:
             password.monitor = 0
     password.store()
     return
Esempio n. 3
0
 def sd(self):
     '''This is what we'll call to dump out the config for the storage daemon'''
     self.output = ['Director {\n  Name = "%(name)s"' % self, '}']
     if getattr(self, STORAGE_ID, None):
         a = bacula_tools.PasswordStore(
             bacula_tools.Storage().search(self.storage_id), self)
         if getattr(a, PASSWORD, None):
             self.output.insert(-1, '  Password = "******"' % a.password)
     return '\n'.join(self.output)
Esempio n. 4
0
 def fd(self):
     self.output = [
         'Director {\n  Name = "%(name)s"' % self, '  Monitor = yes', '}'
     ]
     if getattr(self, CLIENT_ID, None):
         c = bacula_tools.Client().search(self.client_id)
         a = bacula_tools.PasswordStore(c, self)
         self.output.insert(-1, '  Password = "******"' % a.password)
     return '\n'.join(self.output)
Esempio n. 5
0
 def test_password_load(self):
     self.bc.do_sql('delete from pwords')
     self.bc.do_sql(
         '''INSERT INTO pwords (obj_id, obj_type, director_id, director_type, password) values (%s, %s, %s, %s, %s)''',
         (self.client[bacula_tools.ID], self.client.IDTAG,
          self.director[bacula_tools.ID], self.director.IDTAG, 'fred'))
     p = bacula_tools.PasswordStore(self.client, self.director)
     self.bc.do_sql('delete from pwords')
     self.assertEquals(p.password, 'fred')
     return
Esempio n. 6
0
 def test_password_store_valid(self):
     PWORD = 'fred'
     self.bc.do_sql('delete from pwords')
     p = bacula_tools.PasswordStore(self.client, self.director)
     p.password = PWORD
     p.store()
     result = self.bc.do_sql(
         '''SELECT password FROM pwords WHERE obj_id=%s and obj_type=%s and director_id=%s and director_type=%s''',
         (self.client[bacula_tools.ID], self.client.IDTAG,
          self.director[bacula_tools.ID], self.director.IDTAG))
     self.bc.do_sql('delete from pwords')
     self.assertEquals(result, ((PWORD, ), ))
     return
Esempio n. 7
0
 def _cli_special_print(self):
     '''Prints out the passwords and the directors/consoles with which they are associated'''
     print('\nPasswords:')
     sql = 'select director_id, director_type from pwords where obj_id = %s and obj_type = %s'
     for row in self.bc.do_sql(sql, (self[bacula_tools.ID], self.IDTAG)):
         if row[1] == bacula_tools.Director.IDTAG:
             other = bacula_tools.Director().search(row[0])
         if row[1] == bacula_tools.Console.IDTAG:
             other = bacula_tools.Console().search(row[0])
         password = bacula_tools.PasswordStore(self, other)
         retval = '%30s: %s' % (other[bacula_tools.NAME], password.password)
         print(retval)
     return
Esempio n. 8
0
def default_director(client, dname=''):
    '''Selects a director (preferring the value passed in if possible), and
    creates a new password for use with that director.  You will
    undoubtedly want to OVERRIDE THIS to meet the needs of your own
    site.  The default in this case is the first one returned by a select
    against the director table with no where clause.'''
    if dname:
        d = bacula_tools.Director().search(dname)
    else:
        d = bacula_tools.Director().Find(order_by=bacula_tools.ID)[0]

    password = bacula_tools.PasswordStore(client, d)
    password.password = bacula_tools.GENERATE
    password.store()
Esempio n. 9
0
    def __str__(self):
        '''String representation of a Storage suitable for inclusion in a Director configuration.'''
        self.output = ['Storage {\n  Name = "%(name)s"' % self, '}']
        if getattr(self, bacula_tools.DIRECTOR_ID, None):
            a = bacula_tools.PasswordStore(
                self,
                bacula_tools.Director().search(self.director_id))
            if getattr(a, bacula_tools.PASSWORD, None):
                self.output.insert(-1, '  Password = "******"' % a.password)

        for key in self.dir_keys:
            self._simple_phrase(key)
        for key in self.BOOL_KEYS:
            self._simple_phrase(key)
        return '\n'.join(self.output)
Esempio n. 10
0
 def _cli_special_print(self):
     '''Print out the passwords for the CLI.'''
     print('\nPasswords:')
     sql = 'select director_id, director_type from pwords where obj_id = %s and obj_type = %s'
     for row in self.bc.do_sql(sql, (self[bacula_tools.ID], self.IDTAG)):
         if row[1] == bacula_tools.Director.IDTAG:
             other = bacula_tools.Director().search(row[0])
         if row[1] == bacula_tools.Console.IDTAG:
             other = bacula_tools.Console().search(row[0])
         try:
             password = bacula_tools.PasswordStore(self, other)
             print('%30s: %s' %
                   (other[bacula_tools.NAME], password.password))
         except:
             # There's no password assiciated with this director/console.
             pass
     return
Esempio n. 11
0
    def __str__(self):
        '''Convert a Client into a string suitable for inclusion into a Director's
configuration.'''
        self.output = ['Client {\n  Name = "%(name)s"' % self, '}']
        self.output.insert(
            -1, ' %s = "%s"' %
            (bacula_tools.CATALOG.capitalize(),
             self._fk_reference(bacula_tools.CATALOG_ID)[bacula_tools.NAME]))
        if getattr(self, bacula_tools.DIRECTOR_ID, None):
            pw_store = bacula_tools.PasswordStore(
                self,
                bacula_tools.Director().search(self.director_id))
            if getattr(pw_store, bacula_tools.PASSWORD, None):
                self.output.insert(-1, '  Password = "******"' % pw_store.password)
        for key in [
                bacula_tools.ADDRESS, bacula_tools.FDPORT,
                bacula_tools.FILERETENTION, bacula_tools.JOBRETENTION,
                bacula_tools.MAXIMUMCONCURRENTJOBS,
                bacula_tools.MAXIMUMBANDWIDTHPERJOB, bacula_tools.PRIORITY
        ]:
            self._simple_phrase(key)
        self._yesno_phrase(bacula_tools.AUTOPRUNE)
        return '\n'.join(self.output)
Esempio n. 12
0
 def _cli_special_do_parse(self, args):
     '''Handle CLI switches for password management.'''
     if (args.password == None) and (args.director == None):
         return  # Nothing to do!
     if (args.password == None) ^ (args.director == None):
         print(
             '\n***WARNING***: You must specify both a password and a director to change a password.  Password not changed.\n'
         )
         # Bail on any password changes, but otherwise continue
         return
     d = bacula_tools.Director()
     try:
         d.search(args.director)
     except:
         d.search(args.director)
     if not d[bacula_tools.ID]:
         print(
             '\n***WARNING***: Unable to find a director using "%s".  Password not changed\n'
             % args.director)
         return
     password = bacula_tools.PasswordStore(self, d)
     password.password = args.password
     password.store()
     return
Esempio n. 13
0
 def test_password_store_invalid(self):
     self.bc.do_sql('delete from pwords')
     p = bacula_tools.PasswordStore(self.client, self.director)
     p.store()
     self.assertRaises(AttributeError, p.store())
     return
Esempio n. 14
0
 def test_no_password(self):
     self.bc.do_sql('delete from pwords')
     p = bacula_tools.PasswordStore(self.client, self.director)
     self.assertFalse(p.password)
     return