int do_add_merchants(int param) { int c; MERCHANTS merchants; char tmp[INFO_MAXINPUT + 1]; LOG(LOG_DEBUG, "执行添加商户信息功能..."); memset(&merchants, 0, sizeof(merchants)); INPUT_MID: printf("请输入[添加]商户编号:"); scanf("%s", tmp); while((c = getchar()) != '\n' && c != EOF);//清空缓存 if (strlen(tmp) != MID_SIZE || !isdigits(tmp, strlen(tmp))) { printf("输入数据必须是%d个数字!\n", MID_SIZE); goto INPUT_MID; } memcpy(merchants.mid, tmp, strlen(tmp)); INPUT_TID: printf("请输入终端编号:"); scanf("%s", tmp); while((c = getchar()) != '\n' && c != EOF);//清空缓存 if (strlen(tmp) != TID_SIZE || !isdigits(tmp, strlen(tmp))) { printf("输入数据必须是%d个数字!\n", TID_SIZE); goto INPUT_TID; } memcpy(merchants.tid, tmp, strlen(tmp)); INPUT_MNAME: printf("请输入商户名称:"); scanf("%s", tmp); while((c = getchar()) != '\n' && c != EOF);//清空缓存 if (strlen(tmp) > MNAME_MAXSIZE) { printf("输入数据不能超过%d个字节!\n", MNAME_MAXSIZE); goto INPUT_MNAME; } memcpy(merchants.mname, tmp, strlen(tmp)); INPUT_MMENU: printf("请输入商户菜单:"); scanf("%s", tmp); while((c = getchar()) != '\n' && c != EOF);//清空缓存 if (strlen(tmp) > MMENU_MAXSIZE) { printf("输入数据不能超过%d个字节!\n", MMENU_MAXSIZE); goto INPUT_MMENU; } memcpy(merchants.mmenu, tmp, strlen(tmp)); if (sel_db(IT_MERCHANTS, merchants.mid, 0)) { printf("添加商户:%s失败,商户已经存在!\n", merchants.mid); return -1; } if (!add_db(IT_MERCHANTS, MEMBERS_COUNT, merchants.mid, merchants.tid, merchants.mname, merchants.mmenu)) { printf("添加商户:%s失败!\n", merchants.mid); return -1; } else { printf("添加商户:%s成功。\n", merchants.mid); return 0; } }
int do_sel_merchants(int param) { int c; MERCHANTS merchants; char tmp[INFO_MAXINPUT + 1]; LOG(LOG_DEBUG, "执行查询商户信息功能..."); memset(&merchants, 0, sizeof(merchants)); INPUT_MID: printf("请输入[查询]的商户编号:"); scanf("%s", tmp); while((c = getchar()) != '\n' && c != EOF);//清空缓存 if (strlen(tmp) != MID_SIZE || !isdigits(tmp, strlen(tmp))) { printf("输入数据必须是%d个数字!\n", MID_SIZE); goto INPUT_MID; } if (!sel_db(IT_MERCHANTS, tmp, MEMBERS_COUNT, merchants.mid, merchants.tid, merchants.mname, merchants.mmenu)) { printf("查询商户:%s失败!\n", tmp); return -1; } else { printf("查询商户:%s成功。\n", tmp); printf("商户编号:%s\n", merchants.mid); printf("终端编号:%s\n", merchants.tid); printf("商户名称:%s\n", merchants.mname); printf("商户菜单:%s\n", merchants.mmenu); return 0; } }
void DeleteMessage(void) { char id[4]; int id_val; // read in the ID: zero(id, 4); print("ID: "); if (read_until(id, '\n', 4) == -1) { _terminate(-1); } if (strlen(id) == 0) { return; } if (!isdigits(id)) { return; } id_val = atoi(id); if (id_val > USERS[CURRENT_USER].top_message) { print("[-] Message ID out of range\n"); return; } zero(USERS[CURRENT_USER].messages[id_val], MAX_MESSAGE_LEN); return; }
void ReadMessage(void) { char id[4]; int id_val; // read in the ID: zero(id, 4); print("ID: "); if (read_until(id, '\n', 4) == -1) { _terminate(-1); } if (strlen(id) == 0) { return; } if (!isdigits(id)) { return; } id_val = atoi(id); if (id_val > USERS[CURRENT_USER].top_message) { print("[-] Message ID out of range\n"); return; } if (USERS[CURRENT_USER].messages[id_val][0] == '\0') { print("[-] Message ID not found\n"); return; } // print the message print("***********************************\n"); print(id); print(": "); print(USERS[CURRENT_USER].messages[id_val]); print("\n"); print("***********************************\n"); USERS[CURRENT_USER].msg_read[id_val] = 1; return; }
int do_del_merchants(int param) { int c; MERCHANTS merchants; char tmp[INFO_MAXINPUT + 1]; LOG(LOG_DEBUG, "执行删除商户信息功能..."); memset(&merchants, 0, sizeof(merchants)); INPUT_MID: printf("请输入[删除]的商户编号:"); scanf("%s", tmp); while((c = getchar()) != '\n' && c != EOF);//清空缓存 if (strlen(tmp) != MID_SIZE || !isdigits(tmp, strlen(tmp))) { printf("输入数据必须是%d个数字!\n", MID_SIZE); goto INPUT_MID; } if (!del_db(IT_MERCHANTS, tmp)) { printf("删除商户:%s失败!\n", tmp); return -1; } else { printf("删除商户:%s成功。\n", tmp); return 0; } }
int fromRsh() { int hosti,porti,hosto,porto; if( 0 < _fromRsh ) return 1; if( 0 > _fromRsh ) return 0; _fromRsh = -1; if( getenv("HOME") == NULL ) return 0; if( getenv("SHELL") == NULL ) return 0; if( file_issock(0) < 0 ) return 0; if( file_issock(1) < 0 ) return 0; if( getenv("SSH_CONNECTION") != 0 ){ if( sock_isAFUNIX(0) || sockFromMyself(0) || sock_isconnectedX(0,0) ){ _fromRsh = IS_SSH; return 0; } } /* if( file_issock(2) < 0 ) return 0; */ { int hostl,portl; hostl = sockHostport(0,&portl); /* * If this DeleGate is invoked from rshd, the port number must be * shell(cmd) == 514/tcp */ if( portl != 514 ){ return 0; } /* * Now this DeleGate might be working as a proxy rsh daemon. * It can be detected by peeking the first packet in rsh * protocol which will be a port number string in ASCII * terminated with '\0'. */ if( 0 < PollIn(0,100) ){ int rcc,ci; CStr(buf,8); rcc = recvPeekTIMEOUT(0,AVStr(buf),7); if( 0 < rcc ) if( buf[rcc-1] == '\0' ) if( isdigits(buf) ){ return 0; } } } hosti = peerHostport(0,&porti); if( hosti == -1 || porti<0 || porti<512 || 1023<porti ) return 0; hosto = peerHostport(1,&porto); if( hosto == -1 || porto<0 || porto<512 || 1023<porto ) return 0; if( hosti != hosto ) return 0; _fromRsh = 1; return 1; }
int main(int argc, char* argv[]) { int i; char* arg; char db_file[512]; // Setup default configuration for the execution opts.cmd = LAST_N; opts.c_recs = 10; opts.sleep = 1 * 1000; opts.verbose = FALSE; opts.db_file = db_file; opts.db = 0; opts._last_row_id = -1; trap_signals(); if(! find_db(db_file) ) error("Failed to find cislogs.sdb, set the " ENV_VAR " environment variable to the location to the file"); // Command line parsing for(i=1; i<argc; i++){ arg = argv[i]; if( arg[0] == '-' ) { arg++; if( strlen(arg) == 0 ) { continue; } else if( arg[0] == 'h' || arg[0] == '?' ) { usage(); } else if( isdigits(arg) ) { opts.c_recs = atoi(arg); } else if( strcmp("f",arg)==0 ) { opts.cmd = FOLLOW; } else if( strcmp("a",arg)==0 ) { opts.cmd = ALL; } else if( strcmp("v",arg)==0 ) { opts.verbose = TRUE; } else if( strcmp("V",arg)==0 ) { printf("Version: " VERSION "\n"); terminate(0); } else if( strcmp("s",arg)==0 ) { if( i+1 < argc) { arg = argv[++i]; if( !isdigits(arg) ) { error("sleep interval must be numeric"); } opts.sleep = atoi(arg) * 1000; if( opts.sleep <= 0 ) { error("sleep interval must be larger than zero"); } } else { error("Option \"-s N\" must have number of seconds as an argument"); } } else { error("Invalid option: %s", argv[i]); } } else { error("Invalid argument: %s", argv[i]); } } // END command line parsing if(opts.verbose) { printf("Using firewall db file: %s\n\n", opts.db_file); } tail(); terminate(0); }