summaryrefslogtreecommitdiff
path: root/source4/scripting
diff options
context:
space:
mode:
authorGünther Deschner <gd@samba.org>2016-09-27 20:31:58 +0200
committerAndrew Bartlett <abartlet@samba.org>2017-02-14 09:46:22 +0100
commitb806b69d198c0a95386695d2cc902f7a5005bd72 (patch)
treed39ea2db1083957eba93d64bad647cb2305a4b21 /source4/scripting
parent4f558c9ad6f9b8a947e33207473579655708eed0 (diff)
downloadsamba-b806b69d198c0a95386695d2cc902f7a5005bd72.tar.gz
errors: generate python error codes for NTSTATUS
Guenther Signed-off-by: Guenther Deschner <gd@samba.org> Reviewed-by: Andrew Bartlett <abartlet@samba.org> Reviewed-by: Garming Sam <garming@catalyst.net.nz>
Diffstat (limited to 'source4/scripting')
-rwxr-xr-xsource4/scripting/bin/gen_ntstatus.py31
1 files changed, 31 insertions, 0 deletions
diff --git a/source4/scripting/bin/gen_ntstatus.py b/source4/scripting/bin/gen_ntstatus.py
index bf57fefc228..dd0c3263274 100755
--- a/source4/scripting/bin/gen_ntstatus.py
+++ b/source4/scripting/bin/gen_ntstatus.py
@@ -165,6 +165,32 @@ def generateSourceFile(out_file):
for err in ErrorsToUse:
out_file.write(" { \"%s\", %s },\n"%(err.err_define, err.err_define))
+def generatePythonFile(out_file):
+ out_file.write("/*\n")
+ out_file.write(" * New descriptions for existing errors generated from\n")
+ out_file.write(" * [MS-ERREF] http://msdn.microsoft.com/en-us/library/cc704588.aspx\n")
+ out_file.write(" */\n")
+ out_file.write("#include <Python.h>\n")
+ out_file.write("#include \"includes.h\"\n\n")
+ out_file.write("static inline PyObject *ndr_PyLong_FromUnsignedLongLong(unsigned long long v)\n");
+ out_file.write("{\n");
+ out_file.write("\tif (v > LONG_MAX) {\n");
+ out_file.write("\t\treturn PyLong_FromUnsignedLongLong(v);\n");
+ out_file.write("\t} else {\n");
+ out_file.write("\t\treturn PyInt_FromLong(v);\n");
+ out_file.write("\t}\n");
+ out_file.write("}\n\n");
+ out_file.write("void initntstatus(void)\n")
+ out_file.write("{\n")
+ out_file.write("\tPyObject *m;\n\n")
+ out_file.write("\tm = Py_InitModule3(\"ntstatus\", NULL, \"NTSTATUS error defines\");\n");
+ out_file.write("\tif (m == NULL)\n");
+ out_file.write("\t\treturn;\n\n");
+ for err in ErrorsToUse:
+ line = "\tPyModule_AddObject(m, \"%s\", ndr_PyLong_FromUnsignedLongLong(0x%08x));\n" % (err.err_define, err.err_code)
+ out_file.write(line)
+ out_file.write("}\n");
+
def def_in_list(define, err_def_with_desc):
for item in err_def_with_desc:
if item.strip() == define:
@@ -217,6 +243,7 @@ def main ():
filename = "ntstatus"
headerfile_name = filename + ".h"
sourcefile_name = filename + ".c"
+ pythonfile_name = "py_" + filename + ".c"
if len(sys.argv) > 3:
input_file1 = sys.argv[1]
input_file2 = sys.argv[2]
@@ -241,6 +268,10 @@ def main ():
out_file = open(sourcefile_name,"w")
generateSourceFile(out_file)
out_file.close()
+ print "writing new headerfile: %s"%pythonfile_name
+ out_file = open(pythonfile_name,"w")
+ generatePythonFile(out_file)
+ out_file.close()
if __name__ == '__main__':