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