void conn_mkunion(uint8_t p, uint8_t q) { uint8_t i = conn_find(p); uint8_t j = conn_find(q); if (i == j) return; if (Sz[i] < Sz[j]) { Id[i] = j; Sz[j] += Sz[i]; } else { Id[j] = i; Sz[i] += Sz[j]; } Count--; }
void update_info(ToxGroup *g) { wmove(win_info, 0, 0); werase(win_info); wprintw(win_info, "npeer: %u | nconn %u | info %u\n", g->npeer, g->nconn, g->info); int i = 0; while(i < 4) { if(i < g->npeer) { PEER *p = &g->peerlist[i]; CONN *c; c = conn_find(g, p->ip, p->port); char ip[16]; inet_ntop(AF_INET, &p->ip, ip, 16); if(!c) { wprintw(win_info, "%s:%u (%u) (%X)\n", ip, p->port, p->timeout, p->info); } else { wprintw(win_info, "%s:%u (%u) (%u) (%u) (%X, %X)\n", ip, p->port, p->timeout, c->timeout, c->connect, p->info, c->info); } } else { wprintw(win_info, "\n"); } i++; } wrefresh(win_info); }
/**************************************************************************** do a switch on the message type, and return the response size ****************************************************************************/ static int switch_message(int type,char *inbuf,char *outbuf, int size,int bufsize, int ProcSockID, int threadid) { int outsize = 0; static int num_smb_messages = sizeof(smb_messages) / sizeof(struct smb_message_struct); int match; // extern int Client; connection_struct *conn; //0703 last_message = type; /* make sure this is an SMB packet */ if (strncmp(smb_base(inbuf),"\377SMB",4) != 0) { //os kwait(NULL); cyg_thread_yield(); return(-1); } for (match=0;match<num_smb_messages;match++) if (smb_messages[match].code == type) break; if (match == num_smb_messages) { //Jesse outsize = reply_unknown(inbuf,outbuf); outsize = ERROR(ERRSRV,ERRaccess); } else { if (smb_messages[match].fn) { //0609 int flags = smb_messages[match].flags; //0609 static uint16 last_session_tag = UID_FIELD_INVALID; uint16 session_tag = SVAL(inbuf,smb_uid); /* Ensure this value is replaced in the incoming packet. */ SSVAL(inbuf,smb_uid,session_tag); //0703 last_inbuf = inbuf; conn = conn_find(SVAL(inbuf, smb_tid), threadid); if (conn) conn->lastused = (msclock() /1000); //add by ron 7/5/2001 outsize = smb_messages[match].fn(conn,inbuf,outbuf,size,bufsize, ProcSockID, threadid); } else { outsize = reply_unknown(inbuf,outbuf); } } return(outsize); }
static BOOL process_lock(blocking_lock_record *blr) { char *outbuf = OutBuffer; char *inbuf = blr->inbuf; int outsize; SMB_BIG_UINT count = (SMB_BIG_UINT)0, offset = (SMB_BIG_UINT)0; NTSTATUS status; connection_struct *conn = conn_find(SVAL(inbuf,smb_tid)); files_struct *fsp = blr->fsp; BOOL my_lock_ctx = False; count = IVAL_TO_SMB_OFF_T(inbuf,smb_vwv1); offset = IVAL_TO_SMB_OFF_T(inbuf,smb_vwv3); errno = 0; status = do_lock_spin(fsp, conn, SVAL(inbuf,smb_pid), count, offset, WRITE_LOCK, &my_lock_ctx); if (NT_STATUS_IS_ERR(status)) { if (!NT_STATUS_EQUAL(status,NT_STATUS_LOCK_NOT_GRANTED) && !NT_STATUS_EQUAL(status,NT_STATUS_FILE_LOCK_CONFLICT)) { /* * We have other than a "can't get lock" * error. Send an error. * Return True so we get dequeued. */ blocking_lock_reply_error(blr, status); return True; } /* * Still can't get the lock - keep waiting. */ DEBUG(10,("process_lock: failed to get lock for file = %s. Still waiting....\n", fsp->fsp_name)); return False; } /* * Success - we got the lock. */ DEBUG(3,("process_lock : file=%s fnum=%d offset=%.0f count=%.0f\n", fsp->fsp_name, fsp->fnum, (double)offset, (double)count)); construct_reply_common(inbuf, outbuf); outsize = set_message(outbuf,0,0,True); send_blocking_reply(outbuf,outsize); return True; }
static void reply_lockingX_error(blocking_lock_record *blr, NTSTATUS status) { char *inbuf = blr->inbuf; files_struct *fsp = blr->fsp; connection_struct *conn = conn_find(SVAL(inbuf,smb_tid)); uint16 num_ulocks = SVAL(inbuf,smb_vwv6); SMB_BIG_UINT count = (SMB_BIG_UINT)0, offset = (SMB_BIG_UINT) 0; uint16 lock_pid; unsigned char locktype = CVAL(inbuf,smb_vwv3); BOOL large_file_format = (locktype & LOCKING_ANDX_LARGE_FILES); char *data; int i; data = smb_buf(inbuf) + ((large_file_format ? 20 : 10)*num_ulocks); /* * Data now points at the beginning of the list * of smb_lkrng structs. */ /* * Ensure we don't do a remove on the lock that just failed, * as under POSIX rules, if we have a lock already there, we * will delete it (and we shouldn't) ..... */ for(i = blr->lock_num - 1; i >= 0; i--) { BOOL err; lock_pid = get_lock_pid( data, i, large_file_format); count = get_lock_count( data, i, large_file_format); offset = get_lock_offset( data, i, large_file_format, &err); /* * We know err cannot be set as if it was the lock * request would never have been queued. JRA. */ do_unlock(fsp,conn,lock_pid,count,offset); } generic_blocking_lock_error(blr, status); }
int input_logout(DESC_DATA *d, const char *data, int plen) { const int PACKET_LENGTH = 4; if (plen < PACKET_LENGTH) return 0; DWORD account_id = decode_4bytes((const BYTE*)data); // sys_log("LOGOUT: %u", account_id); CONN_DATA *conn = conn_find(account_id); if (NULL==conn) { return PACKET_LENGTH; } // update online time and logout time { conn_delete(account_id); } return PACKET_LENGTH; } /* end of input_logout() */
static BOOL process_lockingX(blocking_lock_record *blr) { char *inbuf = blr->inbuf; unsigned char locktype = CVAL(inbuf,smb_vwv3); files_struct *fsp = blr->fsp; connection_struct *conn = conn_find(SVAL(inbuf,smb_tid)); uint16 num_ulocks = SVAL(inbuf,smb_vwv6); uint16 num_locks = SVAL(inbuf,smb_vwv7); SMB_BIG_UINT count = (SMB_BIG_UINT)0, offset = (SMB_BIG_UINT)0; uint16 lock_pid; BOOL large_file_format = (locktype & LOCKING_ANDX_LARGE_FILES); char *data; BOOL my_lock_ctx = False; NTSTATUS status = NT_STATUS_OK; data = smb_buf(inbuf) + ((large_file_format ? 20 : 10)*num_ulocks); /* * Data now points at the beginning of the list * of smb_lkrng structs. */ for(; blr->lock_num < num_locks; blr->lock_num++) { BOOL err; lock_pid = get_lock_pid( data, blr->lock_num, large_file_format); count = get_lock_count( data, blr->lock_num, large_file_format); offset = get_lock_offset( data, blr->lock_num, large_file_format, &err); /* * We know err cannot be set as if it was the lock * request would never have been queued. JRA. */ errno = 0; status = do_lock_spin(fsp,conn,lock_pid,count,offset, ((locktype & 1) ? READ_LOCK : WRITE_LOCK), &my_lock_ctx); if (NT_STATUS_IS_ERR(status)) break; } if(blr->lock_num == num_locks) { /* * Success - we got all the locks. */ DEBUG(3,("process_lockingX file = %s, fnum=%d type=%d num_locks=%d\n", fsp->fsp_name, fsp->fnum, (unsigned int)locktype, num_locks) ); reply_lockingX_success(blr); return True; } else if (!NT_STATUS_EQUAL(status,NT_STATUS_LOCK_NOT_GRANTED) && !NT_STATUS_EQUAL(status,NT_STATUS_FILE_LOCK_CONFLICT)) { /* * We have other than a "can't get lock" * error. Free any locks we had and return an error. * Return True so we get dequeued. */ blocking_lock_reply_error(blr, status); return True; } /* * Still can't get all the locks - keep waiting. */ DEBUG(10,("process_lockingX: only got %d locks of %d needed for file %s, fnum = %d. \ Waiting....\n", blr->lock_num, num_locks, fsp->fsp_name, fsp->fnum)); return False; }
static BOOL process_lockread(blocking_lock_record *blr) { char *outbuf = OutBuffer; char *inbuf = blr->inbuf; ssize_t nread = -1; char *data, *p; int outsize = 0; SMB_BIG_UINT startpos; size_t numtoread; NTSTATUS status; connection_struct *conn = conn_find(SVAL(inbuf,smb_tid)); files_struct *fsp = blr->fsp; BOOL my_lock_ctx = False; numtoread = SVAL(inbuf,smb_vwv1); startpos = (SMB_BIG_UINT)IVAL(inbuf,smb_vwv2); numtoread = MIN(BUFFER_SIZE-outsize,numtoread); data = smb_buf(outbuf) + 3; status = do_lock_spin( fsp, conn, SVAL(inbuf,smb_pid), (SMB_BIG_UINT)numtoread, startpos, READ_LOCK, &my_lock_ctx); if (NT_STATUS_V(status)) { if (!NT_STATUS_EQUAL(status,NT_STATUS_LOCK_NOT_GRANTED) && !NT_STATUS_EQUAL(status,NT_STATUS_FILE_LOCK_CONFLICT)) { /* * We have other than a "can't get lock" * error. Send an error. * Return True so we get dequeued. */ generic_blocking_lock_error(blr, status); return True; } /* * Still waiting for lock.... */ DEBUG(10,("process_lockread: failed to get lock for file = %s. Still waiting....\n", fsp->fsp_name)); return False; } nread = read_file(fsp,data,startpos,numtoread); if (nread < 0) { generic_blocking_lock_error(blr,NT_STATUS_ACCESS_DENIED); return True; } construct_reply_common(inbuf, outbuf); outsize = set_message(outbuf,5,0,True); outsize += nread; SSVAL(outbuf,smb_vwv0,nread); SSVAL(outbuf,smb_vwv5,nread+3); p = smb_buf(outbuf); *p++ = 1; SSVAL(p,0,nread); p += 2; set_message_end(outbuf, p+nread); DEBUG(3, ( "process_lockread file = %s, fnum=%d num=%d nread=%d\n", fsp->fsp_name, fsp->fnum, (int)numtoread, (int)nread ) ); send_blocking_reply(outbuf,outsize); return True; }
static int conn_send(struct sip_connqent **qentp, struct sip *sip, bool secure, const struct sa *dst, struct mbuf *mb, sip_transp_h *transph, void *arg) { struct sip_conn *conn, *new_conn = NULL; struct sip_connqent *qent; int err = 0; conn = conn_find(sip, dst, secure); if (conn) { if (!conn->established) goto enqueue; return tcp_send(conn->tc, mb); } new_conn = conn = mem_zalloc(sizeof(*conn), conn_destructor); if (!conn) return ENOMEM; hash_append(sip->ht_conn, sa_hash(dst, SA_ALL), &conn->he, conn); conn->paddr = *dst; conn->sip = sip; err = tcp_connect(&conn->tc, dst, tcp_estab_handler, tcp_recv_handler, tcp_close_handler, conn); if (err) goto out; err = tcp_conn_local_get(conn->tc, &conn->laddr); if (err) goto out; #ifdef USE_TLS if (secure) { const struct sip_transport *transp; transp = transp_find(sip, SIP_TRANSP_TLS, sa_af(dst), dst); if (!transp || !transp->tls) { err = EPROTONOSUPPORT; goto out; } err = tls_start_tcp(&conn->sc, transp->tls, conn->tc, 0); if (err) goto out; } #endif tmr_start(&conn->tmr, TCP_IDLE_TIMEOUT * 1000, conn_tmr_handler, conn); enqueue: qent = mem_zalloc(sizeof(*qent), qent_destructor); if (!qent) { err = ENOMEM; goto out; } list_append(&conn->ql, &qent->le, qent); qent->mb = mem_ref(mb); qent->transph = transph ? transph : internal_transport_handler; qent->arg = arg; if (qentp) { qent->qentp = qentp; *qentp = qent; } out: if (err) mem_deref(new_conn); return err; }
int input_login(DESC_DATA *d, const char *data, int plen) { const int PACKET_LENGTH = 4; if (plen < PACKET_LENGTH) return 0; DWORD account_id = decode_4bytes((const BYTE*)data); // sys_log("LOGIN: %u", account_id); /* 기존 정보가 있으면 접속을 끊으라고 알려줌 */ CONN_DATA *conn = conn_find(account_id); if (conn) { send_force_logout(conn); //conn_delete(GET_ID(conn)); // 새로운 접속자도 접속을 끊는다. { PACKET_DATA *buf = &d->packet_buffer; packet_header(buf, HEADER_TG_FORCE_LOGOUT, d->desc_num); packet(buf, GET_LOGIN(conn), MAX_LOGIN_LEN); } return PACKET_LENGTH; } conn = (CONN_DATA*) calloc(1, sizeof(CONN_DATA)); GET_ID(conn) = account_id; GET_DESC(conn) = d; GET_EVENT(conn) = NULL; int login_succ = FALSE; if (teen_all_flag) login_succ = account_login_teen_all(account_id, conn); else login_succ = account_login(account_id, conn); if (FALSE==login_succ) { //conn_delete(GET_ID(conn)); SAFE_FREE(conn); return PACKET_LENGTH; } conn_insert(conn); if (YES==GET_TEENAGE(conn)) { conn_event_info *info = (conn_event_info*) calloc(1, sizeof(conn_event_info)); info->conn = conn; GET_EVENT(conn) = event_create(conn_event_func, info, (CHECK_TIME_SEC * PASSES_PER_SEC)); } else { GET_EVENT(conn) = NULL; } if (YES==GET_TEENAGE(conn)) { send_login_notice(conn); set_notice_step(conn); send_notice(conn); } sys_log("CONN_INSERT : %u, %s", GET_ID(conn), GET_LOGIN(conn)); return PACKET_LENGTH; } /* end of input_login() */