/* trustee.c - shared helpers for GRANT/REVOKE/REMOVE style tools */ #include "net.h" #include "trustee.h" #include #include #ifndef S_IFDIR #define S_IFDIR 0040000 #endif int trustee_same(char *a, char *b) { return(tool_strsame(a, b)); } int trustee_is_help(char *s) { return(tool_is_help_arg(s)); } int trustee_is_option(char *s) { return(tool_is_option(s)); } int trustee_current_dhandle(uint8 *connid, uint8 *dhandle) { return(tool_current_dhandle(connid, dhandle)); } void trustee_upcopy(char *dst, char *src, int max) { tool_upcopy(dst, src, max); } void trustee_basename(char *dst, char *src, int max) { tool_basename(dst, src, max); } void trustee_header_path(char *out, char *path, int max) { tool_header_path(out, path, max); } void trustee_join_path(char *out, char *base, char *name, int max) { tool_join_path(out, base, name, max); } int trustee_is_dot_dir(char *name) { return(tool_is_dot_dir(name)); } int trustee_path_has_wildcards(char *path) { return(tool_has_wildcards(path)); } void trustee_parent_pattern(char *dir, char *pattern, char *path, int maxdir, int maxpat) { tool_parent_pattern(dir, pattern, path, maxdir, maxpat); } int trustee_is_subdirs_option(char *s) { if (!s) return(0); return(trustee_same(s, "/SUBDIRS") || trustee_same(s, "-SUBDIRS") || trustee_same(s, "/SUBDIRECTORIES") || trustee_same(s, "-SUBDIRECTORIES") || trustee_same(s, "/S") || trustee_same(s, "-S")); } int trustee_is_files_option(char *s) { if (!s) return(0); return(trustee_same(s, "/FILES") || trustee_same(s, "-FILES") || trustee_same(s, "/F") || trustee_same(s, "-F")); } int trustee_parse_right_word(char *s, uint16 *rights) { if (trustee_same(s, "ALL")) { *rights = TRUSTEE_RIGHT_ALL_386; return(0); } if (trustee_same(s, "N") || trustee_same(s, "NONE")) { *rights = TRUSTEE_RIGHT_ALL_386; return(0); } if (trustee_same(s, "S") || trustee_same(s, "SUPERVISOR")) { *rights |= TRUSTEE_RIGHT_SUPER; return(0); } if (trustee_same(s, "R") || trustee_same(s, "READ")) { *rights |= TRUSTEE_RIGHT_READ; return(0); } if (trustee_same(s, "W") || trustee_same(s, "WRITE")) { *rights |= TRUSTEE_RIGHT_WRITE; return(0); } if (trustee_same(s, "C") || trustee_same(s, "CREATE")) { *rights |= TRUSTEE_RIGHT_CREATE; return(0); } if (trustee_same(s, "E") || trustee_same(s, "ERASE") || trustee_same(s, "D") || trustee_same(s, "DELETE")) { *rights |= TRUSTEE_RIGHT_DELETE; return(0); } if (trustee_same(s, "M") || trustee_same(s, "MODIFY")) { *rights |= TRUSTEE_RIGHT_MODIFY; return(0); } if (trustee_same(s, "F") || trustee_same(s, "FILESCAN") || trustee_same(s, "FILE") || trustee_same(s, "SCAN")) { *rights |= TRUSTEE_RIGHT_SEARCH; return(0); } if (trustee_same(s, "A") || trustee_same(s, "ACCESS") || trustee_same(s, "CONTROL") || trustee_same(s, "ACCESSCONTROL")) { *rights |= TRUSTEE_RIGHT_OWNER; return(0); } return(-1); } void trustee_rights_bracket(uint16 rights, char *out) { out[0] = (rights & TRUSTEE_RIGHT_SUPER) ? 'S' : ' '; out[1] = (rights & TRUSTEE_RIGHT_READ) ? 'R' : ' '; out[2] = (rights & TRUSTEE_RIGHT_WRITE) ? 'W' : ' '; out[3] = (rights & TRUSTEE_RIGHT_CREATE) ? 'C' : ' '; out[4] = (rights & TRUSTEE_RIGHT_DELETE) ? 'E' : ' '; out[5] = (rights & TRUSTEE_RIGHT_MODIFY) ? 'M' : ' '; out[6] = (rights & TRUSTEE_RIGHT_SEARCH) ? 'F' : ' '; out[7] = (rights & TRUSTEE_RIGHT_OWNER) ? 'A' : ' '; out[8] = '\0'; } uint32 trustee_lookup_object(char *name, uint16 *objtype, int objtype_given) { uint8 namebuf[48]; uint32 object_id; strmaxcpy(namebuf, name, sizeof(namebuf) - 1); upstr(namebuf); if (objtype_given) { return(ncp_17_35(namebuf, *objtype)); } *objtype = TRUSTEE_BINDERY_USER; object_id = ncp_17_35(namebuf, TRUSTEE_BINDERY_USER); if (object_id) return(object_id); *objtype = TRUSTEE_BINDERY_GROUP; object_id = ncp_17_35(namebuf, TRUSTEE_BINDERY_GROUP); return(object_id); } int trustee_path_is_dir(char *path) { struct stat st; if (!path || !*path || trustee_same(path, ".") || trustee_same(path, ".\\") || trustee_same(path, "./")) return(1); if (stat(path, &st) == 0) { if (st.st_mode & S_IFDIR) return(1); } return(0); }