std::string facebook_client::choose_request_url( int request_type, std::string* data, std::string* get_data ) { std::string url = choose_proto( request_type ); url.append( choose_server( request_type, data, get_data ) ); url.append( choose_action( request_type, data, get_data ) ); return url; }
std::string Omegle_client::choose_request_url( int request_type, std::string* data, std::string* get_data ) { std::string url = ""; url.append( choose_server( request_type, data, get_data )); url.append( choose_action( request_type, data, get_data )); return url; }
int connect_2_analyze_server(int *sockfd) { static int ana_retry_count = 0; uint32_t serverip; if (if_choose_server) serverip = choose_server(); else serverip = analyze_server_set->ipvalue; if (connect_2_server(serverip,server_analyze_port, sockfd, "analyze") == -1) { ana_retry_count ++; if (ana_retry_count == 3) { write_log("Connect to analyze server:retry 3 times,all failed, server maybe done or get bad config file!\n"); ana_retry_count = 0; if (initiate(NULL) == -1)//重新读取配置文件 return -1; } return -1; } return 0; }
/* * @brief 将某个文件发送到服务器 * @param const char *send_file:带发送的文件名指针 * @return 0 表示发送成功,1表示非法文件, -1表示发送失败 */ static int send_2_server(const char *send_file) { int sockfd; //套接字 struct sockaddr_in server; //服务器 file_header_t file_head; //文件头 FILE *fp; //文件打开指针 int read_count=0; //读出的记录数 int write_count=0; //写入buffer中的结构数 int read_len; //实际从文件中读出的字节长度 int send_len; //tcp实际发送的字节长度 int total_send_len; //tcp总共发送了多少字节 uint32_t proper_server; //choose_ip()返回的合适的服务器IP 本机字节序 char buffer[NET_BUFFER_LEN]; //数据缓冲区 char encrypt_buffer[NET_BUFFER_LEN]; //加密后的缓冲区 char *buf_ptr; //缓冲区的剩余空间指针 store_result_t tmp_result; //临时存放一个数据 store_result_t *result_ptr; //指向数据的指针 store_result_t *tmp_result_ptr; //保存result_ptr指针 int effective_size; //结构体中的有效数据长度,需要减去next指针的大小 store_result_t *send_link=NULL; //数据发送链,处理完毕后写回文件 //(void)encrypt_buffer; fp=fopen(send_file, "rb"); if (fp == NULL) { write_log("Can not open file:%s!!!\n", send_file); return 1; } if ((read_len=fread(&file_head, sizeof(file_header_t), 1, fp)) != 1 ) { write_log("File not complete:%s!!!\n", send_file); fclose(fp); return 1;//file not complete; } if (memcmp(file_head.symbol,FILE_HEAD_SYMBOL, F_SYMBOL_LEN) != 0) { write_log("%s is not a valid velocity test file!!!\n", send_file); fclose(fp); return 1;//not a valid velocity test file; } if (file_head.processed_record == file_head.total_record) { write_log("%s has already been send!!!\n", send_file); fclose(fp); return 0; //no need to handle this file } effective_size = sizeof(store_result_t) - sizeof(store_result_t*);//丢掉next指针的长度 这里是36字节 while (!feof(fp)) { read_len = fread(&tmp_result, effective_size, 1, fp); /* printf("%u,%u,%d,%u,%u,%u,%u,%u,%u\n",tmp_result.processed,tmp_result.machine_number ,tmp_result.probe_time,tmp_result.probed_ip,tmp_result.reachable,tmp_result.hop ,tmp_result.loss_percentage,tmp_result.avg_latency,tmp_result.previous_hop); */ if (read_len != 1) break; tmp_result.next = NULL; read_count++; //记录数加1 if ((result_ptr = (store_result_t*)malloc(sizeof(store_result_t))) == NULL) { write_log("Send_2_server:malloc failed!!\n"); fclose(fp); pthread_exit(NULL); } memcpy(result_ptr, &tmp_result, sizeof(store_result_t)); if (send_link == NULL) send_link = result_ptr; else { result_ptr->next=send_link; send_link=result_ptr; } }//while fclose(fp); if ( read_count != file_head.total_record) { write_log("%s:file record not equal total_record field!!!\n", send_file); free_send_link(send_link); return 1; //读到的记录数与总记录数不相等 } if (read_count == 0 || send_link == NULL) { write_log("%s:file record==0!\n", send_file); free_send_link(send_link); return 1; //没有读到记录 } proper_server = choose_server(); if (proper_server == 0) { write_log("Send file:no proper server exist!\n"); free_send_link(send_link); return -1; } if ((sockfd = socket(AF_INET, SOCK_STREAM, 0)) == -1) { write_log("Send file:create socket failed!%s\n", strerror(errno)); free_send_link(send_link); return -1; } server.sin_addr.s_addr = htonl(proper_server); server.sin_family = AF_INET; server.sin_port = htons(server_conn_port); bzero(&(server.sin_zero), sizeof(server.sin_zero)); if (connect(sockfd, (struct sockaddr*)(&server), sizeof(server)) == -1) { char buf[INET_ADDRSTRLEN]; write_log("Send file:connetct to server %s failed!%s\n", inet_ntop(AF_INET, &(server.sin_addr), buf, INET_ADDRSTRLEN), strerror(errno)); close(sockfd); free_send_link(send_link); return -1; } result_ptr = send_link; //tmp_result_ptr = result_ptr; int buffer_full_flag = 1;//等于1表示缓冲区已经满了,已经发送,需要重新建立头部信息 int buffer_remain_flag = 0;//buffer里面还有没有数据 默认没了 while (result_ptr != NULL) { if (result_ptr->processed) { result_ptr = result_ptr->next; continue; } if (buffer_full_flag == 1) { //重建buffer的头部 buf_ptr = buffer; buffer_full_flag = 0; write_count = 0; //buffer的前16个字节是"TAOMEEV5SENDDATA",接着8个字节是数据长度 memcpy(buf_ptr, SYMBOL, P_SYMBOL_LEN); buf_ptr += P_SYMBOL_LEN; memcpy(buf_ptr, C_SEND_DATA, COMMAND_LEN); buf_ptr += COMMAND_LEN; buf_ptr += (DATA_LEN + FILL_LEN); //跳过数据长度部分 } if ( (buffer + sizeof(buffer) - buf_ptr) >= (effective_size + DATA_END_LEN) ) { //如果buffer的剩余空间还可以容纳一个结构 memcpy(buf_ptr, result_ptr, effective_size); buf_ptr += effective_size; write_count++; buffer_remain_flag = 1; } else { //已经容纳不下更多数据,填写实际的数据长度(8字节),加密缓冲区并发送缓冲区内容 uint32_t len = write_count * effective_size; //写入的数据长度 memcpy(buffer + P_SYMBOL_LEN + COMMAND_LEN, &len, DATA_LEN ); uint32_t fill_len = (ALIGN_LEN - len%ALIGN_LEN) % ALIGN_LEN; //需要补齐的字节数 memcpy(buffer + P_SYMBOL_LEN + COMMAND_LEN + DATA_LEN, &fill_len, FILL_LEN); memset(buf_ptr, 0x0, fill_len );//保证是8字节的整数倍 buf_ptr += fill_len; //进入到else说明还后后续数据 memcpy(buf_ptr, CONTINUE, DATA_END_LEN); buf_ptr += DATA_END_LEN; //buf_ptr指向整个数据的末端 #ifdef ENCODE_ des_encrypt_n(des_pass_phrase, (const void*)buffer , (void*)encrypt_buffer, (buf_ptr - buffer)/ALIGN_LEN); memcpy(buffer, encrypt_buffer, buf_ptr - buffer); #endif //sent to server send_len = 0; total_send_len = 0; int data_len = buf_ptr - buffer; while ((send_len = send(sockfd, buffer+total_send_len, (data_len-total_send_len), 0) ) < (data_len - total_send_len)) { if (send_len == -1 ) { if (errno == EINTR) continue; write_log("Send file: send error:%s\n", strerror(errno)); close(sockfd); free_send_link(send_link); return -1; } else total_send_len += send_len; } total_send_len += send_len; buffer_full_flag = 1; buffer_remain_flag = 0; //buffer里面没数据了 continue; }//else result_ptr=result_ptr->next; }//while if (buffer_remain_flag == 1) {//结束while循环的条件有多种,结束后Buffer中可能还有数据 uint32_t len = write_count * effective_size; //写入的数据长度 memcpy(buffer + P_SYMBOL_LEN + COMMAND_LEN, &len, DATA_LEN ); uint32_t fill_len = (ALIGN_LEN - len%ALIGN_LEN)%ALIGN_LEN; //需要补齐的字节数 memcpy(buffer + P_SYMBOL_LEN + COMMAND_LEN + DATA_LEN, &fill_len, FILL_LEN); memset(buf_ptr, 0x0, fill_len );//保证是8字节的整数倍 buf_ptr += fill_len; //buf_ptr指向整个数据的末端 //到这一步,说明已经没有后续数据了,可以结束发送,DATA_END字段全置"DATA_END" memcpy(buf_ptr,DATA_END,DATA_END_LEN); buf_ptr += DATA_END_LEN; //buf_ptr指向整个数据的末端 #ifdef ENCODE_ des_encrypt_n(des_pass_phrase, (const void*)buffer , (void*)encrypt_buffer, (buf_ptr - buffer)/ALIGN_LEN); memcpy(buffer, encrypt_buffer, buf_ptr - buffer); #endif //sent to server send_len = 0; total_send_len = 0; int data_len = buf_ptr - buffer; while ((send_len=send(sockfd, buffer+total_send_len, (data_len-total_send_len), 0) ) < (data_len - total_send_len)) { if (send_len == -1) { if (errno == EINTR) continue; write_log("Send file: send error:%s\n", strerror(errno)); close(sockfd); free_send_link(send_link); return -1; } else total_send_len += send_len; } total_send_len += send_len; } // wait for server's response int recv_len = 0; int total_recv_len = 0; int data_len = P_SYMBOL_LEN + COMMAND_LEN + DATA_LEN + FILL_LEN + DATA_END_LEN; //32 while ((recv_len = recv(sockfd, (void*)buffer+total_recv_len, (sizeof(buffer) - total_recv_len), 0)) < (data_len - total_recv_len)) { if (recv_len == -1) { if (errno == EINTR) continue; write_log("Send file:receive server response error:%s\n", strerror(errno)); close(sockfd); free_send_link(send_link); return -1; } else if (recv_len == 0) { write_log("Send file:receive server response error:%s\n", strerror(errno)); close(sockfd); free_send_link(send_link); return -1; } else total_recv_len += recv_len; } total_recv_len += recv_len; #ifdef ENCODE_ des_decrypt_n(des_pass_phrase, (const void*)buffer, (void*)encrypt_buffer, (data_len)/ALIGN_LEN); //32BYTE/8BYTE memcpy(buffer, encrypt_buffer, sizeof(buffer)); #endif //server should reply "TAOMEEV5DATA__OK"+0000+0000 + "DATA_END" if (memcmp(SYMBOL, buffer, P_SYMBOL_LEN) == 0 && memcmp(C_DATA_OK, buffer + P_SYMBOL_LEN, COMMAND_LEN ) == 0) { //DATA_OK file_head.processed_record = file_head.total_record; file_head.last_modify = time((time_t*)0); //after sending buffer reset proceesed flag tmp_result_ptr = send_link; while (tmp_result_ptr != NULL) { tmp_result_ptr->processed = 1; tmp_result_ptr = tmp_result_ptr->next; } write_back_to_file(send_file, send_link, file_head); close(sockfd); free_send_link(send_link); return 0; } else { write_log("Send_file:wait response: bad respose:%s\n", buffer); close(sockfd); free_send_link(send_link); return -1; } }
int whois_main(int argc, char *argv[]) { const char *country, *host; char *qnichost; int ch, flags, use_qnichost; #ifdef SOCKS SOCKSinit(argv[0]); #endif country = host = qnichost = NULL; flags = use_qnichost = 0; optind = 1; // initialize for getopt while ((ch = getopt(argc, argv, "aAbc:dgh:iIlmp:QrR6")) != -1) { switch (ch) { case 'a': host = ANICHOST; break; case 'A': host = PNICHOST; break; case 'b': host = ABUSEHOST; break; case 'c': country = optarg; break; case 'd': host = DNICHOST; break; case 'g': host = GNICHOST; break; case 'h': host = optarg; break; case 'i': host = INICHOST; break; case 'I': host = IANAHOST; break; case 'l': host = LNICHOST; break; case 'm': host = MNICHOST; break; case 'p': port = optarg; break; case 'Q': flags |= WHOIS_QUICK; break; case 'r': host = RNICHOST; break; case 'R': warnx("-R is deprecated; use '-c ru' instead"); country = "ru"; break; case '6': host = SNICHOST; break; case '?': default: usage(); /* NOTREACHED */ } } argc -= optind; argv += optind; if (!argc || (country != NULL && host != NULL)) usage(); /* * If no host or country is specified determine the top level domain * from the query. If the TLD is a number, query ARIN. Otherwise, use * TLD.whois-server.net. If the domain does not contain '.', fall * back to NICHOST. */ if (host == NULL && country == NULL) { use_qnichost = 1; host = NICHOST; if (!(flags & WHOIS_QUICK)) flags |= WHOIS_RECURSE; } while (argc-- > 0) { if (country != NULL) { s_asprintf(&qnichost, "%s%s", country, QNICHOST_TAIL); whois(*argv, qnichost, flags); } else if (use_qnichost) if ((qnichost = choose_server(*argv)) != NULL) whois(*argv, qnichost, flags); if (qnichost == NULL) whois(*argv, host, flags); free(qnichost); qnichost = NULL; argv++; } exit(0); return 0; }
http::response facebook_client::flap(RequestType request_type, std::string* request_data, std::string* request_get_data, int method) { NETLIBHTTPREQUEST nlhr = {sizeof(NETLIBHTTPREQUEST)}; nlhr.requestType = !method ? choose_method(request_type) : method; std::string url = choose_proto(request_type); url.append(choose_server(request_type, request_data, request_get_data)); url.append(choose_action(request_type, request_data, request_get_data)); nlhr.szUrl = (char*)url.c_str(); nlhr.flags = NLHRF_HTTP11 | choose_security_level(request_type); nlhr.headers = get_request_headers(nlhr.requestType, &nlhr.headersCount); #ifdef _DEBUG nlhr.flags |= NLHRF_DUMPASTEXT; #else nlhr.flags |= NLHRF_NODUMP; #endif switch (request_type) { case REQUEST_MESSAGES_RECEIVE: nlhr.timeout = 1000 * 65; break; default: nlhr.timeout = 1000 * 20; break; } if (request_data != NULL) { nlhr.pData = (char*)(*request_data).c_str(); nlhr.dataLength = (int)request_data->length(); } parent->debugLogA("@@@@@ Sending request to '%s'", nlhr.szUrl); switch (request_type) { case REQUEST_LOGIN: nlhr.nlc = NULL; break; case REQUEST_MESSAGES_RECEIVE: nlhr.nlc = hMsgCon; nlhr.flags |= NLHRF_PERSISTENT; break; default: WaitForSingleObject(fcb_conn_lock_, INFINITE); nlhr.nlc = hFcbCon; nlhr.flags |= NLHRF_PERSISTENT; break; } NETLIBHTTPREQUEST* pnlhr = (NETLIBHTTPREQUEST*)CallService(MS_NETLIB_HTTPTRANSACTION, (WPARAM)handle_, (LPARAM)&nlhr); mir_free(nlhr.headers[3].szValue); mir_free(nlhr.headers); http::response resp; switch (request_type) { case REQUEST_LOGIN: case REQUEST_SETUP_MACHINE: break; case REQUEST_MESSAGES_RECEIVE: hMsgCon = pnlhr ? pnlhr->nlc : NULL; break; default: ReleaseMutex(fcb_conn_lock_); hFcbCon = pnlhr ? pnlhr->nlc : NULL; break; } if (pnlhr != NULL) { parent->debugLogA("@@@@@ Got response with code %d", pnlhr->resultCode); store_headers(&resp, pnlhr->headers, pnlhr->headersCount); resp.code = pnlhr->resultCode; resp.data = pnlhr->pData ? pnlhr->pData : ""; CallService(MS_NETLIB_FREEHTTPREQUESTSTRUCT, 0, (LPARAM)pnlhr); } else { parent->debugLogA("!!!!! No response from server (time-out)"); resp.code = HTTP_CODE_FAKE_DISCONNECTED; // Better to have something set explicitely as this value is compaired in all communication requests } // Get Facebook's error message if (resp.code == HTTP_CODE_OK) { std::string::size_type pos = resp.data.find("\"error\":"); if (pos != std::string::npos) { pos += 8; int error_num = atoi(resp.data.substr(pos, resp.data.find(",", pos) - pos).c_str()); if (error_num != 0) { std::string error = ""; pos = resp.data.find("\"errorDescription\":\"", pos); if (pos != std::string::npos) { pos += 20; error = resp.data.substr(pos, resp.data.find("\"", pos) - pos); error = utils::text::trim(utils::text::special_expressions_decode(utils::text::slashu_to_utf8(error))); error = ptrA( mir_utf8decodeA(error.c_str())); } std::string title = ""; pos = resp.data.find("\"errorSummary\":\"", pos); if (pos != std::string::npos) { pos += 16; title = resp.data.substr(pos, resp.data.find("\"", pos) - pos); title = utils::text::trim(utils::text::special_expressions_decode(utils::text::slashu_to_utf8(title))); title = ptrA( mir_utf8decodeA(title.c_str())); } bool silent = resp.data.find("\"silentError\":1") != std::string::npos; resp.error_number = error_num; resp.error_text = error; resp.error_title = title; resp.code = HTTP_CODE_FAKE_ERROR; parent->debugLogA(" ! ! Received Facebook error: %d -- %s", error_num, error.c_str()); if (notify_errors(request_type) && !silent) client_notify(_A2T(error.c_str())); } } } return resp; }
http::response Omegle_client::flap(const int request_type, std::string *post_data, std::string *get_data) { http::response resp; // Prepare the request NETLIBHTTPREQUEST nlhr = { sizeof(NETLIBHTTPREQUEST) }; // Set request URL std::string url = choose_server(request_type) + choose_action(request_type, get_data); nlhr.szUrl = (char*)url.c_str(); // Set timeout (bigger for channel request) nlhr.timeout = 1000 * ((request_type == OMEGLE_REQUEST_EVENTS) ? 65 : 20); // Set request type (GET/POST) and eventually also POST data if (post_data != NULL) { nlhr.requestType = REQUEST_POST; nlhr.pData = (char*)(*post_data).c_str(); nlhr.dataLength = (int)post_data->length(); } else { nlhr.requestType = REQUEST_GET; } // Set headers - it depends on requestType so it must be after setting that nlhr.headers = get_request_headers(nlhr.requestType, &nlhr.headersCount); // Set flags nlhr.flags = NLHRF_HTTP11; #ifdef _DEBUG nlhr.flags |= NLHRF_DUMPASTEXT; #else nlhr.flags |= NLHRF_NODUMP; #endif // Set persistent connection (or not) switch (request_type) { case OMEGLE_REQUEST_HOME: nlhr.nlc = NULL; break; case OMEGLE_REQUEST_EVENTS: nlhr.nlc = hEventsConnection; nlhr.flags |= NLHRF_PERSISTENT; break; default: WaitForSingleObject(connection_lock_, INFINITE); nlhr.nlc = hConnection; nlhr.flags |= NLHRF_PERSISTENT; break; } parent->debugLogA("@@@@@ Sending request to '%s'", nlhr.szUrl); // Send the request NETLIBHTTPREQUEST *pnlhr = (NETLIBHTTPREQUEST*)CallService(MS_NETLIB_HTTPTRANSACTION, (WPARAM)handle_, (LPARAM)&nlhr); mir_free(nlhr.headers); // Remember the persistent connection handle (or not) switch (request_type) { case OMEGLE_REQUEST_HOME: break; case OMEGLE_REQUEST_EVENTS: hEventsConnection = pnlhr ? pnlhr->nlc : NULL; break; default: ReleaseMutex(connection_lock_); hConnection = pnlhr ? pnlhr->nlc : NULL; break; } // Check and copy response data if (pnlhr != NULL) { parent->debugLogA("@@@@@ Got response with code %d", pnlhr->resultCode); store_headers(&resp, pnlhr->headers, pnlhr->headersCount); resp.code = pnlhr->resultCode; resp.data = pnlhr->pData ? pnlhr->pData : ""; parent->debugLogA("&&&&& Got response: %s", resp.data.c_str()); CallService(MS_NETLIB_FREEHTTPREQUESTSTRUCT, 0, (LPARAM)pnlhr); } else { parent->debugLogA("!!!!! No response from server (time-out)"); resp.code = HTTP_CODE_FAKE_DISCONNECTED; // Better to have something set explicitely as this value is compaired in all communication requests } return resp; }
int main (int argc, char *argv[]) { GtkWidget *dialog; char *command; char *version; char *ret; const char *message; GOptionContext *ctx; bindtextdomain (GETTEXT_PACKAGE, GNOMELOCALEDIR); bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8"); textdomain (GETTEXT_PACKAGE); /* Option parsing */ ctx = g_option_context_new ("- New mdm login"); g_option_context_add_main_entries (ctx, options, _("main options")); g_option_context_parse (ctx, &argc, &argv, NULL); g_option_context_free (ctx); if (monte_carlo_pi) { calc_pi (); return 0; } mdm_log_init (); mdm_log_set_debug (debug_in); if (args_remaining != NULL && args_remaining[0] != NULL) server = args_remaining[0]; if (send_command != NULL) { if ( ! mdmcomm_check (FALSE)) { mdm_common_error (_("Error: MDM (MDM Display Manager) is not running.")); mdm_common_error (_("You might be using a different display manager.")); return 1; } } else { /* * The --command argument does not display anything, so avoid * running gtk_init until it finishes. Sometimes the * --command argument is used when there is no display so it * will fail and cause the program to exit, complaining about * "no display". */ gtk_init (&argc, &argv); if ( ! mdmcomm_check (TRUE)) { return 1; } } /* Start reading config data in bulk */ mdmcomm_comm_bulk_start (); /* Process --command option */ g_type_init (); if (send_command != NULL) { /* gdk_init is needed for cookie code to get display */ gdk_init (&argc, &argv); if (authenticate) auth_cookie = mdmcomm_get_auth_cookie (); /* * If asking for a translatable config value, then try to get * the translated value first. If this fails, then go ahead * and call the normal sockets command. */ if (strncmp (send_command, MDM_SUP_GET_CONFIG " ", strlen (MDM_SUP_GET_CONFIG " ")) == 0) { gchar *value = NULL; const char *key = &send_command[strlen (MDM_SUP_GET_CONFIG " ")]; if (is_key (MDM_KEY_WELCOME, key) || is_key (MDM_KEY_REMOTE_WELCOME, key)) { value = mdm_config_get_translated_string ((gchar *)key); if (value != NULL) { ret = g_strdup_printf ("OK %s", value); } } /* * If the above didn't return a value, then must be a * different key, so call mdmcomm_call_mdm. */ if (value == NULL) ret = mdmcomm_call_mdm (send_command, auth_cookie, "1.0.0.0", 5); } else { ret = mdmcomm_call_mdm (send_command, auth_cookie, "1.0.0.0", 5); } /* At this point we are done using the socket, so close it */ mdmcomm_comm_bulk_stop (); if (ret != NULL) { g_print ("%s\n", ret); return 0; } else { dialog = hig_dialog_new (NULL /* parent */, GTK_DIALOG_MODAL /* flags */, GTK_MESSAGE_ERROR, GTK_BUTTONS_OK, _("Cannot communicate with MDM " "(The MDM Display Manager)"), _("Perhaps you have an old version " "of MDM running.")); gtk_widget_show_all (dialog); gtk_dialog_run (GTK_DIALOG (dialog)); gtk_widget_destroy (dialog); return 1; } } /* * Now process what mdmflexiserver is more frequently used to * do, start VT (Virtual Terminal) sesions - at least on * systems where it is supported. On systems where it is not * supporteed VT stands for "Very Tight" and will mess up your * display if you use it. Tight! So do not use it. * * I would accept a patch to disable it on such systems, but it * is easy to avoid not using it as long as your distro does not * put the menu choice in the application launch button on the * panel (don't ship the desktop file). */ /* * Always attempt to get cookie and authenticate. On remote * servers */ auth_cookie = mdmcomm_get_auth_cookie (); if (use_xnest) { char *cookie = mdmcomm_get_a_cookie (FALSE /* binary */); if (cookie == NULL) { /* At this point we are done using the socket, so close it */ mdmcomm_comm_bulk_stop (); dialog = hig_dialog_new (NULL /* parent */, GTK_DIALOG_MODAL /* flags */, GTK_MESSAGE_ERROR, GTK_BUTTONS_OK, _("You do not seem to have the " "authentication needed for this " "operation"), _("Perhaps your .Xauthority " "file is not set up correctly.")); gtk_widget_show_all (dialog); gtk_dialog_run (GTK_DIALOG (dialog)); gtk_widget_destroy (dialog); return 1; } command = g_strdup_printf (MDM_SUP_FLEXI_XNEST " %s %d %s %s", mdmcomm_get_display (), (int)getuid (), cookie, XauFileName ()); g_free (cookie); version = "1.0.0.0"; auth_cookie = NULL; } else { /* check for other displays/logged in users */ check_for_users (); if (auth_cookie == NULL) { /* At this point we are done using the socket, so close it */ mdmcomm_comm_bulk_stop (); dialog = hig_dialog_new (NULL /* parent */, GTK_DIALOG_MODAL /* flags */, GTK_MESSAGE_ERROR, GTK_BUTTONS_OK, _("You do not seem to be logged in on the " "console"), _("Starting a new login only " "works correctly on the console.")); gtk_dialog_set_has_separator (GTK_DIALOG (dialog), FALSE); gtk_widget_show_all (dialog); gtk_dialog_run (GTK_DIALOG (dialog)); gtk_widget_destroy (dialog); return 1; } read_servers (); server = choose_server (); if (server == NULL) command = g_strdup (MDM_SUP_FLEXI_XSERVER); else command = g_strdup_printf (MDM_SUP_FLEXI_XSERVER " %s", server); version = "1.0.0.0"; } ret = mdmcomm_call_mdm (command, auth_cookie, version, 5); g_free (command); g_free (auth_cookie); g_strfreev (args_remaining); /* At this point we are done using the socket, so close it */ mdmcomm_comm_bulk_stop (); if (ret != NULL && strncmp (ret, "OK ", 3) == 0) { /* if we switched to a different screen as a result of this, * lock the current screen */ if ( ! no_lock && ! use_xnest) { maybe_lock_screen (); } /* all fine and dandy */ g_free (ret); return 0; } message = mdmcomm_get_error_message (ret, use_xnest); dialog = hig_dialog_new (NULL /* parent */, GTK_DIALOG_MODAL /* flags */, GTK_MESSAGE_ERROR, GTK_BUTTONS_OK, _("Cannot start new display"), message); gtk_widget_show_all (dialog); gtk_dialog_run (GTK_DIALOG (dialog)); gtk_widget_destroy (dialog); g_free (ret); return 1; }
int main(int argc, char *argv[]) { int ch, flags, rval; char *host, *name, *country; country = host = NULL; flags = rval = 0; while ((ch = getopt(argc, argv, "aAc:dgh:ilmp:PqQrR")) != -1) switch (ch) { case 'a': host = ANICHOST; break; case 'A': host = PNICHOST; break; case 'c': country = optarg; break; case 'd': host = DNICHOST; break; case 'g': host = GNICHOST; break; case 'h': host = optarg; break; case 'i': host = INICHOST; break; case 'l': host = LNICHOST; break; case 'm': host = MNICHOST; break; case 'p': port_whois = optarg; break; case 'P': host = PDBHOST; break; case 'q': /* deprecated, now the default */ break; case 'Q': flags |= WHOIS_QUICK; break; case 'r': host = RNICHOST; break; case 'R': host = RUNICHOST; break; default: usage(); } argc -= optind; argv += optind; if (!argc || (country != NULL && host != NULL)) usage(); if (host == NULL && country == NULL && !(flags & WHOIS_QUICK)) flags |= WHOIS_RECURSE; for (name = *argv; (name = *argv) != NULL; argv++) rval += whois(name, host ? host : choose_server(name, country), port_whois, flags); exit(rval); }
int main(int argc, char *argv[]) { const char *country, *host; int ch, flags; #ifdef SOCKS SOCKSinit(argv[0]); #endif country = host = NULL; flags = 0; while ((ch = getopt(argc, argv, "aAbc:fgh:iIklmp:PQrRS")) != -1) { switch (ch) { case 'a': host = ANICHOST; break; case 'A': host = PNICHOST; break; case 'b': host = ABUSEHOST; break; case 'c': country = optarg; break; case 'f': host = FNICHOST; break; case 'g': host = GNICHOST; break; case 'h': host = optarg; break; case 'i': host = INICHOST; break; case 'I': host = IANAHOST; break; case 'k': host = KNICHOST; break; case 'l': host = LNICHOST; break; case 'm': host = MNICHOST; break; case 'p': port = optarg; break; case 'P': host = PDBHOST; break; case 'Q': flags |= WHOIS_QUICK; break; case 'r': host = RNICHOST; break; case 'R': flags |= WHOIS_RECURSE; break; case 'S': flags |= WHOIS_SPAM_ME; break; case '?': default: usage(); /* NOTREACHED */ } } argc -= optind; argv += optind; if (!argc || (country != NULL && host != NULL)) usage(); /* * If no host or country is specified, rely on referrals from IANA. */ if (host == NULL && country == NULL) { if ((host = getenv("WHOIS_SERVER")) == NULL && (host = getenv("RA_SERVER")) == NULL) { if (!(flags & WHOIS_QUICK)) flags |= WHOIS_RECURSE; } } while (argc-- > 0) { if (country != NULL) { char *qnichost; s_asprintf(&qnichost, "%s%s", country, QNICHOST_TAIL); whois(*argv, qnichost, flags); free(qnichost); } else whois(*argv, host != NULL ? host : choose_server(*argv), flags); argv++; } exit(0); }
int main (int argc, char **argv) { rcComm_t *conn = NULL; rodsEnv irods_env; rErrMsg_t err_msg; dataObjInp_t data_obj; openedDataObjInp_t open_obj; int open_fd; char *new_host = NULL; int status; char *obj_name = NULL; char *buffer; char prog_name[255]; size_t buf_size = DEFAULT_BUFFER_SIZE; int verbose = 0; int opt; unsigned long total_written = 0; int write_to_irods = 1; int server_set = 0; while ((opt = getopt(argc, argv, "b:vhrdw")) != -1) { switch (opt) { case 'b': buf_size = atoi(optarg); if (buf_size <= 0) { error_and_exit(conn, "Error: buffer size must be greater than 0.\n"); } break; case 'v': verbose = 1; break; case 'r': write_to_irods = 0; break; case 'w': // dummy write option to be enforced later break; case 'd': server_set = 1; break; case 'h': usage_and_exit(argv[0], EXIT_SUCCESS); break; default: usage_and_exit(argv[0], EXIT_FAILURE); break; } } if (optind >= argc) { fprintf(stderr, "Error: Missing iRODS file.\n"); usage_and_exit(argv[0], EXIT_FAILURE); } obj_name = argv[optind]; if ((buffer = malloc(buf_size)) == NULL) { error_and_exit(conn, "Error: unable to set buffer to size %ld\n", buf_size); } // set the client name so iRODS knows what program is connecting to it sprintf(prog_name, "%s:%s", PACKAGE_NAME, PACKAGE_VERSION); if (verbose) { fprintf(stderr, "Setting client name to: %s\n", prog_name); } setenv(SP_OPTION, prog_name, 1); // lets get the irods environment if ((status = getRodsEnv(&irods_env)) < 0) { error_and_exit(conn, "Error: getRodsEnv failed with status %d:%s\n", status, get_irods_error_name(status, verbose)); } if ((status = irods_uri_check(obj_name, &irods_env, verbose)) < 0) { error_and_exit(conn, "Error: invalid uri: %s\n", obj_name); } else if (status > 0) { server_set = 1; } if (verbose) { fprintf(stderr, "host %s\nzone %s\nuser %s\nport %d\n", irods_env.rodsHost, irods_env.rodsZone, irods_env.rodsUserName, irods_env.rodsPort); } #if IRODS_VERSION_INTEGER && IRODS_VERSION_INTEGER >= 4001008 init_client_api_table(); #endif // make the irods connections conn = rcConnect(irods_env.rodsHost, irods_env.rodsPort, irods_env.rodsUserName, irods_env.rodsZone, 0, &err_msg); if (!conn) { print_irods_error("Error: rcConnect failed:", &err_msg); exit(EXIT_FAILURE); } #if IRODS_VERSION_INTEGER && IRODS_VERSION_INTEGER >= 4001008 status = clientLogin(conn, "", ""); #else status = clientLogin(conn); #endif if (status < 0) { error_and_exit(conn, "Error: clientLogin failed with status %d:%s\n", status, get_irods_error_name(status, verbose)); } // set up the data object memset(&data_obj, 0, sizeof(data_obj)); strncpy(data_obj.objPath, obj_name, MAX_NAME_LEN); if (write_to_irods) { data_obj.openFlags = O_WRONLY; } else { data_obj.openFlags = O_RDONLY; } data_obj.dataSize = 0; // talk to server if (write_to_irods) { if (!server_set) { if ((status = rcGetHostForPut(conn, &data_obj, &new_host)) < 0) { error_and_exit(conn, "Error: rcGetHostForPut failed with status %d:%s\n", status, get_irods_error_name(status, verbose)); } choose_server(&conn, new_host, &irods_env, verbose); free(new_host); } if ((open_fd = rcDataObjCreate(conn, &data_obj)) < 0) { error_and_exit(conn, "Error: rcDataObjCreate failed with status %d:%s\n", open_fd, get_irods_error_name(open_fd, verbose)); } } else { if (!server_set) { if ((status = rcGetHostForGet(conn, &data_obj, &new_host)) < 0) { error_and_exit(conn, "Error: rcGetHostForGet failed with status %d:%s\n", status, get_irods_error_name(status, verbose)); } choose_server(&conn, new_host, &irods_env, verbose); free(new_host); } if ((open_fd = rcDataObjOpen(conn, &data_obj)) < 0) { error_and_exit(conn, "Error: rcDataObjOpen failed with status %d:%s\n", open_fd, get_irods_error_name(open_fd, verbose)); } } // the read/write loop while (1) { bytesBuf_t data_buffer; long read_in; long written_out; // set up common data elements memset(&open_obj, 0, sizeof(open_obj)); open_obj.l1descInx = open_fd; data_buffer.buf = buffer; // time to read something if (write_to_irods) { read_in = fread(buffer, 1, buf_size, stdin); open_obj.len = read_in; data_buffer.len = open_obj.len; } else { open_obj.len = buf_size; data_buffer.len = open_obj.len; if ((read_in = rcDataObjRead(conn, &open_obj, &data_buffer)) < 0) { error_and_exit(conn, "Error: rcDataObjRead failed with status %ld:%s\n", read_in, get_irods_error_name(read_in, verbose)); } } if (verbose) { fprintf(stderr, "%ld bytes read\n", read_in); } if (!read_in) break; // now try and write something if (write_to_irods) { open_obj.len = read_in; data_buffer.len = open_obj.len; if ((written_out = rcDataObjWrite(conn, &open_obj, &data_buffer)) < 0) { error_and_exit(conn, "Error: rcDataObjWrite failed with status %ld\n", written_out, get_irods_error_name(written_out, verbose)); } } else { written_out = fwrite(buffer, 1, read_in, stdout); } if (verbose) { fprintf(stderr, "%ld bytes written\n", written_out); } total_written += written_out; if (read_in != written_out) { error_and_exit(conn, "Error: write fail %ld written, should be %ld.\n", written_out, read_in); } }; if (verbose) { fprintf(stderr, "Total bytes written %ld\n", total_written); } if ((status = rcDataObjClose(conn, &open_obj)) < 0) { error_and_exit(conn, "Error: rcDataObjClose failed with status %d:%s\n", status, get_irods_error_name(status, verbose)); } rcDisconnect(conn); free(buffer); exit(EXIT_SUCCESS); }