diff options
Diffstat (limited to 'lib/libaccess/acltools.cpp')
-rw-r--r-- | lib/libaccess/acltools.cpp | 760 |
1 files changed, 0 insertions, 760 deletions
diff --git a/lib/libaccess/acltools.cpp b/lib/libaccess/acltools.cpp index c93bbc6d..32ab5d74 100644 --- a/lib/libaccess/acltools.cpp +++ b/lib/libaccess/acltools.cpp @@ -2273,694 +2273,6 @@ acl_strstr(char * block, char * aclname) } - -/* - * local function: find the acl string from mapfile and return its acl structure - */ -int -get_acl_from_file(char * filename, char * aclname, ACLListHandle_t ** acllist_pp) -{ - int rv = 0; - char * pattern=NULL; - char header[] = "version 3.0;\n"; - int headerlen = strlen(header); - long filesize; - FILE * file; - char * mirror=NULL, * text=NULL, *nextname=NULL; - char * block=NULL, * aclhead=NULL, * aclend=NULL; - - *acllist_pp = NULL; - - // build the acl name pattern, which should be acl "..." - // the ".." is built by acl_to_str_create - - if (aclname==NULL) { - rv = ACLERRUNDEF; - goto get_cleanup; - } - - if ((pattern=(char *)PERM_MALLOC(strlen(aclname) + 1))==NULL) { - rv = ACLERRNOMEM; - goto get_cleanup; - } - else { - sprintf(pattern,"%s", aclname); - str_tolower(pattern); - } - - /* get the acl text from the mapfile */ - if ((rv=open_file_buf(&file, filename, "rb", &block, &filesize))<0) - goto get_cleanup; - - if ((mirror = (char *) PERM_MALLOC(filesize+1))==NULL) { - rv = ACLERRNOMEM; - goto get_cleanup; - } - - memcpy(mirror, block, filesize); - mirror[filesize]=0; - str_tolower(mirror); - - if ((aclhead = acl_strstr(mirror, pattern))!=NULL) { - // use mirror to search, then transfer to work on block; - aclhead = block + (aclhead - mirror); - acl_get_first_name(aclhead+3, &nextname, &aclend); - aclend = acl_strstr(aclhead+3, nextname); - if (aclend == NULL) { - // this is the last acl in the file - aclend = &aclhead[strlen(aclhead)]; - } - - int len = aclend - aclhead; - text = (char *) PERM_MALLOC(len + headerlen + 1); - sprintf(text, "%s", header); - memcpy(&text[headerlen], aclhead, len); - text[headerlen + len] = 0; - - if ((*acllist_pp=ACL_ParseString(NULL, text))==NULL) { - rv = ACLERRPARSE; - } - } - -get_cleanup: - if (pattern) - PERM_FREE(pattern); - if (file) - close_file_buf(file, filename, "rb", block); - if (mirror) - PERM_FREE(mirror); - if (text) - PERM_FREE(text); - if (nextname) - PERM_FREE(nextname); - return rv; -} - - -/* - * local function: delete the acl string from mapfile - */ -int -delete_acl_from_file(char * filename, char * aclname) -{ - char * pattern=NULL; - char header[] = "version 3.0;\n"; - int headerlen = strlen(header); - int rv = ACLERRUNDEF; - long filesize; - FILE * file; - char * mirror=NULL, * text=NULL, * nextname=NULL; - char * block=NULL, * aclhead=NULL, * aclend=NULL; - int remain; - - // build the acl name pattern, which should be acl "..." - // the ".." is built by acl_to_str_create - - if (aclname==NULL) { - rv = ACLERRUNDEF; - goto delete_cleanup; - } - - if ((pattern=(char *)PERM_MALLOC(strlen(aclname) + 10))==NULL) { - rv = ACLERRNOMEM; - goto delete_cleanup; - } - else { - sprintf(pattern,"%s", aclname); - str_tolower(pattern); - } - - /* file the acl text from the mapfile */ - if ((rv=open_file_buf(&file, filename, "rb", &block, &filesize))<0) - goto delete_cleanup; - - if ((mirror = (char *) PERM_MALLOC(filesize+1))==NULL) { - rv = ACLERRNOMEM; - goto delete_cleanup; - } - - memcpy(mirror, block, filesize); - mirror[filesize]=0; - str_tolower(mirror); - - if ((aclhead = acl_strstr(mirror, pattern))!=NULL) { - // use mirror to search, then transfer to work on block; - aclhead = block + (aclhead - mirror); - acl_get_first_name(aclhead+3, &nextname, &aclend); - aclend = acl_strstr(aclhead+3, nextname); - if (aclend == NULL) { - // this is the last acl in the file - aclend = &aclhead[strlen(aclhead)]; - } - - int len = aclend - aclhead; - text = (char *) PERM_MALLOC(len + headerlen + 1); - sprintf(text, "%s", header); - memcpy(&text[headerlen], aclhead, len); - text[headerlen + len] = 0; - - if (ACL_ParseString(NULL, text)==NULL) { - rv = ACLERRPARSE; - goto delete_cleanup; - } - } - - if (aclhead!=NULL) { // found the acl in the map file - - // int filesize = mpfile->Size(); - - remain = strlen(aclend); - if (memcpy(aclhead, aclend, remain)!=NULL) - rv = 0; - else - rv = ACLERRIO; - - aclhead[remain]=0; - - block = (char *) PERM_REALLOC(block, strlen(block)+1); - } - else - rv = ACLERRUNDEF; - -delete_cleanup: - if (pattern) - PERM_FREE(pattern); - if (text) - PERM_FREE(text); - if (mirror) - PERM_FREE(mirror); - if (nextname) - PERM_FREE(nextname); - if (file) - close_file_buf(file, filename, "wb", block); - return rv; -} - -/* - * local function: append the acl string to file - */ -int -append_acl_to_file(char * filename, char * aclname, char * acltext) -{ - int rv; - /* acltext has been parsed to verify syntax up to this point */ - char * pattern=NULL; - char * start=NULL; - char * block; - long filesize; - FILE * file; - long len; - - if ((pattern=(char *)PERM_MALLOC(strlen(aclname) + 10))==NULL) { - rv = ACLERRNOMEM; - goto append_cleanup; - } - else { - sprintf(pattern,"%s", aclname); - } - - if ((rv=open_file_buf(&file, filename, "rb", &block, &filesize))<0) - goto append_cleanup; - - // find the begining of acl, skip the version part - - len = strlen(block); - start = acl_strstr(acltext, pattern); - if ((block=(char *)PERM_REALLOC(block, len+strlen(start)+1))==NULL) { - rv = ACLERRNOMEM; - goto append_cleanup; - } - strcat(block, start); - -append_cleanup: - if (pattern) - PERM_FREE(pattern); - if (file) - close_file_buf(file, filename, "wb", block); - - return rv; -} - - - -/* - * local function: rename the acl name in the file - */ -int -rename_acl_in_file(char * filename, char * aclname, char * newname) -{ - char * pattern=NULL; - char header[] = "version 3.0;\n"; - int headerlen = strlen(header); - int rv = 0; - long filesize; - FILE * file; - int remain; - long len; - char * text=NULL, * mirror=NULL, * nextname=NULL; - char * block=NULL, * aclhead=NULL, * aclend=NULL; - char * cut=NULL; - acl_string_t str_t = {NULL,0,0}; - - // build the acl name pattern, which should be acl "..." - // the ".." is built by acl_to_str_create - - if (aclname==NULL || newname==NULL) { - rv = ACLERRUNDEF; - goto rename_cleanup; - } - - if ((pattern=(char *)PERM_MALLOC(strlen(aclname) + 10))==NULL) { - rv = ACLERRNOMEM; - goto rename_cleanup; - } - else { - sprintf(pattern,"%s", aclname); - str_tolower(pattern); - } - - // file the acl text from the mapfile - if ((rv=open_file_buf(&file, filename, "rb", &block, &filesize))<0) - goto rename_cleanup; - - if ((mirror = (char *) PERM_MALLOC(filesize+1))==NULL) { - rv = ACLERRNOMEM; - goto rename_cleanup; - } - - memcpy(mirror, block, filesize); - mirror[filesize]=0; - str_tolower(mirror); - - if ((aclhead = acl_strstr(mirror, pattern))!=NULL) { - // use mirror to search, then transfer to work on block; - aclhead = block + (aclhead - mirror); - acl_get_first_name(aclhead+3, &nextname, &aclend); - aclend = acl_strstr(aclhead+3, nextname); - if (aclend == NULL) { - // this is the last acl in the file - aclend = &aclhead[strlen(aclhead)]; - } - - len = aclend - aclhead; - text = (char *) PERM_MALLOC(len + headerlen + 1); - sprintf(text, "%s", header); - memcpy(&text[headerlen], aclhead, len); - text[headerlen + len] = 0; - - if (ACL_ParseString(NULL, text)==NULL) { - rv = ACLERRPARSE; - goto rename_cleanup; - } - } - - if (aclhead!=NULL) { // found the acl in the map file - - remain = strlen(aclend); - // delete the acltext from where it is - if (memcpy(aclhead, aclend, remain)!=NULL) - rv = 0; - else - rv = ACLERRUNDEF; - - aclhead[remain] = 0; - len = strlen(block); - - /* establish the renamed the acl */ - acl_to_str_append(&str_t, "acl \""); - acl_to_str_append(&str_t, newname); - acl_to_str_append(&str_t, "\";"); - /* skip acl "..."; the semicollon in the last counts for the +1 - add the rest acl text to str_t */ - cut = strchr(text, ';'); // skip version ...; - cut = strchr(cut+1, ';') + 1; // skip acl ...; - if (cut==NULL) { - rv = ACLERRUNDEF; - goto rename_cleanup; - } - acl_to_str_append(&str_t, cut); - // acl_to_str_append(&str_t, "\n"); - - if ((block=(char *) PERM_REALLOC(block, len + strlen(str_t.str) + 1))==NULL) { - rv = ACLERRNOMEM; - goto rename_cleanup; - } - // strcat(block, "\n"); - strcat(block, str_t.str); - } - else - rv = ACLERRUNDEF; - -rename_cleanup: - if (pattern) - PERM_FREE(pattern); - if (text) - PERM_FREE(text); - if (mirror) - PERM_FREE(mirror); - if (nextname) - PERM_FREE(nextname); - if (str_t.str) - PERM_FREE(str_t.str); - if (file) - close_file_buf(file, filename, "wb", block); - return rv; -} - - -/* - * Retrieves the definition of a named ACL - * - * Input: - * errp a error stack - * filename Target ACL file - * acl_name Name of the target ACL - * acl_text a dynmaically allocated text (result) - * Output: - * errp error stack is set on error - * Returns: - * 0 success - * <0 failure - */ -NSAPI_PUBLIC int -ACL_FileGetAcl(NSErr_t *errp, - char *filename, - char *acl_name, - // ACLListHandle_t **acllist_p, - char ** acltext, - int flags) -{ - int rv; - ACLListHandle_t * acllist_p; - - if (acl_parse_crit == NULL) - acl_parse_crit = crit_init(); - - crit_enter( acl_parse_crit ); - - rv = get_acl_from_file(filename, acl_name, &acllist_p); - - if (acllist_p == NULL) { - *acltext = NULL; - goto get_cleanup; - } - - /* - if ((rv=ACL_Decompose(errp, acltext, acllist_p))<0) { - *acltext = NULL; - goto get_cleanup; - } - */ - if ((rv=ACL_WriteString(errp, acltext, acllist_p))<0) { - *acltext = NULL; - goto get_cleanup; - } - - -get_cleanup: - - crit_exit( acl_parse_crit ); - - return rv; -} - - - -/* - * Delete a named ACL from an ACL file - * - * Input: - * errp a error stack - * filename Target ACL file - * acl_name Name of the target ACL - * Output: - * errp error stack is set on error - * Returns: - * 0 success - * < 0 failure - */ - -NSAPI_PUBLIC int -ACL_FileDeleteAcl(NSErr_t *errp, - char *filename, - char *acl_name, - int flags) -{ - int rv = 0; - - if ( acl_parse_crit == NULL ) - acl_parse_crit = crit_init(); - - crit_enter( acl_parse_crit ); - - rv = delete_acl_from_file(filename, acl_name); - - crit_exit( acl_parse_crit ); - return(rv); -} - - -/* - * Sets the definition of an ACL in an ACL file - * - * Input: - * errp a error stack - * filename Target ACL file - * acl_name Name of the target ACL - * acl_text a string that defines the new ACL - * Output: - * errp error stack is set on error - * Returns: - * 0 success - * < 0 failure - */ - -NSAPI_PUBLIC int -ACL_FileSetAcl(NSErr_t *errp, - char *filename, - char *acl_text, - int flags) -{ - int rv = 0; - ACLListHandle_t *new_acl_list = NULL; - char **acl_name_list = NULL; - - if ( acl_parse_crit == NULL ) - acl_parse_crit = crit_init(); - - crit_enter( acl_parse_crit ); - - // get the acl name. - new_acl_list = ACL_ParseString(errp, acl_text); - if ( new_acl_list == NULL ) { - rv = ACLERRPARSE; - goto set_cleanup; - } - - if ( ACL_ListGetNameList(errp, new_acl_list, &acl_name_list) < 0 ) { - rv = ACLERRNOMEM; - goto set_cleanup; - } - - - delete_acl_from_file(filename, acl_name_list[0]); - rv = append_acl_to_file(filename, acl_name_list[0], acl_text); - -set_cleanup: - - crit_exit( acl_parse_crit ); - if (new_acl_list) - ACL_ListDestroy(errp, new_acl_list); - if (acl_name_list) - free(acl_name_list); - return(rv); -} - - -/* - * Rename a named ACL in ACL text file - * - * Input: - * errp a error stack - * filename Target ACL file - * acl_name Name of the target ACL - * new_acl_name New ACL name - * Output: - * errp error stack is set on error - * Returns: - * 0 success - * < 0 failure - */ - -NSAPI_PUBLIC int -ACL_FileRenameAcl(NSErr_t *errp, - char *filename, - char *aclname, - char *newname, - int flags) -{ - int rv = 0; - - if ( acl_parse_crit == NULL ) - acl_parse_crit = crit_init(); - - crit_enter( acl_parse_crit ); - - rv = rename_acl_in_file(filename, aclname, newname); - - crit_exit( acl_parse_crit ); - return(rv); - -} - - -// -// Merge a list of ACLs into one ACL -// -// Input: -// filename the target acl file -// acl_list ACLs to merge -// new_acl_name resultant ACL -// flags currently ignored -// Returns: -// 0 success -// < 0 failure -// - -NSAPI_PUBLIC int -ACL_FileMergeAcl(NSErr_t *errp, - char *filename, - char **acl_name_list, - char *new_acl_name, - int flags) -{ - ACLListHandle_t *new_acl_list = NULL; - ACLListHandle_t *tmp_acl_list = NULL; - int ii; - int rv; - ACLHandle_t *tmp_acl; - ACLHandle_t *new_acl; - ACLExprHandle_t *expr; - - - tmp_acl_list = ACL_ParseFile(errp, filename); - if ( tmp_acl_list == NULL ) { - rv = ACLERRPARSE; - goto cleanup; - } - - new_acl_list = ACL_ParseFile(errp, filename); - if ( new_acl_list == NULL ) { - rv = ACLERRPARSE; - goto cleanup; - } - - // first get rid of all the ACLs that will be merged - - for (ii = 0; acl_name_list[ii]; ii++) { - rv = ACL_ListAclDelete(errp, new_acl_list, acl_name_list[ii], flags); - if ( rv < 0 ) - goto cleanup; - } - - // now create ACL to house the merged result - new_acl = ACL_AclNew(errp, new_acl_name); - if ( new_acl == NULL ) { - rv = ACLERRNOMEM; - goto cleanup; - } - - rv = ACL_ListAppend(errp, new_acl_list, new_acl, flags); - if ( rv < 0 ) - goto cleanup; - - for (ii = 0; acl_name_list[ii]; ii++) { - tmp_acl = ACL_ListFind(errp, tmp_acl_list, acl_name_list[ii], flags); - if ( tmp_acl == NULL ) { - rv = ACLERRUNDEF; - goto cleanup; - } - for (expr = tmp_acl->expr_list_head; expr; expr = expr->expr_next) { - // This call can't really fail unless we pass it a NULL - // or some memory is corrupt. - rv = ACL_ExprAppend(errp, new_acl, expr); - if ( rv < 0 ) - goto cleanup; - tmp_acl->expr_list_head = expr->expr_next; - tmp_acl->expr_count--; - } - - // Last bit of clean up so the destroy routine isn't confused. - - tmp_acl->expr_list_tail = NULL; - tmp_acl->expr_count = 0; - } - - rv = ACL_WriteFile(errp, filename, new_acl_list); - -cleanup: - if ( new_acl_list ) - ACL_ListDestroy(errp, new_acl_list); - if ( tmp_acl_list ) - ACL_ListDestroy(errp, tmp_acl_list); - return(rv); -} - -// -// Merge a list of ACL files into one ACL file -// -// Input: -// filename the target acl file -// file_list ACL files to merge -// flags currently ignored -// Returns: -// 0 success -// < 0 failure -// - -NSAPI_PUBLIC int -ACL_FileMergeFile(NSErr_t *errp, - char *filename, - char **file_list, - int flags) -{ - ACLListHandle_t *new_acl_list = NULL; - ACLListHandle_t *tmp_acl_list = NULL; - int ii; - int rv; - - // we don't care if they have nothing to do - - if ( filename == NULL || file_list == NULL ) - return(0); - - new_acl_list = ACL_ListNew(errp); - if (new_acl_list == NULL) - return(ACLERRNOMEM); - - for (ii = 0; file_list[ii]; ii++) { - tmp_acl_list = ACL_ParseFile(errp, file_list[ii]); - if (tmp_acl_list == NULL) { - rv = ACLERRPARSE; - goto cleanup; - } - rv = ACL_ListConcat(errp, new_acl_list, tmp_acl_list, flags); - if ( rv < 0 ) - goto cleanup; - ACL_ListDestroy(errp, tmp_acl_list); - tmp_acl_list = NULL; - } - - rv = ACL_WriteFile(errp, filename, new_acl_list); - -cleanup: - if ( new_acl_list ) - ACL_ListDestroy(errp, new_acl_list); - if ( tmp_acl_list ) - ACL_ListDestroy(errp, tmp_acl_list); - return(rv); -} - /* * Destroy a NameList * @@ -3048,78 +2360,6 @@ ACL_ListGetNameList(NSErr_t *errp, ACLListHandle_t *acl_list, char ***name_list) } /* - * Gets a name list of consisting of all ACL names from the input aclfile - * - * Input: - * filename acl file - * name_list pointer to a list of string pointers - * Returns: - * 0 success - * < 0 failure - */ - -NSAPI_PUBLIC int -ACL_FileGetNameList(NSErr_t *errp, char * filename, char ***name_list) -{ - - const int block_size = 50; - int rv, list_size, list_index; - char ** local_list = NULL; - char * block ; - char * name; - char * next; - long filesize; - FILE * file; - char * head; - - if ((rv=open_file_buf(&file, filename, "rb", &block, &filesize))<0) - goto list_cleanup; - - list_size = block_size; - local_list = (char **) PERM_MALLOC(sizeof(char *) * list_size); - if ( local_list == NULL ) { - rv = ACLERRNOMEM; - goto list_cleanup; - } - list_index = 0; - local_list[list_index] = NULL; - - head = block; - while ((acl_get_first_name(head, &name, &next))) { - - if (list_index+2 > list_size) { - list_size += block_size; - char ** tmp_list = (char **) PERM_REALLOC(local_list, sizeof(char *) * list_size); - if ( tmp_list == NULL ) { - rv = ACLERRNOMEM; - goto list_cleanup; - } - local_list = tmp_list; - } - // local_list[list_index] = PERM_STRDUP(name); - local_list[list_index] = name; - if ( local_list[list_index] == NULL ) { - rv = ACLERRNOMEM; - goto list_cleanup; - } - list_index++; - local_list[list_index] = NULL; - head = next; - } - - rv = 0; - *name_list = local_list; - -list_cleanup: - if (local_list && rv<0) - ACL_NameListDestroy(errp, local_list); - if (file) - close_file_buf(file, filename, "rb", block); - - return rv; -} - -/* * Changes method to method plus DBTYPE, and registers * databases. * |