int site_user_has_account(char *user, char *host, char *cluster) { int ret; int lineno; ret = check_and_read_config(ACCOUNTS, accounts_lines, &accounts_last_modification, &accounts_last_line); if (ret == -1) return CHECK_OK; /* for testing mode, when file not present */ /* file not found, unreadable, ... switch test off*/ if (accounts_last_line != -1) { /* there is good chance that the same user is checked */ ret = check_user(user, host, cluster, accounts_last_line); if (ret != CHECK_USER) return ret; } /* check all lines */ lineno = 0; while (accounts_lines[lineno] != NULL) { ret = check_user(user, host, cluster, lineno); if (ret != CHECK_USER) return ret; lineno++; } ret = CHECK_NO; /* user not found on any line */ return ret; }
int sys_write(int fd, const void *buffer, unsigned size) { // memory validation : [buffer+0, buffer+size) should be all valid check_user((const uint8_t*) buffer); check_user((const uint8_t*) buffer + size - 1); lock_acquire (&filesys_lock); int ret; if(fd == 1) { // write to stdout putbuf(buffer, size); ret = size; } else { // write into file struct file_desc* file_d = find_file_desc(thread_current(), fd, FD_FILE); if(file_d && file_d->file) { #ifdef VM preload_and_pin_pages(buffer, size); #endif ret = file_write(file_d->file, buffer, size); #ifdef VM unpin_preloaded_pages(buffer, size); #endif } else // no such file or can't open ret = -1; } lock_release (&filesys_lock); return ret; }
/** * Loaded tables are registered for processing events. * * \param[in] pIn inotify object * \param[in] pEd inotify event dispatcher * * \throw InotifyException thrown if base table directory cannot be read */ void load_tables(Inotify* pIn, EventDispatcher* pEd) throw (InotifyException) { DIR* d = opendir(INCRON_TABLE_BASE); if (d == NULL) throw InotifyException("cannot open table directory", errno); syslog(LOG_NOTICE, "loading user tables"); struct dirent* pDe = NULL; while ((pDe = readdir(d)) != NULL) { std::string un(pDe->d_name); if (pDe->d_type == DT_REG && un != "." && un != "..") { if (check_user(pDe->d_name)) { syslog(LOG_INFO, "loading table for user %s", pDe->d_name); UserTable* pUt = new UserTable(pIn, pEd, un); g_ut.insert(SUT_MAP::value_type(un, pUt)); pUt->Load(); } else { syslog(LOG_WARNING, "table for invalid user %s found (ignored)", pDe->d_name); } } } closedir(d); }
std::string impl::check_requirements(const atf::tests::vars_map& metadata, const atf::tests::vars_map& config) { std::string failure_reason = ""; for (atf::tests::vars_map::const_iterator iter = metadata.begin(); failure_reason.empty() && iter != metadata.end(); iter++) { const std::string& name = (*iter).first; const std::string& value = (*iter).second; INV(!value.empty()); // Enforced by application/X-atf-tp parser. if (name == "require.arch") failure_reason = check_arch(value); else if (name == "require.config") failure_reason = check_config(value, config); else if (name == "require.machine") failure_reason = check_machine(value); else if (name == "require.progs") failure_reason = check_progs(value); else if (name == "require.user") failure_reason = check_user(value, config); else { // Unknown require.* properties are forbidden by the // application/X-atf-tp parser. INV(failure_reason.find("require.") != 0); } } return failure_reason; }
void buy_me(void) { int code ; code = FGetBuyMe() ; if ( code == IDOK ) check_user() ; }
void test_check_user() { printf("\nTesting test_check_user\n"); struct passwd *user = check_user(username); if (user == NULL) { printf("FAIL: failed check for user %s\n", username); exit(1); } free(user); if (check_user("lp") != NULL) { printf("FAIL: failed check for system user lp\n"); exit(1); } if (check_user("root") != NULL) { printf("FAIL: failed check for system user root\n"); exit(1); } }
/*解析消息线程*/ void *pthread_func() { head_user = (struct user_info *)malloc(sizeof(struct user_info)); head_user->next = NULL; struct user_info *tmp; // 循环变量,用于便利在线用户链表将其发送给第一次登录的或者有刷新请求的客户端 struct servmsg *free_tmp; int ret= -1; while(1) { while(H->next != NULL) { // free_tmp = H; H = H->next; //消息头,处理玩就往后移动 // free(free_tmp);//将处理完的消息所占内存释放掉 // free_tmp = NULL; printf("消息链表首地址H :%p\n",H); printf("准备解析消息---\n"); printf("消息来自%s:\tIP:%s(%d)\n",H->recvmsg.self_name,inet_ntoa(H->addr.sin_addr),ntohs(H->addr.sin_port)); if(H->recvmsg.type == REGISTER) { register_user(); continue; } if(H->recvmsg.type == LOG_IN ) { check_user(); // if(find) { add_user(head_user,H);// add } continue; } if(H->recvmsg.type == REFRESH){ printf("%s刷新消息\n",H->recvmsg.self_name); //usleep(50000); send_all_online(H->addr); continue; } if (H->recvmsg.type == OFFLINE){ printf("%s下线\n",H->recvmsg.self_name); delete_user(H->recvmsg.self_name); } if (H->recvmsg.type == CHAT_PRI){ printf("%s私聊消息\n",H->recvmsg.self_name); printf("目标:%s\n",H->recvmsg.dst_name); chat_private(); } if(H->recvmsg.type == CHAT_ALL){ printf("%s群聊消息\n",H->recvmsg.self_name); chat_toall(); } printf("-----------------------------------\n"); }//end while(H) } }
bool sys_remove(const char* filename) { bool return_code; // memory validation check_user((const uint8_t*) filename); lock_acquire (&filesys_lock); return_code = filesys_remove(filename); lock_release (&filesys_lock); return return_code; }
bool sys_create(const char* filename, unsigned initial_size) { bool return_code; // memory validation check_user((const uint8_t*) filename); lock_acquire (&filesys_lock); return_code = filesys_create(filename, initial_size, false); lock_release (&filesys_lock); return return_code; }
int sys_read(int fd, void *buffer, unsigned size) { // memory validation : [buffer+0, buffer+size) should be all valid check_user((const uint8_t*) buffer); check_user((const uint8_t*) buffer + size - 1); lock_acquire (&filesys_lock); int ret; if(fd == 0) { // stdin unsigned i; for(i = 0; i < size; ++i) { if(! put_user(buffer + i, input_getc()) ) { lock_release (&filesys_lock); sys_exit(-1); // segfault } } ret = size; } else { // read from file struct file_desc* file_d = find_file_desc(thread_current(), fd, FD_FILE); if(file_d && file_d->file) { #ifdef VM preload_and_pin_pages(buffer, size); #endif ret = file_read(file_d->file, buffer, size); #ifdef VM unpin_preloaded_pages(buffer, size); #endif } else // no such file or can't open ret = -1; } lock_release (&filesys_lock); return ret; }
pid_t sys_exec(const char *cmdline) { _DEBUG_PRINTF ("[DEBUG] Exec : %s\n", cmdline); // cmdline is an address to the character buffer, on user memory // so a validation check is required check_user((const uint8_t*) cmdline); lock_acquire (&filesys_lock); // load() uses filesystem pid_t pid = process_execute(cmdline); lock_release (&filesys_lock); return pid; }
/** * function used to populate and user_details structure. */ int set_user(const char *user) { // free any old user if (user_detail != NULL) { free(user_detail); user_detail = NULL; } user_detail = check_user(user); if (user_detail == NULL) { return -1; } return change_effective_user(user_detail->pw_uid, user_detail->pw_gid); }
static void login(Request * request) { bool result = check_user(request->params[0], request->params[1]); ResponseStatus rs; if (result) { strcpy(username, request->params[0]); rs = SUCCESS; state = VERIFIED; } else { rs = FAILED; } send_response(rs, 0, NULL); }
void test_check_user(int expectedFailure) { printf("\nTesting test_check_user\n"); struct passwd *user = check_user(username); if (user == NULL && !expectedFailure) { printf("FAIL: failed check for user %s\n", username); exit(1); } free(user); if (check_user("lp") != NULL && !expectedFailure) { printf("FAIL: failed check for system user lp\n"); exit(1); } if (check_user("root") != NULL) { printf("FAIL: failed check for system user root\n"); exit(1); } if (check_user("daemon") == NULL && !expectedFailure) { printf("FAIL: failed check for whitelisted system user daemon\n"); exit(1); } }
void test_check_user() { printf("\nTesting test_check_user\n"); struct passwd *user = check_user(username); if (user == NULL) { printf("FAIL: failed check for user %s\n", username); exit(1); } free(user); if (check_user("lp") != NULL) { printf("FAIL: failed check for system user lp\n"); exit(1); } if (check_user("root") != NULL) { printf("FAIL: failed check for system user root\n"); exit(1); } #if !defined(__MACH__) // macosx do not have user bin if (check_user("bin") == NULL) { printf("FAIL: failed check for whitelisted system user bin\n"); exit(1); } #endif }
enum pat_match_res pat_match_auth(struct sample *smp, struct pattern *pattern) { struct userlist *ul = smp->ctx.a[0]; char *user = smp->ctx.a[1]; char *pass = smp->ctx.a[2]; unsigned int group_mask = pattern->val.group_mask; if (check_user(ul, group_mask, user, pass)) return PAT_MATCH; else return PAT_NOMATCH; }
int display_prompt(char **environ) { char *pwd; char *user; pwd = check_pwd(environ); user = check_user(environ); ft_putstr("$ "); ft_putstr(user); ft_putstr(" ~"); ft_putstr(pwd); ft_putstr(" > "); return ((int)(ft_strlen(user) + ft_strlen(pwd) + 7)); }
void *CUSER_get(CCONNECTION *conn, const char *name) { CUSER *_object; if (check_user(conn, name, TRUE)) return NULL; _object = GB.New(GB.FindClass("DatabaseUser"), NULL, NULL); THIS->conn = conn; THIS->driver = conn->driver; THIS->name = GB.NewZeroString(name); conn->driver->User.Info(&conn->db, THIS->name, &THIS->info); return THIS; }
static int enter_picld_wait(uid_t uid) { int rv; if (pthread_mutex_lock(&wait_req_mutex) != 0) return (PICL_FAILURE); if ((wait_count < MAX_CONCURRENT_WAITS) && (check_user(uid) == PICL_SUCCESS)) { rv = PICL_SUCCESS; wait_count++; } else { rv = PICL_FAILURE; } (void) pthread_mutex_unlock(&wait_req_mutex); return (rv); }
void login(int connSock,char mesg[], User user[], int max_user){ char account[LEN]; char pass[LEN]; char mesg2[LEN]; char *pch; int t,i; char buff_ok[LEN]="1|0|0|0|0|"; char buff_faile[LEN]="0|0|0|0|0|"; strcpy(mesg2,mesg); pch = strtok(mesg2,"|"); pch = strtok(NULL,"|"); pch = strtok(NULL,"|"); strcpy(account,""); strcpy(account,pch); pch = strtok(NULL,"|"); strcpy(pass,""); strcpy(pass,pch); t = check_user(account,pass,user,max_user); if(t == 1){ //thay doi trang thai cua user thanh online for(i=0;i<max_user;i++){ if(strcmp(account,user[i].account) == 0){ if(user[i].status == 1){ printf("Gui tin dang nhap that bai\n"); send(connSock, buff_faile, strlen(buff_faile), 0);//dang nhap that bai return; } else{ user[i].status = 1; user[i].sockfd = connSock; } break; } } printf("\nDoi trang thai thanh cong. Gui cho user\n"); send(connSock, buff_ok, strlen(buff_ok), 0);//gui lai cho client da dang nhap thanh cong printf("Done\n"); }else{ printf("\nDang nhap that bai!!"); send(connSock, buff_faile, strlen(buff_faile), 0);//dang nhap that bai } }
static int check_attempt(const abl_args *args, abl_info *info) { int err; time_t tm = time(NULL); if (info->user != NULL && info->service != NULL && info->host != NULL) { info->subject = HOST; err = check_host(args, info, tm); if (err) log_warning(args,"Failed to check host."); if (info->state == BLOCKED ) { /*No point in continuing since they've failed.*/ return 0; } info->subject = USER; err = check_user(args, info, tm); if (err) log_warning(args,"Failed to check user."); } return 0; }
/****************************************************************************** 函 数: my_register 功 能: 完成用户的注册工作 传入参数: confd : 服务器和客户端的通信接口 传出参数: 无 返 回: -1:程序错误返回 0:程序正确执行 ******************************************************************************/ int my_register(int confd, struct user *temp_user) { debug_msg("d: my_reg- %s",temp_user->name); char buf[MAXSIZE]; memset(buf,0,MAXSIZE); int n_write; /*判断用户名是否已经存在*/ if(check_user(temp_user->name) == 1) { strcpy(buf,"Sorry!Register failed, user has existed\n"); n_write = Write(confd,buf,strlen(buf)); if(n_write <= 0) { fputs("Write error in my_register\n",stderr); close(confd); return -1; } } else { pthread_mutex_lock(®_lock); //链表和文件操作地方上锁 write_in(temp_user); struct user_link *temp = user_node(temp_user,-1); insert_link(temp); pthread_mutex_unlock(®_lock); strcpy(buf,"Register success!\n"); n_write = Write(confd,buf,strlen(buf)); if(n_write <= 0) { fputs("Write error in my_register\n",stderr); close(confd); return -1; } } return 0; }
int sys_open(const char* file) { // memory validation check_user((const uint8_t*) file); struct file* file_opened; struct file_desc* fd = palloc_get_page(0); if (!fd) { return -1; } lock_acquire (&filesys_lock); file_opened = filesys_open(file); if (!file_opened) { palloc_free_page (fd); lock_release (&filesys_lock); return -1; } fd->file = file_opened; //file save // directory handling struct inode *inode = file_get_inode(fd->file); if(inode != NULL && inode_is_directory(inode)) { fd->dir = dir_open( inode_reopen(inode) ); } else fd->dir = NULL; struct list* fd_list = &thread_current()->file_descriptors; if (list_empty(fd_list)) { // 0, 1, 2 are reserved for stdin, stdout, stderr fd->id = 3; } else { fd->id = (list_entry(list_back(fd_list), struct file_desc, elem)->id) + 1; } list_push_back(fd_list, &(fd->elem)); lock_release (&filesys_lock); return fd->id; }
/** * function used to populate and user_details structure. */ int set_user(const char *user) { // free any old user if (user_detail != NULL) { free(user_detail); user_detail = NULL; } user_detail = check_user(user); if (user_detail == NULL) { return -1; } if (geteuid() == user_detail->pw_uid) { return 0; } if (initgroups(user, user_detail->pw_gid) != 0) { fprintf(LOGFILE, "Error setting supplementary groups for user %s: %s\n", user, strerror(errno)); return -1; } return change_effective_user(user_detail->pw_uid, user_detail->pw_gid); }
int main(int argc, char *argv[]){ check_user(); int c, mode = 1; //default promiscous mode with mode = 1 char *interface = NULL, *expression; bpf_u_int32 netaddr=0, mask=0; struct bpf_program filter; char errbuf[PCAP_ERRBUF_SIZE]; pcap_t *descr = NULL; struct pcap_pkthdr pkthdr; const unsigned char *packet= NULL; struct sigaction act; start_sniff = time(NULL); //start sniff time act.sa_sigaction = sighandler; act.sa_flags = SA_SIGINFO; //options management while((c = getopt(argc,argv,"m:hi:e:c::inv")) != -1){ switch(c){ case 'i': interface = optarg; break; case 'm': mode = atoi(optarg); break; case 'v': view = 1; //verbose break; case 'h': help(); break; case 'e': expression = optarg; break; case 'c': compute_sum = 1; break; case 'n': resolve_name = 1; break; } } if(expression != NULL && interface != NULL){ descr = pcap_open_live(interface, MAXCAPUTERBYTES, mode, 512, errbuf); if(descr == NULL){ perror(errbuf); exit(1); } if(pcap_lookupnet(interface,&netaddr,&mask,errbuf) == -1){ perror(errbuf); exit(1); } if(pcap_compile(descr, &filter, expression,1,mask) == -1){ perror(pcap_geterr(descr)); exit(1); } if(pcap_setfilter(descr,&filter) == -1){ perror(pcap_geterr(descr)); exit(1); } //action to bo taken when SIGINT occurs sigaction(SIGINT, &act, NULL); while(1){ //get packet packet = pcap_next(descr,&pkthdr); if(packet != NULL){ printf("\033[0;34mPacket #: %d\033[0m - Packet size: %d Bytes - %s", ++pktcount, pkthdr.len, ctime(&pkthdr.ts.tv_sec)); pkt_tot_size += pkthdr.len; print_packet(packet); } } } else{ fprintf(stderr,"Please choose an interface and a expression\n"); } return 0; }
/*{ ** Name: II_PrecheckInstallation - Pre-check installation environment ** ** Description: ** Verify that a machine environment will support the current release of ** Ingres. The following checks are made: **(E ** a. A minimum operating system version ** b. Other required software (currently none) ** c. Check the install path ** - exists ** - that user can write to it ** - does not have any disallowed characters (Windows only). **)E ** ** Inputs: ** response_file path to the Embedded Ingres response file. ** For more information concerning response file options ** please see the Ingres Embedded Edition User Guide. ** ** Outputs: ** error_msg Message text for status. If the message text exceeds ** MAX_IIERR_LEN then the message is truncated to ** MAX_IIERR_LEN. ** Unchanged if II_SUCCESSFUL is returned. ** ** Returns: ** II_SUCCESSFUL The environment test completed successfully ** II_NULL_PARAM The parameters passed are invalid ** II_NO_INSTALL_PATH Error reading response file or no II_SYSTEM entry ** II_CHARMAP_ERROR Error processing character mapping file ** II_GET_COMPUTER_FAIL Attempt to retrieve computer name failed ** II_INVALID_HOST Computer name contains illegal characters ** II_GET_HOST_FAILED Attempt to retrieve the network name failed ** II_INVALID_USER The username contains illegal characters ** II_UNMATCHED_NAME Computer name does not match network name ** II_OS_NOT_MIN_VERSION OS version does not meet the minimum requirement ** II_BAD_PATH The II_SYSTEM path is incorrectly formed ** II_INVAL_CHARS_IN_PATH The II_SYSTEM path contains illegal characters ** II_PATH_NOT_DIR The II_SYSTEM path is not a directory ** II_PATH_CANNOT_WRITE No write permission in the II_SYSTEM directory ** II_PATH_EXCEEDED Length of the path exceeds permitted maximum ** ** Example: ** # include "tngapi.h" ** ** # if defined(UNIX) ** II_CHAR reponsefile[] = {"./ingres.rsp"}; ** # else ** II_CHAR reponsefile[] = {".\\ingres.rsp"}; ** # endif ** II_INT4 status; ** II_CHAR error_msg[MAX_IIERR_LEN + 1] = { '\0' }; ** ** if ((status = II_PrecheckInstallation( responsefile, error_msg )) != ** II_SUCCESSFUL) ** { ** printf( "II_PrecheckInstallation failed - %s\n", error_msg ); ** } ** ** Side Effects: ** none ** ** History: ** 16-apr-2002 (abbjo03) ** Written. ** 11-Jul-2005 (fanra01) ** Add more specific status code from check_path_chars. */ int II_PrecheckInstallation( char *response_file, char *error_msg) { LOCATION loc; char buf[MAX_LOC]; char charmap[MAX_LOC+1]; LOINFORMATION loinfo; i4 flags; int result; CL_ERR_DESC clerr; if (!response_file || !error_msg) { result = II_NULL_PARAM; if (error_msg) II_GetErrorMessage(error_msgs[result], error_msg); return result; } if (!GetPrivateProfileString("Ingres Configuration", "II_SYSTEM", "", buf, sizeof(buf), response_file)) { result = II_NO_INSTALL_PATH; II_GetErrorMessage(error_msgs[result], error_msg); return result; } /* ** Get the charmap field from the response file. */ if (!GetPrivateProfileString("Ingres Configuration", II_CHARMAP, "", charmap, sizeof(charmap), response_file)) { result = II_NO_CHAR_MAP; II_GetErrorMessage(error_msgs[result], error_msg); return result; } /* ** Open and read the character map specified in the response file. ** This is a special installation character description file. */ #if defined(UNIX) if ((result = CMset_attr( charmap, &clerr )) != 0) #else if ((result = CMread_attr( II_CHARSET, charmap, &clerr )) != 0) #endif { result = II_CHARMAP_ERROR; II_GetErrorMessage( error_msgs[result], error_msg ); return(result); } if ((result = check_user()) != II_SUCCESSFUL) { II_GetErrorMessage( error_msgs[result], error_msg ); return(result); } if ((result = check_host()) != II_SUCCESSFUL) { II_GetErrorMessage( error_msgs[result], error_msg ); return(result); } if (check_platform( II_DEFARCH ) != OK) { result = II_OS_NOT_MIN_VERSION; II_GetErrorMessage(error_msgs[result], error_msg); return result; } if (LOfroms(PATH & FILENAME, buf, &loc) != OK) { result = II_BAD_PATH; II_GetErrorMessage(error_msgs[result], error_msg); return result; } flags = LO_I_TYPE | LO_I_PERMS; if (LOinfo(&loc, &flags, &loinfo) != OK) { result = II_BAD_PATH; II_GetErrorMessage(error_msgs[result], error_msg); return result; } if ((flags & LO_I_TYPE) == 0 || loinfo.li_type != LO_IS_DIR) { result = II_PATH_NOT_DIR; II_GetErrorMessage(error_msgs[result], error_msg); return result; } if ((flags & LO_I_PERMS) == 0 || (loinfo.li_perms & LO_P_WRITE) == 0) { result = II_PATH_CANNOT_WRITE; II_GetErrorMessage(error_msgs[result], error_msg); return result; } if (check_path_chars(&loc, &result)) { switch(result) { case LO_BAD_DEVICE: result = II_BAD_PATH; break; case LO_NOT_PATH: case LO_NOT_FILE: default: result = II_INVAL_CHARS_IN_PATH; break; } II_GetErrorMessage(error_msgs[result], error_msg); return result; } result = II_SUCCESSFUL; II_GetErrorMessage(error_msgs[result], error_msg); return result; }
/*{ ** Name: II_PrecheckInstallationEx - Extended installation environment pre-check ** ** Description: ** Verify that a machine environment will support the current release of ** Ingres. ** The following checks may be made by specifying the required set of flags: **(E ** ** a. Test for invalid characters in the machine hostname ** b. Test for invalid characters in the username ** c. A minimum operating system version ** d. Test that the path value supplied for II_SYSTEM ** i) does not contain disallowed characters (Windows only) ** ii) consists of an existing parent directory ** e. Test that the operating system user of the running process is granted ** permission to write in d.ii). ** f. The value of the instancecode field in the response file is tested ** for valid characters and character sequences. **)E ** ** The path check flags II_CHK_PATHDIR and II_CHK_PATHPERM may be combined ** (bit wise); they include an implicit II_CHK_PATHCHAR. All path checks ** implicitly include an II_CHK_PATHLEN flag. ** Use the II_CHK_ALL flag as a convenient shorthand to perform each of the ** tests together. ** Specifying a flag of zero will check for the existence of the ** II_SYSTEM entry in the response file. ** ** Inputs: ** eflags Specifies the pre-installation checks to be performed. ** Can be a combination of the following ** 0 Test for existence of II_SYSTEM entry ** in response file ** II_CHK_HOSTNAME Verify characters in machine name ** II_CHK_OSVERSION Verify minimum OS version ** II_CHK_PATHCHAR Check characters used in II_SYSTEM ** II_CHK_PATHDIR Check II_SYSTEM path for a valid ** existing directory ** II_CHK_PATHPERM Check path write permissions ** II_CHK_PATHLEN Check length of path not exceeded ** II_CHK_USERNAME Verify characters in user name ** II_CHK_INSTCODE Verify characters of the configured ** instance code ** II_CHK_ALL Equivalent to II_PrecheckInstallation ** call. ** architecture The value of architecture is used only if the ** II_CHK_VERSION flag is set in the eflags field. ** If the II_CHK_VERSION flag is set ** Let the value of architecture be set as follows: ** Case: ** - II_DEFVER determines if the suitability of ** the internal Ingres platform architecture ** is appropriate for the operating architecture. ** - Determines if the suitability of the defined ** value of architecture is appropriate for the ** operating architecture. ** If the II_CHK_VERSION flag is not set ** Let the value of architecture be set to II_DEFVER. ** ** response_file Path to the Embedded Ingres response file ** For more information concerning response file options ** please see the Ingres Embedded Edition User Guide. ** This function requires valid values for the II_SYSTEM and ** charmap entries. ** ** Outputs: ** error_msg Message text for status. If the message text exceeds ** MAX_IIERR_LEN then the message is truncated to ** MAX_IIERR_LEN. ** Unchanged if II_SUCCESSFUL is returned. ** ** Returns: ** II_SUCCESSFUL The environment test completed successfully ** II_NULL_PARAM The parameters passed are invalid ** II_NO_INSTALL_PATH Error reading response file or no II_SYSTEM entry ** II_NO_CHAR_MAP Error reading response file or no II_CHARMAP entry ** II_CHARMAP_ERROR Error processing character mapping file ** II_GET_COMPUTER_FAIL Attempt to retrieve computer name failed ** II_INVALID_HOST Computer name contains illegal characters ** II_GET_HOST_FAILED Attempt to retrieve the network name failed ** II_INVALID_USER The username contains illegal characters ** II_UNMATCHED_NAME Computer name does not match network name ** II_OS_NOT_MIN_VERSION OS version does not meet the minimum requirement ** II_BAD_PATH The II_SYSTEM path is incorrectly formed ** II_INVAL_CHARS_IN_PATH The II_SYSTEM path contains illegal characters ** II_PATH_NOT_DIR The II_SYSTEM path does not contain a valid ** directory ** II_PATH_CANNOT_WRITE No write permission in the II_SYSTEM directory or ** a parent directory. ** II_PATH_EXCEEDED Length of the path exceeds permitted maximum ** II_INVALID_INSTANCECODE Instance code contains illegal characters ** II_INSTANCE_ERROR Error reading instance code or no instancecode ** entry. ** ** Example: ** # include "tngapi.h" ** ** # if defined(UNIX) ** II_CHAR reponsefile[] = {"./ingres.rsp"}; ** # else ** II_CHAR reponsefile[] = {".\\ingres.rsp"}; ** # endif ** II_INT4 status; ** II_INT4 eflags = (II_CHK_HOSTNAME | II_CHK_OSVERSION | \ ** II_CHK_PATHCHAR | II_CHK_PATHDIR | II_CHK_PATHPERM | II_CHK_PATHLEN \ ** II_CHK_INSTCODE); ** II_CHAR error_msg[MAX_IIERR_LEN + 1] = { '\0' }; ** ** if ((status = II_PrecheckInstallationEx( eflags, II_DEFARCH, responsefile, ** error_msg )) != II_SUCCESSFUL) ** { ** printf( "II_PrecheckInstallationEx failed - %s\n", error_msg ); ** } ** ** if ((status = II_PrecheckInstallationEx( II_CHK_OSVERSION, II_IA64, ** responsefile, error_msg )) != II_SUCCESSFUL) ** { ** printf( "II_PrecheckInstallationEx failed - %s\n", error_msg ); ** if (status == II_OS_NOT_MIN_VERSION) ** { ** printf( "Target environment is unsuitable for IA64 binaries\n"); ** } ** } ** ** Side Effects: ** none ** ** History: ** 07-Sep-2004 (fanra01) ** Created based on II_PrecheckInstallation. ** 30-Jun-2005 (fanra01) ** Moved and extended path validation into check_path function. ** 18-Aug-2005 (fanra01) ** Include path length check on character map file. }*/ int II_PrecheckInstallationEx( int eflags, int architecture, char* response_file, char* error_msg ) { i4 status = II_SUCCESSFUL; i4 flags; i4 pathlen; LOCATION loc; LOINFORMATION loinfo; char buf[MAX_LOC + 3]; /* over size buffer to detect overrun */ char charmap[MAX_LOC + 3]; char ii_install[MAX_LOC + 3]; CL_ERR_DESC clerr; i4 pathchk = 0; while(TRUE) { if (!response_file || !error_msg) { status = II_NULL_PARAM; break; } if ((pathlen = GetPrivateProfileString( ERx("Ingres Configuration"), ERx("II_SYSTEM"), "", buf, sizeof(buf), response_file )) == 0) { status = II_NO_INSTALL_PATH; break; } else { if ((pathchk = (eflags & (II_CHK_PATHCHAR | II_CHK_PATHDIR | II_CHK_PATHPERM | II_CHK_PATHLEN))) && (pathlen > MAX_LOC)) { status = II_PATH_EXCEEDED; break; } } if (eflags & II_CHK_INSTCODE) { if ((pathlen = GetPrivateProfileString("Ingres Configuration", II_INSTCODE, "", ii_install, sizeof(ii_install), response_file)) == 0) { status = II_INSTANCE_ERROR; break; } else { if ((status = check_instcode( ii_install )) != II_SUCCESSFUL) { break; } } } if ((eflags & (II_CHK_HOSTNAME | II_CHK_USERNAME | pathchk)) && ((pathlen = GetPrivateProfileString("Ingres Configuration", II_CHARMAP, "", charmap, sizeof(charmap), response_file)) == 0)) { status = II_NO_CHAR_MAP; break; } else { if (eflags & (II_CHK_HOSTNAME | II_CHK_USERNAME | pathchk)) { if (pathlen > MAX_LOC) { status = II_PATH_EXCEEDED; break; } else { #if defined(UNIX) if ((status = CMset_attr( charmap, &clerr )) != 0) #else if ((status = CMread_attr( II_CHARSET, charmap, &clerr )) != 0) #endif { status = II_CHARMAP_ERROR; break; } } } } if ((eflags & II_CHK_HOSTNAME) && ((status = check_host()) != II_SUCCESSFUL)) { break; } if ((eflags & II_CHK_USERNAME) && ((status = check_user()) != II_SUCCESSFUL)) { break; } if ((eflags & II_CHK_OSVERSION) && (check_platform( architecture ) != OK)) { status = II_OS_NOT_MIN_VERSION; break; } /* ** Perform path validation test. */ if (eflags & (II_CHK_PATHCHAR | II_CHK_PATHDIR | II_CHK_PATHPERM)) { status = check_path( buf, eflags ); break; } break; } if ((status != II_SUCCESSFUL) && (error_msg != NULL)) { II_GetErrorMessage( error_msgs[status], error_msg ); } return(status); }
int main(int argc, char **argv) { int i, nbytes, sock; char user[40]={0x00}, *uname, *pass; unsigned int dest; unsigned short port; FILE *userlist, *outfile; uname = pass = NULL; outfile = userlist = NULL; port = htons(21); dest = -1; header(); if(argc == 1) help(argv[0]); for(i = 1; i < argc; i++) if(argv[i][0] == '-') switch(argv[i][1]) { case 'h': help(argv[0]); case 'P': printf("using destination port: %s\n",argv[++i]); port = htons(atoi(argv[i])); break; case 'U': printf("opening username list %s... ",argv[++i]); fflush(stdout); if(NULL == (userlist = fopen(argv[i], "r"))) { printf("faild!\n"); exit(-12); } printf("done.\n"); break; case 'u': printf("using username %s\n",argv[++i]); uname = argv[i]; break; case 'p': printf("using passoword %s\n",argv[++i]); pass = argv[i]; break; case 'o': printf("ouputfile: %s\n",argv[++i]); if(NULL == (outfile = fopen(argv[i],"r"))) { printf("cannot create outputfile!\n"); exit(-13); } break; default: printf("unknown option >>%s<<\n",argv[i]); printf("-h for help\n"); exit(-14); } else { printf("destination servers ip: %s\n",argv[i]); dest = inet_addr(argv[i]); } if(dest == -1) { printf("i need a destination ip, einstein\n"); exit(-15); } if(userlist == NULL) { printf("i need a userlist\n"); exit(-20); } if(outfile == NULL) if(NULL == (outfile = fopen("outputfile.log", "a"))) { printf("cannot create outputfile!\n"); exit(-21); } else printf("outputfile \"outputfile.log\" created.\n"); if(uname == NULL) { printf("try to log in as user ftp\n"); uname = "ftp"; } if(pass == NULL) { printf("try to log in with password [email protected]\n"); pass = "******"; } printf("\n\nconnecting to ftp service...\n"); sock = connect_ftp(dest, port, uname, pass); printf("check for viald target... ");fflush(stdout); if(!check_user(sock, "root")) { printf("faild! ftp is no viald target\n"); exit(-22); } else printf("success. ftp server is a viald target\n\n"); printf("\tstart grebbing for viald users...\n"); printf("\t---------------------------------\n"); while( (nbytes = fscanf(userlist, "%s",user)) != EOF) { fseek(userlist, nbytes, SEEK_CUR); printf("\tcheck user %s ----> ",user); if(check_user(sock, user)) { printf("EXISTS\n"); fprintf(outfile, "%s -> existing user:%s\n", inet_ntoa(dest), user); } else printf("no such user\n"); memset(user, 0x00, sizeof(user)); } printf("\t----------------------------------\n\n"); printf("my job is finished here. party on, partner!\n\n"); close(sock); return(0); }
/** * \param[in] argc argument count * \param[in] argv argument array * \return 0 on success, 1 on error * * \attention In daemon mode, it finishes immediately. */ int main(int argc, char** argv) { openlog(INCRON_DAEMON_NAME, INCRON_LOG_OPTS, INCRON_LOG_FACIL); syslog(LOG_NOTICE, "starting service (version %s, built on %s %s)", INCRON_VERSION, __DATE__, __TIME__); try { Inotify in; in.SetNonBlock(true); EventDispatcher ed(&in); try { load_tables(&in, &ed); } catch (InotifyException e) { int err = e.GetErrorNumber(); syslog(LOG_CRIT, "%s: (%i) %s", e.GetMessage().c_str(), err, strerror(err)); syslog(LOG_NOTICE, "stopping service"); closelog(); return 1; } signal(SIGTERM, on_signal); signal(SIGINT, on_signal); signal(SIGCHLD, on_signal); if (DAEMON) daemon(0, 0); uint32_t wm = IN_CLOSE_WRITE | IN_DELETE | IN_MOVE | IN_DELETE_SELF | IN_UNMOUNT; InotifyWatch watch(INCRON_TABLE_BASE, wm); in.Add(watch); syslog(LOG_NOTICE, "ready to process filesystem events"); InotifyEvent e; struct pollfd pfd; pfd.fd = in.GetDescriptor(); pfd.events = (short) POLLIN; pfd.revents = (short) 0; while (!g_fFinish) { int res = poll(&pfd, 1, -1); if (res > 0) { in.WaitForEvents(true); } else if (res < 0) { if (errno != EINTR) throw InotifyException("polling failed", errno, NULL); } UserTable::FinishDone(); while (in.GetEvent(e)) { if (e.GetWatch() == &watch) { if (e.IsType(IN_DELETE_SELF) || e.IsType(IN_UNMOUNT)) { syslog(LOG_CRIT, "base directory destroyed, exitting"); g_fFinish = true; } else if (!e.GetName().empty()) { SUT_MAP::iterator it = g_ut.find(e.GetName()); if (it != g_ut.end()) { UserTable* pUt = (*it).second; if (e.IsType(IN_CLOSE_WRITE) || e.IsType(IN_MOVED_TO)) { syslog(LOG_INFO, "table for user %s changed, reloading", e.GetName().c_str()); pUt->Dispose(); pUt->Load(); } else if (e.IsType(IN_MOVED_FROM) || e.IsType(IN_DELETE)) { syslog(LOG_INFO, "table for user %s destroyed, removing", e.GetName().c_str()); delete pUt; g_ut.erase(it); } } else if (e.IsType(IN_CLOSE_WRITE) || e.IsType(IN_MOVED_TO)) { if (check_user(e.GetName().c_str())) { syslog(LOG_INFO, "table for user %s created, loading", e.GetName().c_str()); UserTable* pUt = new UserTable(&in, &ed, e.GetName()); g_ut.insert(SUT_MAP::value_type(e.GetName(), pUt)); pUt->Load(); } } } } else { ed.DispatchEvent(e); } } } } catch (InotifyException e) { int err = e.GetErrorNumber(); syslog(LOG_CRIT, "*** unhandled exception occurred ***"); syslog(LOG_CRIT, " %s", e.GetMessage().c_str()); syslog(LOG_CRIT, " error: (%i) %s", err, strerror(err)); } syslog(LOG_NOTICE, "stopping service"); closelog(); return 0; }
int main() { string username; string password; string command; string subcommand; string temp_path; char t; load_user(); init(); save(); while (1) { SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY | FOREGROUND_GREEN); cout << "welcome to system" << endl; cout << "please login" << endl; SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY | FOREGROUND_BLUE | FOREGROUND_GREEN | FOREGROUND_RED); while (1) { username = ""; password = ""; cout << "username:"******"password:"******"username or password error" << endl; SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY | FOREGROUND_BLUE | FOREGROUND_GREEN | FOREGROUND_RED); } } system("cls"); getline(cin, command); while (1) { SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY | FOREGROUND_RED | FOREGROUND_BLUE); cout << username; SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY | FOREGROUND_GREEN | FOREGROUND_RED); cout << "@filesystem "; SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY | FOREGROUND_BLUE); if (path.size() == 1) cout << "/"; else { for (auto p : path) { if (p == 0) continue; cout << "/" << catalog[p].info.name; } } SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY | FOREGROUND_BLUE | FOREGROUND_GREEN | FOREGROUND_RED); cout << endl << ">"; getline(cin, command); stringstream command_stream(command); command_stream >> subcommand; if (subcommand == "") { } else if (subcommand == "cd") { change_path(command); } else if (subcommand == "ls") { show_folder(command); } else if (subcommand == "create") { create(command); } else if (subcommand == "mkdir") { create_folder(command); } else if (subcommand == "delete") { delete_file(command); } else if (subcommand == "edit") { edit(command); } else if (subcommand == "search") { search_file(command); } else if (subcommand == "open") { open_file(command); } else if (subcommand == "close") { close_file(command); } else if (subcommand == "cp") { copy(command); } else if (subcommand == "mv") { move(command); } else if (subcommand == "bs"){ backstage(); } else if (subcommand == "l"){ l(); } else if (subcommand == "info"){ info(); } else if (subcommand == "format") { char c; cout << "Are you sure you want to format the disk?(y/N)"; c = _getch(); if (c == 'n' || c == 'N' || c == '\r') { cout << c << endl; continue; } else if (c == 'y' || c == 'Y') { remove("disk.txt"); remove("diskdata.txt"); init(); cout << c << "\nformat complete" << endl; } } else if (subcommand == "useradd") { add_user(command); } else if (subcommand == "userdelete") { delete_user(command); } else if (subcommand == "passwd") { change_password(command); } else if (subcommand == "clear") { system("cls"); } else if (subcommand == "exit") { system("cls"); break; } else { SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY | FOREGROUND_RED); cout << "command not found" << endl; SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY | FOREGROUND_BLUE | FOREGROUND_GREEN | FOREGROUND_RED); } cout << endl; save(); command = ""; subcommand = ""; } } }