summaryrefslogtreecommitdiffstats
path: root/source3/python
ModeNameSize
-rw-r--r--.cvsignore5logstatsplain
-rw-r--r--README889logstatsplain
d---------examples68logstatsplain
-rwxr-xr-xgprinterdata941logstatsplain
-rwxr-xr-xgtdbtool772logstatsplain
-rwxr-xr-xgtkdictbrowser.py7283logstatsplain
-rw-r--r--py_common.c6210logstatsplain
-rw-r--r--py_common.h2410logstatsplain
-rw-r--r--py_conv.c4644logstatsplain
-rw-r--r--py_conv.h1416logstatsplain
-rw-r--r--py_lsa.c10670logstatsplain
-rw-r--r--py_lsa.h1157logstatsplain
-rw-r--r--py_ntsec.c5882logstatsplain
-rw-r--r--py_samr.c15989logstatsplain
-rw-r--r--py_samr.h2363logstatsplain
-rw-r--r--py_samr_conv.c3021logstatsplain
-rw-r--r--py_smb.c9530logstatsplain
-rw-r--r--py_smb.h1105logstatsplain
-rw-r--r--py_spoolss.c14622logstatsplain
-rw-r--r--py_spoolss.h7441logstatsplain
-rw-r--r--py_spoolss_common.c1149logstatsplain
-rw-r--r--py_spoolss_drivers.c9504logstatsplain
-rw-r--r--py_spoolss_drivers_conv.c5544logstatsplain
-rw-r--r--py_spoolss_forms.c6126logstatsplain
-rw-r--r--py_spoolss_forms_conv.c2648logstatsplain
-rw-r--r--py_spoolss_jobs.c9155logstatsplain
-rw-r--r--py_spoolss_jobs_conv.c3824logstatsplain
-rw-r--r--py_spoolss_ports.c3302logstatsplain
-rw-r--r--py_spoolss_ports_conv.c1730logstatsplain
-rw-r--r--py_spoolss_printerdata.c10968logstatsplain
-rw-r--r--py_spoolss_printers.c10584logstatsplain
-rw-r--r--py_spoolss_printers_conv.c11678logstatsplain
-rw-r--r--py_srvsvc.c5667logstatsplain
-rw-r--r--py_srvsvc.h1023logstatsplain
-rw-r--r--py_srvsvc_conv.c1495logstatsplain
-rw-r--r--py_tdb.c15522logstatsplain
-rw-r--r--py_tdb.h888logstatsplain
-rw-r--r--py_tdbpack.c19156logstatsplain
-rw-r--r--py_winbind.c18638logstatsplain
-rw-r--r--py_winbind.h1043logstatsplain
-rw-r--r--py_winbind_conv.c1653logstatsplain
-rw-r--r--py_winreg.c2010logstatsplain
-rw-r--r--py_winreg.h897logstatsplain
d---------samba119logstatsplain
-rwxr-xr-xsetup.py7412logstatsplain
server. It will create an LDAP connection (from a session cookie or the KRB5CCNAME header) and then dispatch the request to the appropriate application. In WSGI parlance, `session` is *middleware*. """ def __init__(self): super(session, self).__init__() self.__apps = {} def __iter__(self): for key in sorted(self.__apps): yield key def __getitem__(self, key): return self.__apps[key] def __contains__(self, key): return key in self.__apps def __call__(self, environ, start_response): try: self.create_context(ccache=environ.get('KRB5CCNAME')) return self.route(environ, start_response) finally: destroy_context() def finalize(self): self.url = self.env['mount_ipa'] super(session, self).finalize() def route(self, environ, start_response): key = shift_path_info(environ) if key in self.__apps: app = self.__apps[key] return app(environ, start_response) return not_found(environ, start_response) def mount(self, app, key): """ Mount the WSGI application *app* at *key*. """ # if self.__islocked__(): # raise StandardError('%s.mount(): locked, cannot mount %r at %r' % ( # self.name, app, key) # ) if key in self.__apps: raise StandardError('%s.mount(): cannot replace %r with %r at %r' % ( self.name, self.__apps[key], app, key) ) self.info('Mounting %r at %r', app, key) self.__apps[key] = app class WSGIExecutioner(Executioner): """ Base class for execution backends with a WSGI application interface. """ key = '' def set_api(self, api): super(WSGIExecutioner, self).set_api(api) if 'session' in self.api.Backend: self.api.Backend.session.mount(self, self.key) def finalize(self): self.url = self.env.mount_ipa + self.key super(WSGIExecutioner, self).finalize() def wsgi_execute(self, environ): result = None error = None _id = None lang= os.environ['LANG'] try: if ('HTTP_ACCEPT_LANGUAGE' in environ): os.environ['LANG']=string.split( environ['HTTP_ACCEPT_LANGUAGE'],",")[0].split(';')[0] if ( environ.get('CONTENT_TYPE', '').startswith(self.content_type) and environ['REQUEST_METHOD'] == 'POST' ): data = read_input(environ) (name, args, options, _id) = self.unmarshal(data) else: (name, args, options, _id) = self.simple_unmarshal(environ) if name not in self.Command: raise CommandError(name=name) result = self.Command[name](*args, **options) except PublicError, e: error = e except StandardError, e: self.exception( 'non-public: %s: %s', e.__class__.__name__, str(e) ) error = InternalError() finally: os.environ['LANG']=lang return self.marshal(result, error, _id) def simple_unmarshal(self, environ): name = environ['PATH_INFO'].strip('/') options = extract_query(environ) return (name, tuple(), options, None) def __call__(self, environ, start_response): """ WSGI application for execution. """ try: status = '200 OK' response = self.wsgi_execute(environ) headers = [('Content-Type', self.content_type + '; charset=utf-8')] except StandardError, e: self.exception('%s.__call__():', self.name) status = '500 Internal Server Error' response = status headers = [('Content-Type', 'text/plain')] start_response(status, headers) return [response] def unmarshal(self, data): raise NotImplementedError('%s.unmarshal()' % self.fullname) def marshal(self, result, error, _id=None): raise NotImplementedError('%s.marshal()' % self.fullname) class xmlserver(WSGIExecutioner): """ Execution backend plugin for XML-RPC server. Also see the `ipalib.rpc.xmlclient` plugin. """ content_type = 'text/xml' key = 'xml' def finalize(self): self.__system = { 'system.listMethods': self.listMethods, 'system.methodSignature': self.methodSignature, 'system.methodHelp': self.methodHelp, } super(xmlserver, self).finalize() def listMethods(self, *params): return tuple(name.decode('UTF-8') for name in self.Command) def methodSignature(self, *params): return u'methodSignature not implemented' def methodHelp(self, *params): return u'methodHelp not implemented' def marshaled_dispatch(self, data, ccache, client_ip): """ Execute the XML-RPC request contained in ``data``. """ try: self.create_context(ccache=ccache, client_ip=client_ip) (params, name) = xml_loads(data) if name in self.__system: response = (self.__system[name](*params),) else: (args, options) = params_2_args_options(params) response = (self.execute(name, *args, **options),) except PublicError, e: self.info('response: %s: %s', e.__class__.__name__, str(e)) response = Fault(e.errno, e.strerror) return xml_dumps(response, methodresponse=True) def unmarshal(self, data): (params, name) = xml_loads(data) (args, options) = params_2_args_options(params) return (name, args, options, None) def marshal(self, result, error, _id=None): if error: self.info('response: %s: %s', error.__class__.__name__, str(error)) response = Fault(error.errno, error.strerror) else: if isinstance(result, dict): self.info('response: entries returned %d', result.get('count', 1)) response = (result,) return xml_dumps(response, methodresponse=True) def json_encode_binary(val): ''' JSON cannot encode binary values. We encode binary values in Python str objects and text in Python unicode objects. In order to allow a binary object to be passed through JSON we base64 encode it thus converting it to text which JSON can transport. To assure we recognize the value is a base64 encoded representation of the original binary value and not confuse it with other text we convert the binary value to a dict in this form: {'__base64__' : base64_encoding_of_binary_value} This modification of the original input value cannot be done "in place" as one might first assume (e.g. replacing any binary items in a container (e.g. list, tuple, dict) with the base64 dict because the container might be an immutable object (i.e. a tuple). Therefore this function returns a copy of any container objects it encounters with tuples replaced by lists. This is O.K. because the JSON encoding will map both lists and tuples to JSON arrays. ''' if isinstance(val, dict): new_dict = {} for k,v in val.items(): if isinstance(v, str): new_dict[k] = {'__base64__' : base64.b64encode(v)} else: new_dict[k] = json_encode_binary(v) del val return new_dict elif isinstance(val, (list, tuple)): new_list = [] n = len(val) i = 0 while i < n: v = val[i] if isinstance(v, str): new_list.append({'__base64__' : base64.b64encode(v)}) else: new_list.append(json_encode_binary(v)) i += 1 del val return new_list elif isinstance(val, str): return {'__base64__' : base64.b64encode(val)} else: return val def json_decode_binary(val): ''' JSON cannot transport binary data. In order to transport binary data we convert binary data to a form like this: {'__base64__' : base64_encoding_of_binary_value} see json_encode_binary() After JSON had decoded the JSON stream back into a Python object we must recursively scan the object looking for any dicts which might represent binary values and replace the dict containing the base64 encoding of the binary value with the decoded binary value. Unlike the encoding problem where the input might consist of immutable object, all JSON decoded container are mutable so the conversion could be done in place. However we don't modify objects in place because of side effects which may be dangerous. Thus we elect to spend a few more cycles and avoid the possibility of unintended side effects in favor of robustness. ''' if isinstance(val, dict): if val.has_key('__base64__'): return base64.b64decode(val['__base64__']) else: new_dict = {} for k,v in val.items(): if isinstance(v, dict) and v.has_key('__base64__'): new_dict[k] = base64.b64decode(v['__base64__']) else: new_dict[k] = json_decode_binary(v) del val return new_dict elif isinstance(val, list): new_list = [] n = len(val) i = 0 while i < n: v = val[i] if isinstance(v, dict) and v.has_key('__base64__'): binary_val = base64.b64decode(v['__base64__']) new_list.append(binary_val) else: new_list.append(json_decode_binary(v)) i += 1 del val return new_list else: return val class jsonserver(WSGIExecutioner): """ JSON RPC server. For information on the JSON-RPC spec, see: http://json-rpc.org/wiki/specification """ content_type = 'application/json' key = 'json' def marshal(self, result, error, _id=None): if error: assert isinstance(error, PublicError) error = dict( code=error.errno, message=error.strerror, name=error.__class__.__name__, kw=dict(error.kw), ) response = dict( result=result, error=error, id=_id, ) response = json_encode_binary(response) return json.dumps(response, sort_keys=True, indent=4) def unmarshal(self, data): try: d = json.loads(data) except ValueError, e: raise JSONError(error=e) if not isinstance(d, dict): raise JSONError(error='Request must be a dict') if 'method' not in d: raise JSONError(error='Request is missing "method"') if 'params' not in d: raise JSONError(error='Request is missing "params"') d = json_decode_binary(d) method = d['method'] params = d['params'] _id = d.get('id') if not isinstance(params, (list, tuple)): raise JSONError(error='params must be a list') if len(params) != 2: raise JSONError( error='params must contain [args, options]' ) args = params[0] if not isinstance(args, (list, tuple)): raise JSONError( error='params[0] (aka args) must be a list' ) options = params[1] if not isinstance(options, dict): raise JSONError( error='params[1] (aka options) must be a dict' ) options = dict((str(k), v) for (k, v) in options.iteritems()) return (method, args, options, _id)