NTSTATUS create_conn_struct_cwd(TALLOC_CTX *ctx, struct tevent_context *ev, struct messaging_context *msg, connection_struct **pconn, int snum, const char *path, const struct auth_session_info *session_info, char **poldcwd) { connection_struct *conn; char *oldcwd; NTSTATUS status = create_conn_struct(ctx, ev, msg, &conn, snum, path, session_info); if (!NT_STATUS_IS_OK(status)) { return status; } /* * Windows seems to insist on doing trans2getdfsreferral() calls on * the IPC$ share as the anonymous user. If we try to chdir as that * user we will fail.... WTF ? JRA. */ oldcwd = vfs_GetWd(ctx, conn); if (oldcwd == NULL) { status = map_nt_error_from_unix(errno); DEBUG(3, ("vfs_GetWd failed: %s\n", strerror(errno))); conn_free(conn); return status; } if (vfs_ChDir(conn,conn->connectpath) != 0) { status = map_nt_error_from_unix(errno); DEBUG(3,("create_conn_struct: Can't ChDir to new conn path %s. " "Error was %s\n", conn->connectpath, strerror(errno) )); conn_free(conn); return status; } *pconn = conn; *poldcwd = oldcwd; return NT_STATUS_OK; }
static void queue_free(Queue *q) { for (List *it = q->head; it != NULL; it = list_next(it)) conn_free(it->elem); mon_free(q->mon); mem_free(q); }
int slave(context_t* ctx) { hlink_t* hardlinks = NULL; // The hardlinks we found while performing SCAN conn_t cn; // Config (void)ctx; conn_init(&cn); cn.infd = 0; cn.outfd = 1; // Main char line[1024]; ssize_t l; while((l = conn_readline(&cn, line, sizeof line))) { proto_delegator(&cn,line,&hardlinks); } // close down conn_free(&cn); // Free hardlinks hlink_t* n = NULL; hlink_t* p; for(p = hardlinks; p; p = n) { n = (hlink_t*)((node_t*)p)->next; free(p); } hardlinks = NULL; return 0; }
static struct connection *conn_create_server(struct context *ctx, struct address *addr, char *key, bool readonly) { int fd = conn_create_fd(); if (fd == -1) { LOG(ERROR, "conn_create_server: fail to create fd"); return NULL; } struct connection *server = server_create(ctx, fd); struct conn_info *info = server->info; memcpy(&info->addr, addr, sizeof(info->addr)); extern const size_t CMD_NUM; info->slow_cmd_counts = cv_calloc(CMD_NUM, sizeof(uint32_t)); if (conn_connect(server) == CORVUS_ERR) { LOG(ERROR, "conn_create_server: fail to connect %s:%d", info->addr.ip, info->addr.port); conn_free(server); conn_buf_free(server); conn_recycle(ctx, server); return NULL; } if (readonly) { server->info->readonly = true; } strncpy(info->dsn, key, ADDRESS_LEN); dict_set(&ctx->server_table, info->dsn, (void*)server); TAILQ_INSERT_TAIL(&ctx->servers, server, next); return server; }
connection_struct *make_connection_smb2(struct smbd_smb2_request *req, struct smbXsrv_tcon *tcon, int snum, struct user_struct *vuser, const char *pdev, NTSTATUS *pstatus) { struct smbd_server_connection *sconn = req->sconn; connection_struct *conn = conn_new(sconn); if (!conn) { DEBUG(0,("make_connection_smb2: Couldn't find free connection.\n")); *pstatus = NT_STATUS_INSUFFICIENT_RESOURCES; return NULL; } conn->cnum = tcon->global->tcon_wire_id; conn->tcon = tcon; *pstatus = make_connection_snum(req->xconn, conn, snum, vuser, pdev); if (!NT_STATUS_IS_OK(*pstatus)) { conn_free(conn); return NULL; } return conn; }
/* * Get a connection for the specified service and return a pointer * to a new connection_s */ connection_s *conn_new( struct service *sp ) { connection_s new_conn ; connection_s *cp ; const char *func = "conn_new" ; CLEAR( new_conn ) ; /* * The reason we first get the connection and then allocate a * 'connection_s' is because we want to always consume some input. */ if ( get_connection( sp, &new_conn ) == FAILED ) return( NULL ) ; new_conn.co_sp = sp ; SVC_HOLD( sp ) ; if ( SVC_WAITS( sp ) ) svc_suspend( sp ) ; cp = NEW_CONN() ; if ( cp == CONN_NULL ) { out_of_memory( func ) ; conn_free( &new_conn, 0 ) ; CLEAR( new_conn ) ; return( CONN_NULL ) ; } memcpy(cp, &new_conn, sizeof(connection_s)); return( cp ) ; }
connection_struct *make_connection_with_chdir(const char *service_in, DATA_BLOB password, const char *dev, uint16 vuid, NTSTATUS *status) { connection_struct *conn = NULL; conn = make_connection(service_in, password, dev, vuid, status); /* * make_connection() does not change the directory for us any more * so we have to do it as a separate step --jerry */ if ( conn && vfs_ChDir(conn,conn->connectpath) != 0 ) { DEBUG(0,("move_driver_to_download_area: Can't change " "directory to %s for [print$] (%s)\n", conn->connectpath,strerror(errno))); yield_connection(conn, lp_servicename(SNUM(conn))); conn_free(conn); *status = NT_STATUS_UNSUCCESSFUL; return NULL; } return conn; }
void conn_put(struct conn *conn) { struct conn_base *cb = conn->cb; ASSERT(conn->sd < 0); ASSERT(conn->owner == NULL); log_debug(LOG_VVERB, "put conn %p", conn); if (cb == NULL) { conn_free(conn); return; } cb->nfree_connq++; TAILQ_INSERT_HEAD(&cb->free_connq, conn, conn_tqe); if (conn->client) { cb->ncurr_cconn--; STATS_LOCK(); ncurr_cconn --; STATS_UNLOCK(); } cb->ncurr_conn--; STATS_LOCK(); ncurr_conn --; STATS_UNLOCK(); }
void conn_free(struct connection *conn) { if (conn == NULL) return; if (conn->fd != -1) { close(conn->fd); conn->fd = -1; } conn->registered = false; if (conn->ev != NULL) { conn->ev->info = NULL; conn_free(conn->ev); conn_recycle(conn->ctx, conn->ev); conn->ev = NULL; } if (conn->info == NULL) return; struct conn_info *info = conn->info; info->status = DISCONNECTED; reader_free(&info->reader); reader_init(&info->reader); EMPTY_CMD_QUEUE(&info->cmd_queue, cmd_next); EMPTY_CMD_QUEUE(&info->ready_queue, ready_next); EMPTY_CMD_QUEUE(&info->waiting_queue, waiting_next); }
static NTSTATUS fss_vfs_conn_create(TALLOC_CTX *mem_ctx, struct tevent_context *ev, struct messaging_context *msg_ctx, struct auth_session_info *session_info, int snum, struct connection_struct **conn_out) { struct connection_struct *conn = NULL; NTSTATUS status; status = create_conn_struct(mem_ctx, ev, msg_ctx, &conn, snum, lp_path(mem_ctx, snum), session_info); if (!NT_STATUS_IS_OK(status)) { DEBUG(0,("failed to create conn for vfs: %s\n", nt_errstr(status))); return status; } status = set_conn_force_user_group(conn, snum); if (!NT_STATUS_IS_OK(status)) { DEBUG(0, ("failed set force user / group\n")); goto err_free_conn; } *conn_out = conn; return NT_STATUS_OK; err_free_conn: SMB_VFS_DISCONNECT(conn); conn_free(conn); return status; }
static struct connection *conn_create_server(struct context *ctx, struct address *addr, char *key) { int fd = conn_create_fd(); if (fd == -1) { LOG(ERROR, "conn_create_server: fail to create fd"); return NULL; } struct connection *server = server_create(ctx, fd); struct conn_info *info = server->info; memcpy(&info->addr, addr, sizeof(info->addr)); if (conn_connect(server) == CORVUS_ERR) { LOG(ERROR, "conn_create_server: fail to connect %s:%d", info->addr.ip, info->addr.port); conn_free(server); conn_buf_free(server); conn_recycle(ctx, server); return NULL; } strncpy(info->dsn, key, DSN_LEN); dict_set(&ctx->server_table, info->dsn, (void*)server); TAILQ_INSERT_TAIL(&ctx->servers, server, next); return server; }
void svc_request( struct service *sp ) { connection_s *cp ; status_e ret_code; cp = conn_new( sp ) ; if ( cp == CONN_NULL ) return ; /* * Output the banner now that the connection is established. The * other banners come later. */ banner_always(sp, cp); if (SVC_NOT_GENERIC(sp)) ret_code = spec_service_handler(sp, cp); else ret_code = svc_generic_handler(sp, cp); if( (SVC_SOCKET_TYPE( sp ) == SOCK_DGRAM) && (SVC_IS_ACTIVE( sp )) ) drain( cp->co_descriptor ) ; /* Prevents looping next time */ if ( ret_code != OK ) { if ( SVC_LOGS_USERID_ON_FAILURE( sp ) ) { if( spec_service_handler( LOG_SERVICE( ps ), cp ) == FAILED ) conn_free( cp, 1 ) ; else if (!SC_WAITS( SVC_CONF( sp ) ) ) { /* The logging service will gen SIGCHLD thus freeing connection */ CONN_CLOSE(cp) ; } return; } if (!SC_WAITS( SVC_CONF( sp ) )) conn_free( cp, 1 ); else { if( (SVC_SOCKET_TYPE( sp ) == SOCK_DGRAM) && (SVC_IS_ACTIVE( sp )) ) drain( cp->co_descriptor ) ; /* Prevents looping next time */ free( cp ); } } else if ((SVC_NOT_GENERIC(sp)) || (!SC_FORKS( SVC_CONF( sp ) ) ) ) free( cp ); }
/** * Delete all connections. */ void delete_all_connections() { /* Delete connections if needed. */ conn_t *conn, *next; for (conn = get_connections(); conn != NULL; conn = next) { next = conn->next; if (conn->delete_me) conn_free(conn); } }
void close_cnum(connection_struct *conn, uint16 vuid) { file_close_conn(conn); if (!IS_IPC(conn)) { dptr_closecnum(conn); } change_to_root_user(); DEBUG(IS_IPC(conn)?3:1, ("%s (%s) closed connection to service %s\n", get_remote_machine_name(), tsocket_address_string(conn->sconn->remote_address, talloc_tos()), lp_servicename(SNUM(conn)))); /* Call VFS disconnect hook */ SMB_VFS_DISCONNECT(conn); yield_connection(conn, lp_servicename(SNUM(conn))); /* make sure we leave the directory available for unmount */ vfs_ChDir(conn, "/"); /* execute any "postexec = " line */ if (*lp_postexec(SNUM(conn)) && change_to_user(conn, vuid)) { char *cmd = talloc_sub_advanced(talloc_tos(), lp_servicename(SNUM(conn)), conn->session_info->unix_info->unix_name, conn->connectpath, conn->session_info->unix_token->gid, conn->session_info->unix_info->sanitized_username, conn->session_info->info->domain_name, lp_postexec(SNUM(conn))); smbrun(cmd,NULL); TALLOC_FREE(cmd); change_to_root_user(); } change_to_root_user(); /* execute any "root postexec = " line */ if (*lp_rootpostexec(SNUM(conn))) { char *cmd = talloc_sub_advanced(talloc_tos(), lp_servicename(SNUM(conn)), conn->session_info->unix_info->unix_name, conn->connectpath, conn->session_info->unix_token->gid, conn->session_info->unix_info->sanitized_username, conn->session_info->info->domain_name, lp_rootpostexec(SNUM(conn))); smbrun(cmd,NULL); TALLOC_FREE(cmd); } conn_free(conn); }
void connmgr_free(struct conn_manager* self) { size_t i; for (i = 0; i < connmgr_size(self); i ++) { conn_disconnect(self->conns[i]); conn_free(self->conns[i]), free(self->conns[i]); } free(self->conns); memset(self, 0, sizeof(*self)); }
void __connmgr_remove_connection_at(struct conn_manager* self, size_t i) { conn_disconnect(self->conns[i]); conn_free(self->conns[i]), free(self->conns[i]); size_t j; for (j = i + 1; j < connmgr_size(self); j ++) { self->conns[j - 1] = self->conns[j]; } self->num_conns --; }
int32 mesh_free(Mesh *mesh) { int32 ii; MeshTopology *topology = mesh->topology; LocalEntities *entities = mesh->entities; for (ii = 0; ii < 16; ii++) { conn_free(topology->conn[ii]); } for (ii = 0; ii < MAX_EL_TYPES; ii++) { conn_free(entities->edges[ii]); conn_free(entities->faces[ii]); } free_mem(topology->edge_oris); free_mem(topology->face_oris); return(RET_OK); }
void close_cnum(connection_struct *conn, uint16 vuid) { if (IS_IPC(conn)) { pipe_close_conn(conn); } else { file_close_conn(conn); dptr_closecnum(conn); } change_to_root_user(); DEBUG(IS_IPC(conn)?3:1, ("%s (%s) closed connection to service %s\n", get_remote_machine_name(), conn->client_address, lp_servicename(SNUM(conn)))); /* Call VFS disconnect hook */ SMB_VFS_DISCONNECT(conn); yield_connection(conn, lp_servicename(SNUM(conn))); /* make sure we leave the directory available for unmount */ vfs_ChDir(conn, "/"); /* execute any "postexec = " line */ if (*lp_postexec(SNUM(conn)) && change_to_user(conn, vuid)) { pstring cmd; pstrcpy(cmd,lp_postexec(SNUM(conn))); standard_sub_advanced(lp_servicename(SNUM(conn)), conn->user, conn->connectpath, conn->gid, get_current_username(), current_user_info.domain, cmd, sizeof(cmd)); smbrun(cmd,NULL); change_to_root_user(); } change_to_root_user(); /* execute any "root postexec = " line */ if (*lp_rootpostexec(SNUM(conn))) { pstring cmd; pstrcpy(cmd,lp_rootpostexec(SNUM(conn))); standard_sub_advanced(lp_servicename(SNUM(conn)), conn->user, conn->connectpath, conn->gid, get_current_username(), current_user_info.domain, cmd, sizeof(cmd)); smbrun(cmd,NULL); } conn_free(conn); }
int32 mesh_free_connectivity(Mesh *mesh, int32 d1, int32 d2) { uint32 D = mesh->topology->max_dim; MeshConnectivity *conn = 0; debprintf("free connectivity %d -> %d\n", d1, d2); conn = mesh->topology->conn[IJ(D, d1, d2)]; conn_free(conn); return(RET_OK); }
void conn_deinit(struct conn_base *cb) { struct conn *conn, *nconn; /* current and next connection */ for (conn = TAILQ_FIRST(&cb->free_connq); conn != NULL; conn = nconn, cb->nfree_connq--) { ASSERT(cb->nfree_connq > 0); nconn = TAILQ_NEXT(conn, conn_tqe); conn_free(conn); } ASSERT(cb->nfree_connq == 0); }
void conn_deinit(void) { struct conn *conn, *nconn; /* current and next connection */ for (conn = STAILQ_FIRST(&free_connq); conn != NULL; conn = nconn, nfree_connq--) { ASSERT(nfree_connq > 0); nconn = STAILQ_NEXT(conn, conn_tqe); conn_free(conn); } ASSERT(nfree_connq == 0); }
void conn_put(struct conn *c) { log_debug(LOG_VVERB, "put conn %p c %d", c, c->sd); if (c->rsize > RSIZE_HIGHWAT) { conn_free(c); return; } pthread_mutex_lock(&free_connq_mutex); nfree_connq++; STAILQ_INSERT_TAIL(&free_connq, c, c_tqe); pthread_mutex_unlock(&free_connq_mutex); }
// Close a connection. void conn_close(conn *c) { assert(c != NULL); /* delete the event, the socket and the conn */ event_del(&c->event); if (config.verbose > 1) { fprintf(stderr, "<%d connection closed.\n", c->sfd); } close(c->sfd); /* if the connection has big buffers, just free it */ if (!conn_add_to_freelist(c)) { conn_free(c); } }
int user_arp_hijack(struct user_conn_info *uci, char *src_fake_mac, char *dst_fake_mac, int input_mode) { struct conn_info *ci; int retval; if (!(ci = conn_get(uci))) { printf("connection isn't available\n"); retval = 1; } else { retval = arp_hijack(ci, src_fake_mac, dst_fake_mac, input_mode); conn_free(ci); } return retval; }
static void mainloop_inetd(void) { ServerConnection *connection = NULL; DataReadySelector *drs; if( ! config_switchToTargetUser() ) exit(1); drs_setNonBlockingCloExecFlags(0); drs = drs_new(); connection = conn_new(0); while( conn_processDataReady(connection, drs, false) != CONN_TO_CLOSE ) drs_select(drs); conn_free(connection); drs_free(drs); }
/* This function kills an existing embryonic session. It stops the connection's * transport layer, releases assigned resources, resumes the listener if it was * disabled and finally kills the file descriptor. This function requires that * sess->origin points to the incoming connection. */ static void session_kill_embryonic(struct session *sess) { int level = LOG_INFO; struct connection *conn = __objt_conn(sess->origin); struct task *task = sess->task; unsigned int log = sess->fe->to_log; const char *err_msg; if (sess->fe->options2 & PR_O2_LOGERRORS) level = LOG_ERR; if (log && (sess->fe->options & PR_O_NULLNOLOG)) { /* with "option dontlognull", we don't log connections with no transfer */ if (!conn->err_code || conn->err_code == CO_ER_PRX_EMPTY || conn->err_code == CO_ER_PRX_ABORT || conn->err_code == CO_ER_CIP_EMPTY || conn->err_code == CO_ER_CIP_ABORT || conn->err_code == CO_ER_SSL_EMPTY || conn->err_code == CO_ER_SSL_ABORT) log = 0; } if (log) { if (!conn->err_code && (task->state & TASK_WOKEN_TIMER)) { if (conn->flags & CO_FL_ACCEPT_PROXY) conn->err_code = CO_ER_PRX_TIMEOUT; else if (conn->flags & CO_FL_ACCEPT_CIP) conn->err_code = CO_ER_CIP_TIMEOUT; else if (conn->flags & CO_FL_SSL_WAIT_HS) conn->err_code = CO_ER_SSL_TIMEOUT; } session_prepare_log_prefix(sess); err_msg = conn_err_code_str(conn); if (err_msg) send_log(sess->fe, level, "%s: %s\n", trash.str, err_msg); else send_log(sess->fe, level, "%s: unknown connection error (code=%d flags=%08x)\n", trash.str, conn->err_code, conn->flags); } /* kill the connection now */ conn_stop_tracking(conn); conn_full_close(conn); conn_free(conn); task_delete(task); task_free(task); session_free(sess); }
/* Callback to be used by connection I/O handlers when some activity is detected * on an idle server connection. Its main purpose is to kill the connection once * a close was detected on it. It returns 0 if it did nothing serious, or -1 if * it killed the connection. */ static int si_idle_conn_wake_cb(struct connection *conn) { struct stream_interface *si = conn->owner; if (!conn_ctrl_ready(conn)) return 0; if (conn->flags & (CO_FL_ERROR | CO_FL_SOCK_RD_SH)) { /* warning, we can't do anything on <conn> after this call ! */ conn_force_close(conn); conn_free(conn); si->end = NULL; return -1; } return 0; }
/* * Invoked when a server of the specified service dies */ void svc_postmortem( struct service *sp, struct server *serp ) { struct service *co_sp = SERVER_CONNSERVICE( serp ) ; connection_s *cp = SERVER_CONNECTION( serp ) ; const char *func = "svc_postmortem" ; SVC_DEC_RUNNING_SERVERS( sp ) ; /* * Log information about the server that died */ if ( SVC_IS_LOGGING( sp ) ) { if ( SERVER_WRITES_TO_LOG(serp) ) { if ( debug.on ) msg( LOG_DEBUG, func, "Checking log size of %s service", SVC_ID( sp ) ) ; xlog_control( SVC_LOG( sp ), XLOG_SIZECHECK ) ; } svc_log_exit( sp, serp ) ; } /* * Now check if we have to check the log size of the service that owns * the connection */ if ( co_sp != sp && SVC_IS_LOGGING( co_sp ) ) xlog_control( SVC_LOG( co_sp ), XLOG_SIZECHECK ) ; if (!SVC_WAITS(sp)) { conn_free( cp, 1 ) ; cp = NULL; } else { if (cp) { if ( SVC_SOCKET_TYPE( sp ) == SOCK_DGRAM ) drain( cp->co_descriptor ) ; free(cp); cp = NULL; if( SVC_RELE( sp ) == 0 ) svc_release( sp ); /* shouldn't be 0, but should remove from * pset if it is... */ } svc_resume(sp); } }
void server_free(server_t *server) { if (!server) return; int i; for (i = 0; i < server->receivers->size; i++) { receiver_free(array_at(server->receivers, i)); } for (i = 0; i < server->workers->size; i++) { worker_free(array_at(server->workers, i)); } conn_free(server->conn); array_free(server->endpoints); array_free(server->receivers); array_free(server->workers); free(server); }
gboolean connection_socket_callback(gpointer ptr) { /* Gets final state of conn_t ptr and frees up the memory */ conn_t *data = (conn_t*)ptr; if(data->canceled && data->state == CONN_SUCCESS) { closesocket(data->socketfd); } else if(!data->canceled) { connecting = NULL; switch(data->state) { case CONN_SUCCESS: connection_dialog_connected(TUNER_THREAD_SOCKET, data->socketfd); break; case CONN_SOCKET_FAIL_RESOLV: connection_dialog_status("Unable to resolve the hostname."); connection_dialog_unlock(TRUE); break; case CONN_SOCKET_FAIL_CONN: connection_dialog_status("Unable to connect to a server."); connection_dialog_unlock(TRUE); break; case CONN_SOCKET_FAIL_AUTH: connection_dialog_status("Authentication error."); connection_dialog_unlock(TRUE); break; case CONN_SOCKET_FAIL_WRITE: connection_dialog_status("Socket write error."); connection_dialog_unlock(TRUE); break; } } conn_free(data); return FALSE; }