X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~mdw/git/checkpath-python/blobdiff_plain/e822318258fb5977492017f5df1cf9230dd3800d..333870bbf36270a9132707e1cb1aff9fc3ace8ab:/checkpath.pyx diff --git a/checkpath.pyx b/checkpath.pyx new file mode 100644 index 0000000..609119b --- /dev/null +++ b/checkpath.pyx @@ -0,0 +1,92 @@ + + +cdef extern from *: + ctypedef int uid_t + ctypedef int gid_t + enum: + NGROUPS_MAX + +cdef extern from "checkpath.h": + struct checkpath: + uid_t cp_uid + gid_t cp_gid[NGROUPS_MAX + 1] + int cp_gids + int cp_verbose + unsigned cp_what + void (*cp_report)(unsigned, int, char *, char *, void *) + void *cp_arg + enum: + c_CP_ERROR "CP_ERROR" + c_CP_WRWORLD "CP_WRWORLD" + c_CP_WRGRP "CP_WRGRP" + c_CP_WROTHGRP "CP_WROTHGRP" + c_CP_WROTHUSR "CP_WROTHUSR" + c_CP_PROBLEMS "CP_PROBLEMS" + c_CP_SYMLINK "CP_SYMLINK" + c_CP_REPORT "CP_REPORT" + c_CP_STICKYOK "CP_STICKYOK" + int c_checkpath "checkpath"(char *path, checkpath *cp) except * + void c_checkpath_setids "checkpath_setids"(checkpath *cp) + +ERROR = c_CP_ERROR +WRWORLD = c_CP_WRWORLD +WRGRP = c_CP_WRGRP +WROTHGRP = c_CP_WROTHGRP +WROTHUSR = c_CP_WROTHUSR +PROBLEMS = c_CP_PROBLEMS +SYMLINK = c_CP_SYMLINK +REPORT = c_CP_REPORT +STICKYOK = c_CP_STICKYOK + +cdef void cp_report(unsigned what, int verb, + char *path, char *msg, void *arg): + cdef object cp + cp = arg + if msg is NULL: + msg = '' + cp.report(what, verb, path, msg) + +cdef class CheckPath: + cdef checkpath cp + def __init__(me): + me.cp.cp_uid = 0 + me.cp.cp_gids = 0 + me.cp.cp_verbose = 1 + me.cp.cp_what = c_CP_PROBLEMS + me.cp.cp_report = cp_report + me.cp.cp_arg = me + c_checkpath_setids(&me.cp) + def setids(me): + c_checkpath_setids(&me.cp) + property uid: + def __get__(me): + return me.cp.cp_uid + def __set__(me, val): + me.cp.cp_uid = val + property gids: + def __get__(me): + g = [] + for i from 0 <= i < me.cp.cp_gids: + g[i] = me.cp.cp_gid[i] + return g + def __set__(me, val): + if len(val) >= NGROUPS_MAX + 1: + raise TypeError, 'too many groups' + for i from 0 <= i < len(val): + me.cp.cp_gid[i] = val[i] + me.cp.cp_gids = len(val) + property verbose: + def __get__(me): + return me.cp.cp_verbose + def __set__(me, val): + me.cp.cp_verbose = val + property what: + def __get__(me): + return me.cp.cp_what + def __set__(me, val): + me.cp.cp_what = val + def check(me, path): + return c_checkpath(path, &me.cp) + def report(me, what, verb, path, msg): + pass +