333870bb |
1 | |
2 | |
3 | cdef extern from *: |
4 | ctypedef int uid_t |
5 | ctypedef int gid_t |
6 | enum: |
7 | NGROUPS_MAX |
8 | |
9 | cdef extern from "checkpath.h": |
10 | struct checkpath: |
11 | uid_t cp_uid |
12 | gid_t cp_gid[NGROUPS_MAX + 1] |
13 | int cp_gids |
14 | int cp_verbose |
15 | unsigned cp_what |
16 | void (*cp_report)(unsigned, int, char *, char *, void *) |
17 | void *cp_arg |
18 | enum: |
19 | c_CP_ERROR "CP_ERROR" |
20 | c_CP_WRWORLD "CP_WRWORLD" |
21 | c_CP_WRGRP "CP_WRGRP" |
22 | c_CP_WROTHGRP "CP_WROTHGRP" |
23 | c_CP_WROTHUSR "CP_WROTHUSR" |
24 | c_CP_PROBLEMS "CP_PROBLEMS" |
25 | c_CP_SYMLINK "CP_SYMLINK" |
26 | c_CP_REPORT "CP_REPORT" |
27 | c_CP_STICKYOK "CP_STICKYOK" |
28 | int c_checkpath "checkpath"(char *path, checkpath *cp) except * |
29 | void c_checkpath_setids "checkpath_setids"(checkpath *cp) |
30 | |
31 | ERROR = c_CP_ERROR |
32 | WRWORLD = c_CP_WRWORLD |
33 | WRGRP = c_CP_WRGRP |
34 | WROTHGRP = c_CP_WROTHGRP |
35 | WROTHUSR = c_CP_WROTHUSR |
36 | PROBLEMS = c_CP_PROBLEMS |
37 | SYMLINK = c_CP_SYMLINK |
38 | REPORT = c_CP_REPORT |
39 | STICKYOK = c_CP_STICKYOK |
40 | |
41 | cdef void cp_report(unsigned what, int verb, |
42 | char *path, char *msg, void *arg): |
43 | cdef object cp |
44 | cp = <object>arg |
45 | if msg is NULL: |
46 | msg = '<null>' |
47 | cp.report(what, verb, path, msg) |
48 | |
49 | cdef class CheckPath: |
50 | cdef checkpath cp |
51 | def __init__(me): |
52 | me.cp.cp_uid = 0 |
53 | me.cp.cp_gids = 0 |
54 | me.cp.cp_verbose = 1 |
55 | me.cp.cp_what = c_CP_PROBLEMS |
56 | me.cp.cp_report = cp_report |
57 | me.cp.cp_arg = <void *>me |
58 | c_checkpath_setids(&me.cp) |
59 | def setids(me): |
60 | c_checkpath_setids(&me.cp) |
61 | property uid: |
62 | def __get__(me): |
63 | return me.cp.cp_uid |
64 | def __set__(me, val): |
65 | me.cp.cp_uid = val |
66 | property gids: |
67 | def __get__(me): |
68 | g = [] |
69 | for i from 0 <= i < me.cp.cp_gids: |
70 | g[i] = me.cp.cp_gid[i] |
71 | return g |
72 | def __set__(me, val): |
73 | if len(val) >= NGROUPS_MAX + 1: |
74 | raise TypeError, 'too many groups' |
75 | for i from 0 <= i < len(val): |
76 | me.cp.cp_gid[i] = val[i] |
77 | me.cp.cp_gids = len(val) |
78 | property verbose: |
79 | def __get__(me): |
80 | return me.cp.cp_verbose |
81 | def __set__(me, val): |
82 | me.cp.cp_verbose = val |
83 | property what: |
84 | def __get__(me): |
85 | return me.cp.cp_what |
86 | def __set__(me, val): |
87 | me.cp.cp_what = val |
88 | def check(me, path): |
89 | return c_checkpath(path, &me.cp) |
90 | def report(me, what, verb, path, msg): |
91 | pass |
92 | |