📄 htaaprot.c
字号:
prot->template = NULL; prot->filename = NULL; prot->uid_name = NULL; prot->gid_name = NULL; prot->valid_schemes = HTList_new(); prot->mask_group= NULL; /* Masking disabled by defaults */ prot->values = HTAssocList_new(); if (prot_filename && NULL != (fp = fopen(prot_filename, TXT_R))) { HTAA_parseProtFile(prot, fp); fclose(fp); if ((cache_item = typecalloc(HTAAProtCache)) == 0) outofmem(__FILE__, "HTAAProt_new"); cache_item->prot = prot; cache_item->prot_filename = NULL; StrAllocCopy(cache_item->prot_filename, prot_filename); HTList_addObject(prot_cache, (void*)cache_item); } else { CTRACE((tfp, "HTAAProt_new: %s `%s'\n", "Unable to open protection setup file", NONNULL(prot_filename))); } } if (cur_docname) StrAllocCopy(prot->filename, cur_docname); HTAA_setIds(prot, ids); return prot;}/* PUBLIC HTAA_setDefaultProtection()** SET THE DEFAULT PROTECTION MODE** (called by rule system when a** "defprot" rule is matched)** ON ENTRY:** cur_docname is the current result of rule translations.** prot_filename is the protection setup file (second argument** for "defprot" rule, optional)** ids contains user and group names separated by** a dot, corresponding to the uid** gid under which the server should run,** default is "nobody.nogroup" (third argument** for "defprot" rule, optional; can be given** only if protection setup file is also given).**** ON EXIT:** returns nothing.** Sets the module-wide variable default_prot.*/PUBLIC void HTAA_setDefaultProtection ARGS3(CONST char *, cur_docname, CONST char *, prot_filename, CONST char *, ids){ default_prot = NULL; /* Not free()'d because this is in cache */ if (prot_filename) { default_prot = HTAAProt_new(cur_docname, prot_filename, ids); } else { CTRACE((tfp, "%s %s\n", "HTAA_setDefaultProtection: ERROR: Protection file", "not specified (obligatory for DefProt rule)!!\n")); }}/* PUBLIC HTAA_setCurrentProtection()** SET THE CURRENT PROTECTION MODE** (called by rule system when a** "protect" rule is matched)** ON ENTRY:** cur_docname is the current result of rule translations.** prot_filename is the protection setup file (second argument** for "protect" rule, optional)** ids contains user and group names separated by** a dot, corresponding to the uid** gid under which the server should run,** default is "nobody.nogroup" (third argument** for "protect" rule, optional; can be given** only if protection setup file is also given).**** ON EXIT:** returns nothing.** Sets the module-wide variable current_prot.*/PUBLIC void HTAA_setCurrentProtection ARGS3(CONST char *, cur_docname, CONST char *, prot_filename, CONST char *, ids){ current_prot = NULL; /* Not free()'d because this is in cache */ if (prot_filename) { current_prot = HTAAProt_new(cur_docname, prot_filename, ids); } else { if (default_prot) { current_prot = default_prot; HTAA_setIds(current_prot, ids); CTRACE((tfp, "%s %s %s\n", "HTAA_setCurrentProtection: Protection file", "not specified for Protect rule", "-- using default protection")); } else { CTRACE((tfp, "%s %s %s\n", "HTAA_setCurrentProtection: ERROR: Protection", "file not specified for Protect rule, and", "default protection is not set!!")); } }}/* PUBLIC HTAA_getCurrentProtection()** GET CURRENT PROTECTION SETUP STRUCTURE** (this is set up by callbacks made from** the rule system when matching "protect"** (and "defprot") rules)** ON ENTRY:** HTTranslate() must have been called before calling** this function.**** ON EXIT:** returns a HTAAProt structure representing the** protection setup of the HTTranslate()'d file.** This must not be free()'d.*/PUBLIC HTAAProt *HTAA_getCurrentProtection NOARGS{ return current_prot;}/* PUBLIC HTAA_getDefaultProtection()** GET DEFAULT PROTECTION SETUP STRUCTURE** AND SET IT TO CURRENT PROTECTION** (this is set up by callbacks made from** the rule system when matching "defprot"** rules)** ON ENTRY:** HTTranslate() must have been called before calling** this function.**** ON EXIT:** returns a HTAAProt structure representing the** default protection setup of the HTTranslate()'d** file (if HTAA_getCurrentProtection() returned** NULL, i.e., if there is no "protect" rule** but ACL exists, and we need to know default** protection settings).** This must not be free()'d.** IMPORTANT:** As a side-effect this tells the protection system that** the file is in fact protected and sets the current** protection mode to default.*/PUBLIC HTAAProt *HTAA_getDefaultProtection NOARGS{ if (!current_prot) { current_prot = default_prot; default_prot = NULL; } return current_prot;}/* SERVER INTERNAL HTAA_clearProtections()** CLEAR DOCUMENT PROTECTION MODE** (ALSO DEFAULT PROTECTION)** (called by the rule system)** ON ENTRY:** No arguments.**** ON EXIT:** returns nothing.** Frees the memory used by protection information.*/PUBLIC void HTAA_clearProtections NOARGS{ current_prot = NULL; /* These are not freed because */ default_prot = NULL; /* they are actually in cache. */}typedef struct { char *name; int user; } USER_DATA;#ifndef NOUSERSPRIVATE HTList *known_grp = NULL;PRIVATE HTList *known_pwd = NULL;PRIVATE BOOL uidgid_cache_inited = NO;#endif#ifdef LY_FIND_LEAKSPRIVATE void clear_uidgid_cache NOARGS{#ifndef NOUSERS USER_DATA *data; if (known_grp) { while ((data = HTList_removeLastObject(known_grp)) != NULL) { FREE(data->name); FREE(data); } FREE(known_grp); } if (known_pwd) { while ((data = HTList_removeLastObject(known_pwd)) != NULL) { FREE(data->name); FREE(data); } FREE(known_pwd); }#endif}#endif /* LY_FIND_LEAKS */#ifndef NOUSERSPRIVATE void save_gid_info ARGS2(char *, name, int, user){ USER_DATA *data = typecalloc(USER_DATA); if (!data) return; if (!known_grp) { known_grp = HTList_new(); if (!uidgid_cache_inited) {#ifdef LY_FIND_LEAKS atexit(clear_uidgid_cache);#endif uidgid_cache_inited = YES; } } StrAllocCopy(data->name, name); data->user = user; HTList_addObject (known_grp, data);}#endif /* NOUSERS */#ifndef NOUSERSPRIVATE void save_uid_info ARGS2(char *, name, int, user){ USER_DATA *data = typecalloc(USER_DATA); if (!data) return; if (!known_pwd) { known_pwd = HTList_new(); if (!uidgid_cache_inited) {#ifdef LY_FIND_LEAKS atexit(clear_uidgid_cache);#endif uidgid_cache_inited = YES; } } StrAllocCopy(data->name, name); data->user = user; HTList_addObject (known_pwd, data);}#endif /* !NOUSERS *//* PUBLIC HTAA_UidToName** GET THE USER NAME** ON ENTRY:** The user-id**** ON EXIT:** returns the user name, or an empty string if not found.*/PUBLIC char * HTAA_UidToName ARGS1(int, uid){#ifndef NOUSERS struct passwd *pw; HTList *me = known_pwd; while (HTList_nextObject(me)) { USER_DATA *data = (USER_DATA *)(me->object); if (uid == data->user) return data->name; } if ((pw = getpwuid(uid)) != 0 && pw->pw_name != 0) { CTRACE((tfp, "%s(%d) returned (%s:%d:...)\n", "HTAA_UidToName: getpwuid", uid, pw->pw_name, (int) pw->pw_uid)); save_uid_info(pw->pw_name, (int) pw->pw_uid); return pw->pw_name; }#endif return "";}/* PUBLIC HTAA_NameToUid** GET THE USER ID** ON ENTRY:** The user-name**** ON EXIT:** returns the user id, or NONESUCH if not found.*/PUBLIC int HTAA_NameToUid ARGS1(char *, name){#ifndef NOUSERS struct passwd *pw; HTList *me = known_pwd; while (HTList_nextObject(me)) { USER_DATA *data = (USER_DATA *)(me->object); if (!strcmp(name, data->name)) return data->user; } if ((pw = getpwnam(name)) != 0) { CTRACE((tfp, "%s(%s) returned (%s:%d:...)\n", "HTAA_NameToUid: getpwnam", name, pw->pw_name, (int) pw->pw_uid)); save_uid_info(pw->pw_name, (int) pw->pw_uid); return (int) pw->pw_uid; }#endif return NONESUCH;}/* PUBLIC HTAA_GidToName** GET THE GROUP NAME** ON ENTRY:** The group-id**** ON EXIT:** returns the group name, or an empty string if not found.*/PUBLIC char * HTAA_GidToName ARGS1(int, gid){#ifndef NOUSERS struct group *gr; HTList *me = known_grp; while (HTList_nextObject(me)) { USER_DATA *data = (USER_DATA *)(me->object); if (gid == data->user) return data->name; } if ((gr = getgrgid(gid)) != 0 && gr->gr_name != 0) { CTRACE((tfp, "%s(%d) returned (%s:%d:...)\n", "HTAA_GidToName: getgrgid", gid, gr->gr_name, (int) gr->gr_gid)); save_gid_info(gr->gr_name, (int) gr->gr_gid); return gr->gr_name; }#endif return "";}/* PUBLIC HTAA_NameToGid** GET THE GROUP ID** ON ENTRY:** The group-name**** ON EXIT:** returns the group id, or NONESUCH if not found.*/PUBLIC int HTAA_NameToGid ARGS1(char *, name){#ifndef NOUSERS struct group *gr; HTList *me = known_grp; while (HTList_nextObject(me)) { USER_DATA *data = (USER_DATA *)(me->object); if (!strcmp(name, data->name)) return data->user; } if ((gr = getgrnam(name)) != 0) { CTRACE((tfp, "%s(%s) returned (%s:%d:...)\n", "HTAA_NameToGid: getgrnam", name, gr->gr_name, (int) gr->gr_gid)); save_gid_info(gr->gr_name, (int) gr->gr_gid); return (int) gr->gr_gid; }#endif return NONESUCH;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -