def do_vi(self, argstr): """Edit a directory entry. usage: vi [-c class1,class2] dn -c specifies a list of classes -t specifies a timeout. default is infinite. entry dn defaults to current location """ # Defaults timeout = -1 dn = '' ocs = [] # list of object classes if not self.schema: self.do_load_schema("") if argstr: optdict, args = parse_args(argstr, "c:t:") argc = len(args) if argc: dn = self.get_dn(args[0]) else: print "No dn specified" return if optdict.has_key('-c'): ocstr = optdict.get('-c') ocs = ocstr.split(",") if optdict.has_key('-t'): try: timeout = int(optdict.get('-t')) except ValueError, e: print "Invalid value for timeout. Should be integer (-1 for unlimited, the default)", e
def do_cat(self, argstr): """Display contents of directory entry. usage: cat [-a attr1,attr2] [-t timeout] [entry dn] -a specified a list of attributes to return. default is all (except specials). -t specifies a timeout. default is infinite. entry dn defaults to current location """ # Defaults dn = self.dn filter = "objectClass=*" attrs = None timeout = -1 scope = ldap.SCOPE_BASE attrs_only = 0 if argstr: optdict, args = parse_args(argstr, "a:t:f:") argc = len(args) if argc: dn = args[0] if optdict.has_key('-a'): attrstr = optdict.get('-a') attrs = attrstr.split(",") if optdict.has_key('-t'): try: timeout = int(optdict.get('-t')) except ValueError, e: print "Invalid value for timeout. Should be integer (-1 for unlimited)", e
def do_dump_schema(self, argstr): outfile = '' if argstr: optdict, args = parse_args(argstr, "f:") outfile = optdict.get('-f', '') outfh = sys.stdout if outfile: try: outfh = open(outfile, "w") except IOError, e: print "Could not open output file (%s)" % outfile print "error:", sys.exc_type, e
def do_describe_at(self, argstr): """Print schema information for specified attribute. usage: describe_at atname """ if argstr: optdict, args = parse_args(argstr, "") if not args: print "No attribute class name specified." if not self.schema: self.do_load_schema("") print self.schema.get_at(args[0])
def do_find(self, argstr): """Search the directory. usage: find [-a attr1,attr2] [-t timeout] [-s base|subtree|onelevel] [filter] [searchbase] -a specified a list of attributes to return. default is all (except specials). -t specifies a timeout. default is infinite. -s specifies search scope. default is subtree filter defaults to "objectClass=*" searchbase defaults to current location """ if not self.conn: print "Not bound to directory." return searchbase = self.dn filter = "objectClass=*" attrs = None timeout = -1 scope = ldap.SCOPE_SUBTREE attrs_only = 0 if argstr: optdict, args = parse_args(argstr, "a:t:s:") argc = len(args) if argc: filter = args[0] if argc == 2: searchbase = args[1] if optdict.has_key('-a'): attrstr = optdict.get('-a') attrs = attrstr.split(",") if optdict.has_key('-t'): try: timeout = int(optdict.get('-t')) except ValueError, e: print "Invalid value for timeout.", e if optdict.has_key('-s'): value = optdict.get('-s') if value == 'base': scope = ldap.SCOPE_BASE elif value == 'subtree': scope = ldap.SCOPE_SUBTREE elif value == 'onelevel': scope = ldap.SCOPE_ONELEVEL else: print "Invalid value for scope"
def do_get_ldif(self, argstr): """Display contents of directory entry. usage: get_ldif [-a attr1,attr2] [-t timeout] [-f outfile] [entry dn] -a specified a list of attributes to return. default is all (except specials). -t specifies a timeout. default is infinite. entry dn defaults to current location """ # Defaults dn = self.dn filter = "objectClass=*" attrs = None timeout = -1 scope = ldap.SCOPE_BASE attrs_only = 0 outfh = sys.stdout outfile = '' if argstr: optdict, args = parse_args(argstr, "a:t:f:") argc = len(args) if argc: dn = args[0] if optdict.has_key('-a'): attrstr = optdict.get('-a') attrs = attrstr.split(",") outfile = optdict.get('-f', '') if outfile: try: outfh = open(outfile, "w") except IOError, e: print "Could not open output file (%s)" % outfile print "error:", sys.exc_type, e if optdict.has_key('-t'): try: timeout = int(optdict.get('-t')) except ValueError, e: print "Invalid value for timeout.", e
def do_print_schema(self, argstr): """Print raw schema info from directory. usage: print_schema [-f outfile] """ outfile = '' if argstr: optdict, args = parse_args(argstr, "f:") outfile = optdict.get('-f', '') # Get subschemaSubentry location from root entry attrs = ['subschemaSubentry', 'subschemasubentry'] try: result = self.conn.search_s("", ldap.SCOPE_BASE, "objectClass=*", attrs) if len(result): values = result[0][1] subentry_dns = get_data_i(values, 'subschemaSubentry') subentry_dn = subentry_dns[0] else: print "Root DSE not found" return except LDAPError, e: print "error:", sys.exc_type, e