/*! * Try to find an old session and pass socket * @returns -1 on error, 0 if no matching session was found, 1 if session was found and socket passed */ int server_child_transfer_session(server_child *children, int forkid, pid_t pid, uid_t uid, int afp_socket, uint16_t DSI_requestID) { EC_INIT; server_child_fork *fork; struct server_child_data *child; fork = (server_child_fork *) children->fork + forkid; if ((child = resolve_child(fork->table, pid)) == NULL) { LOG(log_note, logtype_default, "Reconnect: no child[%u]", pid); if (kill(pid, 0) == 0) { LOG(log_note, logtype_default, "Reconnect: terminating old session[%u]", pid); kill(pid, SIGTERM); sleep(2); if (kill(pid, 0) == 0) { LOG(log_error, logtype_default, "Reconnect: killing old session[%u]", pid); kill(pid, SIGKILL); sleep(2); } } return 0; } if (!child->valid) { /* hmm, client 'guess' the pid, rogue? */ LOG(log_error, logtype_default, "Reconnect: invalidated child[%u]", pid); return 0; } else if (child->uid != uid) { LOG(log_error, logtype_default, "Reconnect: child[%u] not the same user", pid); return 0; } LOG(log_note, logtype_default, "Reconnect: transfering session to child[%u]", pid); if (writet(child->ipc_fd, &DSI_requestID, 2, 0, 2) != 2) { LOG(log_error, logtype_default, "Reconnect: error sending DSI id to child[%u]", pid); EC_STATUS(-1); goto EC_CLEANUP; } EC_ZERO_LOG(send_fd(child->ipc_fd, afp_socket)); EC_ZERO_LOG(kill(pid, SIGURG)); EC_STATUS(1); EC_CLEANUP: EC_EXIT; }
static int ad_conv_v22ea(const char *path, const struct stat *sp, const struct vol *vol) { EC_INIT; const char *adpath; int adflags = S_ISDIR(sp->st_mode) ? ADFLAGS_DIR : 0; become_root(); EC_ZERO( ad_conv_v22ea_hf(path, sp, vol) ); EC_ZERO( ad_conv_v22ea_rf(path, sp, vol) ); EC_NULL( adpath = ad_path(path, adflags) ); LOG(log_debug, logtype_default,"ad_conv_v22ea_hf(\"%s\"): deleting adouble:v2 file: \"%s\"", path, fullpathname(adpath)); unlink(adpath); EC_CLEANUP: if (errno == ENOENT) EC_STATUS(0); unbecome_root(); EC_EXIT; }
/*! * Remove any ACL_USER, ACL_GROUP, ACL_MASK or ACL_TYPE_DEFAULT ACEs from an object * * @param name (r) filesystem object name * * @returns AFP error code, AFP_OK (= 0) on success, AFPERR_MISC on error */ int remove_acl_vfs(const char *name) { EC_INIT; struct stat st; acl_t acl = NULL; acl_entry_t e; acl_tag_t tag; int entry_id = ACL_FIRST_ENTRY; /* Remove default ACL if it's a dir */ EC_ZERO_ERR(stat(name, &st), AFPERR_MISC); if (S_ISDIR(st.st_mode)) { EC_NULL_LOG_ERR(acl = acl_init(0), AFPERR_MISC); EC_ZERO_LOG_ERR(acl_set_file(name, ACL_TYPE_DEFAULT, acl), AFPERR_MISC); EC_ZERO_LOG_ERR(acl_free(acl), AFPERR_MISC); acl = NULL; } /* Now get ACL and remove ACL_MASK, ACL_USER or ACL_GROUP entries, then re-set * the ACL again. acl_calc_mask() must not be called because there is no need * for an ACL_MASK entry in a basic ACL. */ EC_NULL_LOG_ERR(acl = acl_get_file(name, ACL_TYPE_ACCESS), AFPERR_MISC); for ( ; acl_get_entry(acl, entry_id, &e) == 1; entry_id = ACL_NEXT_ENTRY) { EC_ZERO_LOG_ERR(acl_get_tag_type(e, &tag), AFPERR_MISC); if (tag == ACL_USER || tag == ACL_GROUP || tag == ACL_MASK) EC_ZERO_LOG_ERR(acl_delete_entry(acl, e), AFPERR_MISC); } EC_ZERO_LOG_ERR(acl_valid(acl), AFPERR_MISC); EC_ZERO_LOG_ERR(acl_set_file(name, ACL_TYPE_ACCESS, acl), AFPERR_MISC); EC_CLEANUP: if (errno == ENOENT) EC_STATUS(0); if (acl) acl_free(acl); EC_EXIT; }