Esempio n. 1
0
    def __init__(self, *args, **kwargs):
        super(PosixLDIFRadius, self).__init__(*args, **kwargs)

        auth_attr = LDIFutils.ldapconf('USER', 'auth_attr', None)
        self.samba_nt_password = AuthExporter.make_exporter(
            self.db,
            auth_attr['sambaNTPassword'])
 def __init__(self):
     self.user_dn = ldapconf('RADIUS', 'dn', None)
     self.db = Factory.get('Database')()
     self.const = Factory.get('Constants')(self.db)
     self.account = Factory.get('Account')(self.db)
     self.auth = None
     self.id2vlan_vpn = {}
     for spread in reversed(cereconf.LDAP_RADIUS['spreads']):
         vlan_vpn = (cereconf.LDAP_RADIUS['spread2vlan'][spread],
                     "OU=%s;" % cereconf.LDAP_RADIUS['spread2vpn'][spread])
         spread = self.const.Spread(spread)
         for row in self.account.search(spread=spread):
             self.id2vlan_vpn[row['account_id']] = vlan_vpn
     # Configure auth
     auth_attr = ldapconf('RADIUS', 'auth_attr', None)
     self.user_password = AuthExporter.make_exporter(
         self.db, auth_attr['userPassword'])
     self.nt_password = AuthExporter.make_exporter(self.db,
                                                   auth_attr['ntPassword'])
Esempio n. 3
0
    def __init__(self, db, logger, u_sprd=None, g_sprd=None, n_sprd=None,
                 fd=None):
        """ Initiate database and import modules.

        Spreads are given in initiation and general constants which is
        used in more than one method.

        """
        timer = make_timer(logger, 'Initing PosixLDIF...')
        from Cerebrum.modules import PosixGroup
        self.db = db
        self.logger = logger
        self.const = Factory.get('Constants')(self.db)
        self.grp = Factory.get('Group')(self.db)
        self.posuser = Factory.get('PosixUser')(self.db)
        self.posgrp = PosixGroup.PosixGroup(self.db)
        self.user_dn = LDIFutils.ldapconf('USER', 'dn', None)
        # This is an odd one -- if set to False, then id2uname should be
        # populated with users exported in the users export -- which makes the
        # group exports filter group members by *actually* exported users...
        self.get_name = True
        self.fd = fd
        self.spread_d = {}
        # Validate spread from arg or from cereconf
        for x, y in zip(['USER', 'FILEGROUP', 'NETGROUP'],
                        [u_sprd, g_sprd, n_sprd]):
            spread = LDIFutils.map_spreads(
                y or getattr(cereconf, 'LDAP_' + x).get('spread'), list)
            if spread:
                self.spread_d[x.lower()] = spread
        if 'user' not in self.spread_d:
            raise Errors.ProgrammingError(
                "Must specify spread-value as 'arg' or in cereconf")
        self.account2name = dict()
        self.group2gid = dict()
        self.groupcache = defaultdict(dict)
        self.group2groups = defaultdict(set)
        self.group2users = defaultdict(set)
        self.group2persons = defaultdict(list)
        self.shell_tab = dict()
        self.quarantines = dict()
        self.user_exporter = UserExporter(self.db)
        if len(self.spread_d['user']) > 1:
            logger.warning('Exporting users with multiple spreads, '
                           'ignoring homedirs from %r',
                           self.spread_d['user'][1:])
        self.homedirs = HomedirResolver(db, self.spread_d['user'][0])
        self.owners = OwnerResolver(db)

        auth_attr = LDIFutils.ldapconf('USER', 'auth_attr', None)
        self.user_password = AuthExporter.make_exporter(
            db,
            auth_attr['userPassword'])
        timer('... done initing PosixLDIF.')
Esempio n. 4
0
    def __init__(self, logger):
        """ Fetches all users and groups with the required spreads to qualify
        for LDAP export. """

        self.db = Factory.get("Database")()
        self.const = Factory.get("Constants")(self.db)
        self.logger = logger

        # groups must be populated before users, since the latter relies on the
        # former due to data precaching.
        auth_attr = ldapconf('USER', 'auth_attr', {})
        self.user_password = AuthExporter.make_exporter(
            self.db, auth_attr['userPassword'])
        self.groups = self._load_groups()
        self.users = self._load_users()
    def __init__(self, db, ldif, spread):
        """ Set up object with ldap config.

        :param ldif: The LDIFWriter object that contains our settings
        :param spread: The spread that identifies guests. Default: Fetch spread
                       from guestconfig.LDAP['spread']

        """
        self.db = db
        self.spread = spread
        self.object_class = ldif.getconf('objectClass')
        auth_attrs = ldif.getconf('auth_attr')
        self.auth = dict()
        for attr in auth_attrs:
            logger.debug('Configuring auth attr %r: %r', attr,
                         auth_attrs[attr])
            self.auth[attr] = AuthExporter.make_exporter(db, auth_attrs[attr])
Esempio n. 6
0
def main(inargs=None):
    parser = argparse.ArgumentParser(description='Generate a mail-db.ldif', )
    parser.add_argument(
        '-v',
        "--verbose",
        action="count",
        default=0,
        help=('Show some statistics while running. '
              'Repeat the option for more verbosity.'),
    )
    parser.add_argument(
        '-m',
        "--mail-file",
        help='Specify file to write to.',
    )
    parser.add_argument(
        '-s',
        "--spread",
        default=ldapconf('MAIL', 'spread', None),
        help='Targets printed found in spread.',
    )
    parser.add_argument(
        '-i',
        "--ignore-size",
        dest="max_change",
        action="store_const",
        const=100,
        help='Use file class instead of SimilarSizeWriter.',
    )
    parser.add_argument(
        '-a',
        "--no-auth-data",
        dest="auth",
        action="store_false",
        default=True,
        help="Don't populate userPassword.",
    )
    Cerebrum.logutils.options.install_subparser(parser)

    args = parser.parse_args(inargs)
    Cerebrum.logutils.autoconf('cronjob', args)

    logger.info('Start %s', parser.prog)
    logger.debug('args: %s', repr(args))

    db = Factory.get('Database')()

    start = now()

    with log_time('loading the EmailLDAP module'):
        ldap = Factory.get('EmailLDAP')(db)

    spread = args.spread
    if spread is not None:
        spread = map_spreads(spread, int)

    # Configure auth
    if args.auth:
        auth_attr = ldapconf('MAIL', 'auth_attr', None)
        user_password = AuthExporter.make_exporter(db,
                                                   auth_attr['userPassword'])
    else:
        user_password = None

    outfile = ldif_outfile('MAIL', args.mail_file, max_change=args.max_change)
    logger.debug('writing data to %s', repr(outfile))

    with log_time('fetching data', level=logging.INFO):
        get_data(db, ldap, getattr(user_password, 'cache', None), spread)

    with log_time('generating ldif', level=logging.INFO):
        write_ldif(db, ldap, user_password, outfile, verbose=args.verbose)

    end_ldif_outfile('MAIL', outfile)

    logger.info("Total time: %ds" % (now() - start))
    logger.info('Done %s', parser.prog)