void chown_advanced_cmd (void) { /* Number of files at startup */ int files_on_begin; files_on_begin = MAX (1, current_panel->marked); do { /* do while any files remaining */ int file_idx; char buffer[BUF_MEDIUM]; vfs_path_t *vpath; int result; init_chown_advanced (); if (current_panel->marked) fname = next_file (); /* next marked file */ else fname = selection (current_panel)->fname; /* single file */ vpath = vfs_path_from_str (fname); if (mc_stat (vpath, sf_stat) != 0) { /* get status of file */ dlg_destroy (ch_dlg); vfs_path_free (vpath); break; } ch_cmode = sf_stat->st_mode; file_idx = files_on_begin == 1 ? 1 : (files_on_begin - current_panel->marked + 1); g_snprintf (buffer, sizeof (buffer), "%s (%d/%d)", str_fit_to_term (fname, WIDGET (ch_dlg)->cols - 20, J_LEFT_FIT), file_idx, files_on_begin); label_set_text (l_filename, buffer); chown_refresh (); update_ownership (); result = dlg_run (ch_dlg); switch (result) { case B_CANCEL: end_chown = TRUE; break; case B_ENTER: need_update = TRUE; if (mc_chmod (vpath, get_mode ()) == -1) message (D_ERROR, MSG_ERROR, _("Cannot chmod \"%s\"\n%s"), fname, unix_error_string (errno)); /* call mc_chown only, if mc_chmod didn't fail */ else if (mc_chown (vpath, (ch_flags[9] == '+') ? sf_stat->st_uid : (uid_t) (-1), (ch_flags[10] == '+') ? sf_stat->st_gid : (gid_t) (-1)) == -1) message (D_ERROR, MSG_ERROR, _("Cannot chown \"%s\"\n%s"), fname, unix_error_string (errno)); break; case B_SETALL: apply_advanced_chowns (sf_stat); break; case B_SKIP: default: break; } if (current_panel->marked && result != B_CANCEL) { do_file_mark (current_panel, current_file, 0); need_update = TRUE; } dlg_destroy (ch_dlg); vfs_path_free (vpath); } while (current_panel->marked && !end_chown); chown_advanced_done (); }
static void do_enter_key (WDialog * h, int f_pos) { WListbox *chl_list; struct passwd *chl_pass; struct group *chl_grp; int fe; gboolean chl_end, is_owner; do { int result; WDialog *chl_dlg; const char *title; int lxx, lyy, b_pos; is_owner = (f_pos == 3); title = is_owner ? _("owner") : _("group"); lxx = (COLS - 74) / 2 + (is_owner ? 35 : 53); lyy = (LINES - 13) / 2; chl_end = FALSE; chl_dlg = dlg_create (TRUE, lyy, lxx, 13, 17, WPOS_KEEP_DEFAULT, TRUE, dialog_colors, chl_callback, NULL, "[Advanced Chown]", title); /* get new listboxes */ chl_list = listbox_new (1, 1, 11, 15, FALSE, NULL); listbox_add_item (chl_list, LISTBOX_APPEND_AT_END, 0, "<Unknown>", NULL, FALSE); if (is_owner) { /* get and put user names in the listbox */ setpwent (); while ((chl_pass = getpwent ()) != NULL) listbox_add_item (chl_list, LISTBOX_APPEND_SORTED, 0, chl_pass->pw_name, NULL, FALSE); endpwent (); fe = listbox_search_text (chl_list, get_owner (sf_stat->st_uid)); } else { /* get and put group names in the listbox */ setgrent (); while ((chl_grp = getgrent ()) != NULL) listbox_add_item (chl_list, LISTBOX_APPEND_SORTED, 0, chl_grp->gr_name, NULL, FALSE); endgrent (); fe = listbox_search_text (chl_list, get_group (sf_stat->st_gid)); } listbox_select_entry (chl_list, fe); b_pos = chl_list->pos; add_widget (chl_dlg, chl_list); result = dlg_run (chl_dlg); if (result != B_CANCEL) { if (b_pos != chl_list->pos) { gboolean ok = FALSE; char *text; listbox_get_current (chl_list, &text, NULL); if (is_owner) { chl_pass = getpwnam (text); if (chl_pass != NULL) { ok = TRUE; sf_stat->st_uid = chl_pass->pw_uid; } } else { chl_grp = getgrnam (text); if (chl_grp != NULL) { sf_stat->st_gid = chl_grp->gr_gid; ok = TRUE; } } if (ok) { ch_flags[f_pos + 6] = '+'; update_ownership (); } dlg_focus (h); if (ok) print_flags (); } if (result == KEY_LEFT) { if (!is_owner) chl_end = TRUE; dlg_one_up (ch_dlg); f_pos--; } else if (result == KEY_RIGHT) { if (is_owner) chl_end = TRUE; dlg_one_down (ch_dlg); f_pos++; } } /* Here we used to redraw the window */ dlg_destroy (chl_dlg); } while (chl_end); }
void chown_advanced_cmd (void) { files_on_begin = current_panel->marked; do { /* do while any files remaining */ init_chown_advanced (); if (current_panel->marked) fname = next_file (); /* next marked file */ else fname = selection (current_panel)->fname; /* single file */ if (mc_stat (fname, sf_stat) != 0) { /* get status of file */ destroy_dlg (ch_dlg); break; } ch_cmode = sf_stat->st_mode; chown_refresh (); update_ownership (); /* game can begin */ run_dlg (ch_dlg); switch (ch_dlg->ret_value) { case B_CANCEL: end_chown = 1; break; case B_ENTER: need_update = 1; if (mc_chmod (fname, get_mode ()) == -1) message (D_ERROR, MSG_ERROR, _(" Cannot chmod \"%s\" \n %s "), fname, unix_error_string (errno)); /* call mc_chown only, if mc_chmod didn't fail */ else if (mc_chown (fname, (ch_flags[9] == '+') ? sf_stat->st_uid : (uid_t) -1, (ch_flags[10] == '+') ? sf_stat->st_gid : (gid_t) -1) == -1) message (D_ERROR, MSG_ERROR, _(" Cannot chown \"%s\" \n %s "), fname, unix_error_string (errno)); break; case B_SETALL: apply_advanced_chowns (sf_stat); break; case B_SKIP: break; } if (current_panel->marked && ch_dlg->ret_value != B_CANCEL) { do_file_mark (current_panel, current_file, 0); need_update = 1; } destroy_dlg (ch_dlg); } while (current_panel->marked && !end_chown); chown_advanced_done (); }
static ACE_THR_FUNC_RETURN process(void* arg){ ACE_INET_Addr addr; ACE_SOCK_Stream stream; ACE_HANDLE handle = (ACE_HANDLE) (intptr_t) arg; stream.set_handle(handle); /*make sure we're not in non-blocking mode.*/ if(stream.disable(ACE_NONBLOCK) == -1){ ACE_ERROR_RETURN ((LM_ERROR, "%p\n", "disable"), 0); } else if(stream.get_remote_addr(addr) == -1){ ACE_ERROR_RETURN ((LM_ERROR, "%p\n", "get_remote_addr"), 0); } ACE_DEBUG ((LM_INFO, "(%P|%t:%l) client %s connected from %d\n", addr.get_host_name (), addr.get_port_number ())); int r_bytes = 0; char buf[SIZE]; ACE_CString cs; do{ r_bytes = stream.recv(buf, SIZE); if(r_bytes == 0 || r_bytes == -1){ ACE_DEBUG((LM_INFO, "(%P|%t:%l) r_bytes = %d, exit from the loop\n", r_bytes)); break; } for(int i=0; i< r_bytes; i++){ cs += buf[i]; } }while(true); stream.close_reader(); /* ACE_DEBUG((LM_INFO, "%s\n", cs.c_str())); */ /*the layout of the message would be: * ^^pq||step1$$ * 1st step: get the d by pq * 2nd calculate * 3rd send back the digest */ int p0, p1; int len = cs.length(); p0 = 2; p1 = cs.find("||"); ACE_CString pq = cs.substr(2, p1 - 2); ACE_CString step1 = cs.substr(p1 + 2, len - p1 -4); /* ACE_DEBUG((LM_INFO, "pq = %s\n step1 = %s\n", pq.c_str(), step1.c_str())); */ //get the d ACE_CString sql = "select d,textid from player0 where pq='"; sql += pq; sql += "'"; /* ACE_DEBUG((LM_INFO, "sql = %s\n", sql.c_str())); */ PGconn* con; con = PQconnectdb("host=45.33.3.188 port=5432 dbname=nv user=dec"); PGresult* res; if(PQstatus(con)!= CONNECTION_OK){ ACE_DEBUG((LM_INFO, "Connection to database failed:%s\n", PQerrorMessage(con))); reclaim_conn(con); } res = PQexec(con, sql.c_str()); int n = PQntuples(res); if(n != 1){ ACE_ERROR((LM_ERROR, "there is significant error: %d\n", n)); // return 0; } ACE_CString d = ""; d += PQgetvalue(res, 0, 0); /* ACE_DEBUG((LM_INFO, "d = %s\n", d.c_str())); */ bn* pq_ = from_hex(&pq); bn* d_ = from_hex(&d); bn* step1_ = from_hex(&step1); bn* step2_ = npmod(step1_ , d_ , pq_ ); ACE_CString* step2 = step2_->to_hex(); //check if the pq is taking the ownnership? /* if pq is 'centralbank', bypass the check, otherwise check the payer whether has the ownnership of the note; * select count(*) from ownership0 o, player0 p where o.owner = p.textid and o.note='0x12345678' and p.pq='0x12345678'; */ bn* e_ = new bn(1); e_->addat(0,0x10001); bn* step3_ = npmod(step2_ , e_ , pq_ ); ACE_CString* rawMsg = encode(step3_); ACE_DEBUG((LM_INFO, "%T :%l step3 = %s\n", rawMsg->c_str())); if(verify_ownership(rawMsg, pq)){ //update the ownership; int pos1 = rawMsg->find("->"); ACE_CString note = rawMsg->substr(2, pos1 -2); int rawlen = rawMsg->length(); ACE_CString id = rawMsg->substr(pos1 + 2, rawlen - pos1 - 6); update_ownership(note, id); /*insert the log entry*/ insert_logentry(pq, *step2, *rawMsg, note, id); stream.send( step2->c_str(), step2->length()); /* ACE_DEBUG((LM_INFO, "%T :%l the step2 message is:\n%s\n", step2->c_str())); */ }else{ ACE_DEBUG((LM_INFO, "%T :%l invalid transfer\n")); ACE_CString reply ="invalid transfer\n"; stream.send( reply.c_str(), reply.length()); } delete step2 ; delete pq_; delete d_; delete step1_; delete step2_; delete e_; delete step3_; delete rawMsg; /* stream.close_writer(); */ stream.close(); ACE_DEBUG((LM_INFO, "%T :%l closed the stream\n")); }
static void do_enter_key (Dlg_head * h, int f_pos) { Dlg_head *chl_dlg; WListbox *chl_list; struct passwd *chl_pass; struct group *chl_grp; WLEntry *fe; int lxx, lyy, chl_end, b_pos; int is_owner; const char *title; do { is_owner = (f_pos == 3); title = is_owner ? _("owner") : _("group"); lxx = (COLS - 74) / 2 + (is_owner ? 35 : 53); lyy = (LINES - 13) / 2; chl_end = 0; chl_dlg = create_dlg (lyy, lxx, 13, 17, dialog_colors, chl_callback, "[Advanced Chown]", title, DLG_COMPACT | DLG_REVERSE); /* get new listboxes */ chl_list = listbox_new (1, 1, 11, 15, NULL); listbox_add_item (chl_list, LISTBOX_APPEND_AT_END, 0, "<Unknown>", NULL); if (is_owner) { /* get and put user names in the listbox */ setpwent (); while ((chl_pass = getpwent ())) { listbox_add_item (chl_list, LISTBOX_APPEND_SORTED, 0, chl_pass->pw_name, NULL); } endpwent (); fe = listbox_search_text (chl_list, get_owner (sf_stat->st_uid)); } else { /* get and put group names in the listbox */ setgrent (); while ((chl_grp = getgrent ())) { listbox_add_item (chl_list, LISTBOX_APPEND_SORTED, 0, chl_grp->gr_name, NULL); } endgrent (); fe = listbox_search_text (chl_list, get_group (sf_stat->st_gid)); } if (fe) listbox_select_entry (chl_list, fe); b_pos = chl_list->pos; add_widget (chl_dlg, chl_list); run_dlg (chl_dlg); if (b_pos != chl_list->pos) { int ok = 0; if (is_owner) { chl_pass = getpwnam (chl_list->current->text); if (chl_pass) { ok = 1; sf_stat->st_uid = chl_pass->pw_uid; } } else { chl_grp = getgrnam (chl_list->current->text); if (chl_grp) { sf_stat->st_gid = chl_grp->gr_gid; ok = 1; } } if (ok) { ch_flags[f_pos + 6] = '+'; update_ownership (); } dlg_focus (h); if (ok) print_flags (); } if (chl_dlg->ret_value == KEY_LEFT) { if (!is_owner) chl_end = 1; dlg_one_up (ch_dlg); f_pos--; } else if (chl_dlg->ret_value == KEY_RIGHT) { if (is_owner) chl_end = 1; dlg_one_down (ch_dlg); f_pos++; } /* Here we used to redraw the window */ destroy_dlg (chl_dlg); } while (chl_end); }