static bool add_delete_on_close_token(struct share_mode_data *d, uint32_t name_hash, const struct security_token *nt_tok, const struct security_unix_token *tok) { struct delete_token *tmp, *dtl; tmp = talloc_realloc(d, d->delete_tokens, struct delete_token, d->num_delete_tokens+1); if (tmp == NULL) { return false; } d->delete_tokens = tmp; dtl = &d->delete_tokens[d->num_delete_tokens]; dtl->name_hash = name_hash; dtl->delete_nt_token = dup_nt_token(d->delete_tokens, nt_tok); if (dtl->delete_nt_token == NULL) { return false; } dtl->delete_token = copy_unix_token(d->delete_tokens, tok); if (dtl->delete_token == NULL) { return false; } d->num_delete_tokens += 1; d->modified = true; return true; }
void set_delete_on_close_lck(files_struct *fsp, struct share_mode_lock *lck, bool delete_on_close, const struct security_token *nt_tok, const struct security_unix_token *tok) { struct share_mode_data *d = lck->data; int i; bool ret; if (delete_on_close) { SMB_ASSERT(nt_tok != NULL); SMB_ASSERT(tok != NULL); } else { SMB_ASSERT(nt_tok == NULL); SMB_ASSERT(tok == NULL); } for (i=0; i<d->num_delete_tokens; i++) { struct delete_token *dt = &d->delete_tokens[i]; if (dt->name_hash == fsp->name_hash) { d->modified = true; if (delete_on_close == false) { /* Delete this entry. */ TALLOC_FREE(dt->delete_nt_token); TALLOC_FREE(dt->delete_token); *dt = d->delete_tokens[ d->num_delete_tokens-1]; d->num_delete_tokens -= 1; } else { /* Replace this token with the given tok. */ TALLOC_FREE(dt->delete_nt_token); dt->delete_nt_token = dup_nt_token(dt, nt_tok); SMB_ASSERT(dt->delete_nt_token != NULL); TALLOC_FREE(dt->delete_token); dt->delete_token = copy_unix_token(dt, tok); SMB_ASSERT(dt->delete_token != NULL); } return; } } if (!delete_on_close) { /* Nothing to delete - not found. */ return; } ret = add_delete_on_close_token(lck->data, fsp->name_hash, nt_tok, tok); SMB_ASSERT(ret); }
static struct aio_open_private_data *create_private_open_data(const files_struct *fsp, int flags, mode_t mode) { struct aio_open_private_data *opd = talloc_zero(NULL, struct aio_open_private_data); const char *fname = NULL; if (!opd) { return NULL; } opd->jobid = aio_pthread_open_jobid++; opd->dir_fd = -1; opd->ret_fd = -1; opd->ret_errno = EINPROGRESS; opd->flags = flags; opd->mode = mode; opd->mid = fsp->mid; opd->in_progress = true; opd->sconn = fsp->conn->sconn; opd->initial_allocation_size = fsp->initial_allocation_size; /* Copy our current credentials. */ opd->ux_tok = copy_unix_token(opd, get_current_utok(fsp->conn)); if (opd->ux_tok == NULL) { TALLOC_FREE(opd); return NULL; } /* * Copy the parent directory name and the * relative path within it. */ if (parent_dirname(opd, fsp->fsp_name->base_name, &opd->dname, &fname) == false) { TALLOC_FREE(opd); return NULL; } opd->fname = talloc_strdup(opd, fname); if (opd->fname == NULL) { TALLOC_FREE(opd); return NULL; } #if defined(O_DIRECTORY) opd->dir_fd = open(opd->dname, O_RDONLY|O_DIRECTORY); #else opd->dir_fd = open(opd->dname, O_RDONLY); #endif if (opd->dir_fd == -1) { TALLOC_FREE(opd); return NULL; } talloc_set_destructor(opd, opd_destructor); DLIST_ADD_END(open_pd_list, opd, struct aio_open_private_data *); return opd; }