diff options
author | Tim Potter <tpot@samba.org> | 2002-05-02 05:23:38 +0000 |
---|---|---|
committer | Tim Potter <tpot@samba.org> | 2002-05-02 05:23:38 +0000 |
commit | aa69c1ee80fbf7f45d61861089daeb5828e91229 (patch) | |
tree | db681d1494af3ff0d1a7ec48ffa86cd5150428c5 /source3 | |
parent | 9d4f9bda320be9c17f2cf95ecd4d230f6a5283e5 (diff) | |
download | samba-aa69c1ee80fbf7f45d61861089daeb5828e91229.tar.gz samba-aa69c1ee80fbf7f45d61861089daeb5828e91229.tar.bz2 samba-aa69c1ee80fbf7f45d61861089daeb5828e91229.zip |
Some examples using the spoolss python module.
(This used to be commit 68b952561429e1d08a974e633bb9c2870c819c69)
Diffstat (limited to 'source3')
-rwxr-xr-x | source3/python/examples/spoolss/changeid.py | 29 | ||||
-rwxr-xr-x | source3/python/examples/spoolss/enumprinters.py | 25 | ||||
-rwxr-xr-x | source3/python/examples/spoolss/psec.py | 87 |
3 files changed, 141 insertions, 0 deletions
diff --git a/source3/python/examples/spoolss/changeid.py b/source3/python/examples/spoolss/changeid.py new file mode 100755 index 0000000000..b2345094ed --- /dev/null +++ b/source3/python/examples/spoolss/changeid.py @@ -0,0 +1,29 @@ +#!/usr/bin/python +# +# Display the changeid for a list of printers given on the command line +# + +import sys, spoolss + +if len(sys.argv) == 1: + print "Usage: changeid.py <printername>" + sys.exit(1) + +for printer in sys.argv[1:]: + + # Open printer handle + + try: + hnd = spoolss.openprinter(printer) + except: + print "error opening printer %s" % printer + sys.exit(1) + + # Fetch and display changeid + + info = hnd.getprinter(level = 0) + print info["change_id"] + + # Clean up + + spoolss.closeprinter(hnd) diff --git a/source3/python/examples/spoolss/enumprinters.py b/source3/python/examples/spoolss/enumprinters.py new file mode 100755 index 0000000000..bf08b95bb9 --- /dev/null +++ b/source3/python/examples/spoolss/enumprinters.py @@ -0,0 +1,25 @@ +#!/usr/bin/env python +# +# Display information on all printers on a print server +# + +import sys, spoolss + +if len(sys.argv) != 2: + print "Usage: changeid.py <printername>" + sys.exit(1) + +printserver = sys.argv[1] + +# Get list of printers + +try: + printer_list = spoolss.enumprinters(printserver) +except: + print "error enumerating printers on %s" % printserver + sys.exit(1) + +# Display basic info + +for printer in printer_list: + print "%s: %s" % (printer["printer_name"], printer["comment"]) diff --git a/source3/python/examples/spoolss/psec.py b/source3/python/examples/spoolss/psec.py new file mode 100755 index 0000000000..f3fdb7bccd --- /dev/null +++ b/source3/python/examples/spoolss/psec.py @@ -0,0 +1,87 @@ +#!/usr/bin/env python +# +# Get or set the security descriptor on a printer +# + +import sys, spoolss, re, string + +if len(sys.argv) != 3: + print "Usage: psec.py getsec|setsec printername" + sys.exit(1) + +op = sys.argv[1] +printername = sys.argv[2] + +# Display security descriptor + +if op == "getsec": + + try: + hnd = spoolss.openprinter(printername) + except: + print "error opening printer %s" % printername + sys.exit(1) + + secdesc = hnd.getprinter(level = 3)["security_descriptor"] + + print secdesc["owner_sid"] + print secdesc["group_sid"] + + for acl in secdesc["dacl"]["ace_list"]: + print "%d %d 0x%08x %s" % (acl["type"], acl["flags"], + acl["mask"], acl["trustee"]) + + spoolss.closeprinter(hnd) + + sys.exit(0) + +# Set security descriptor + +if op == "setsec": + + # Open printer + + try: + hnd = spoolss.openprinter(printername, + creds = {"domain": "NPSD-TEST2", + "username": "Administrator", + "password": "penguin"}) + except: + print "error opening printer %s" % printername + sys.exit(1) + + # Read lines from standard input and build security descriptor + + lines = sys.stdin.readlines() + + secdesc = {} + + secdesc["owner_sid"] = lines[0] + secdesc["group_sid"] = lines[1] + + secdesc["revision"] = 1 + secdesc["dacl"] = {} + secdesc["dacl"]["revision"] = 2 + secdesc["dacl"]["ace_list"] = [] + + for acl in lines[2:]: + match = re.match("(\d+) (\d+) (0[xX][\dA-Fa-f]+) (\S+)", acl) + secdesc["dacl"]["ace_list"].append( + {"type": int(match.group(1)), "flags": int(match.group(2)), + "mask": string.atoi(match.group(3), 0), "trustee": match.group(4)}) + + # Build info3 structure + + info3 = {} + + info3["flags"] = 0x8004 # self-relative, dacl present + info3["level"] = 3 + info3["security_descriptor"] = secdesc + + hnd.setprinter(info3) + + spoolss.closeprinter(hnd) + sys.exit(0) + +print "invalid operation %s" % op +sys.exit(1) |