int main(void) { initialise_cells(); tremaux(); convert_unknown_to_walls(); create_matrix(); path_init(); printf("Will do dikstra from %d\n", find_current_cell()); dijkstra(find_current_cell(), 0); int z; for (z = 0; z < 16; z ++) { printf("%d ", short_path[z]); } follow_shortest(1); swap_direction('s'); move_forward(); swap_direction('n'); int i; for (i = 0; i < 3; i++) { high(26); pause(500); low(26); pause(500); } move_forward(); path_init(); dijkstra(0, 15); follow_shortest(0); for (i = 0; i < 3; i++) { high(26); pause(500); low(26); pause(500); } return 0; }
void setup (void) { head = path_init(5.0, 5.0); path_append(6.0, 6.0); path_append(7.0, 7.0); }
Node * path_append(float x, float y) { if (x < 0.0 || y < 0.0) { return curr; } if (NULL == path) { return path_init(x, y); } pNode ptr = (pNode)malloc(sizeof(Node)); if (NULL == ptr) { printf("\n Path append failed \n"); return NULL; } ptr->x = x; ptr->y = y; ptr->next = NULL; curr->next = ptr; curr = ptr; return ptr; }
/* Lookup name and return vnode for same. */ int osi_lookupname_internal(char *aname, int followlink, struct vfsmount **mnt, struct dentry **dpp) { int code; struct nameidata nd; int flags = LOOKUP_POSITIVE; code = ENOENT; if (followlink) flags |= LOOKUP_FOLLOW; if (path_init(aname, flags, &nd)) code = path_walk(aname, &nd); if (!code) { #if defined(STRUCT_NAMEIDATA_HAS_PATH) *dpp = dget(nd.path.dentry); if (mnt) *mnt = mntget(nd.path.mnt); path_put(&nd.path); #else *dpp = dget(nd.dentry); if (mnt) *mnt = mntget(nd.mnt); path_release(&nd); #endif } return code; }
int dm_path_to_fshdl( char *path, /* any path name */ void *hanp, /* user's data buffer */ size_t *hlenp) /* set to size of data copied */ { /* REFERENCED */ dm_fsreg_t *fsrp; xfs_handle_t handle; vnode_t *vp; size_t hlen; int error; int lc; /* lock cookie */ struct nameidata nd; struct inode *inode; size_t len; char *name; /* XXX get things straightened out so getname() works here? */ len = strnlen_user(path, 2000); name = kmem_alloc(len, KM_SLEEP); if (copy_from_user(name, path, len)) return(EFAULT); error = 0; if (path_init(name, LOOKUP_POSITIVE|LOOKUP_FOLLOW, &nd)) error = path_walk(name, &nd); if (error) return error; kmem_free(name, len); ASSERT(nd.dentry); ASSERT(nd.dentry->d_inode); inode = igrab(nd.dentry->d_inode); path_release(&nd); /* we need the vnode */ vp = LINVFS_GET_VP(inode); if (!vp || !vp->v_vfsp->vfs_altfsid) { /* we're not in XFS anymore, Toto */ iput(inode); return EINVAL; } error = dm_vp_to_handle(vp, &handle); iput(inode);/*was VN_RELE(vp);*/ if (error) return(error); if ((fsrp = dm_find_fsreg_and_lock((fsid_t*)&handle.ha_fsid, &lc)) == NULL) return(EBADF); mutex_spinunlock(&fsrp->fr_lock, lc); hlen = FSHSIZE; if(copy_to_user(hanp, &handle, (int)hlen)) return(EFAULT); return(put_user(hlen,hlenp)); }
asmlinkage long sys_chdir(const char * filename) { int error; struct nameidata nd; char *name; name = getname(filename); error = PTR_ERR(name); if (IS_ERR(name)) goto out; error = 0; if (path_init(name,LOOKUP_POSITIVE|LOOKUP_FOLLOW|LOOKUP_DIRECTORY,&nd)) error = path_walk(name, &nd); putname(name); if (error) goto out; error = permission(nd.dentry->d_inode,MAY_EXEC); if (error) goto dput_and_out; set_fs_pwd(current->fs, nd.mnt, nd.dentry); dput_and_out: path_release(&nd); out: return error; }
static int backupProc( const std::vector<std::string> &args ) { if ( args.size() < 3 ) { std::cout << "gitbk backup src dest" << std::endl; return 1; } if ( !boost::filesystem::is_directory( args[1] ) ) { std::cout << '\'' << args[1] << "' is not directory!" << std::endl; return 1; } path_init( args[args.size()-1] ); load_hash_set( ); hash_mutex = new boost::shared_mutex; std::auto_ptr<boost::shared_mutex> mp( hash_mutex ); for ( unsigned i = 1; i < args.size()-1; ++i ) backup( args[i] ); free_hash_set( ); return 0; }
asmlinkage long sys_chroot(const char * filename) { int error; struct nameidata nd; char *name; name = getname(filename); error = PTR_ERR(name); if (IS_ERR(name)) goto out; path_init(name, LOOKUP_POSITIVE | LOOKUP_FOLLOW | LOOKUP_DIRECTORY | LOOKUP_NOALT, &nd); error = path_walk(name, &nd); putname(name); if (error) goto out; error = permission(nd.dentry->d_inode,MAY_EXEC); if (error) goto dput_and_out; error = -EPERM; if (!capable(CAP_SYS_CHROOT)) goto dput_and_out; set_fs_root(current->fs, nd.mnt, nd.dentry); set_fs_altroot(); error = 0; dput_and_out: path_release(&nd); out: return error; }
/** Main initialisation. */ static void main_init (void) { #ifndef HOST /* Disable watchdog (enabled in bootloader). */ MCUSR &= ~(1 << WDRF); wdt_disable (); #endif /* Serial port */ uart0_init (); /* Enable interrupts */ sei (); /* Main timer */ timer_init (); timer_wait (); /* TWI communications */ asserv_init (); mimot_init (); twi_master_init (); /* IO modules. */ pwm_init (); contact_init (); codebar_init (); usdist_init (); /* AI modules. */ clamp_init (); logistic_init (); path_init (); /* Initialization done. */ proto_send0 ('z'); }
Test *test_new(SpiceCoreInterface *core) { int port = 5912; Test *test = spice_new0(Test, 1); SpiceServer* server = spice_server_new(); test->qxl_instance.base.sif = &display_sif.base; test->qxl_instance.id = 0; test->core = core; test->server = server; test->wakeup_ms = 1; test->cursor_notify = NOTIFY_CURSOR_BATCH; // some common initialization for all display tests printf("TESTER: listening on port %d (unsecure)\n", port); spice_server_set_port(server, port); spice_server_set_noauth(server); spice_server_init(server, core); cursor_init(); path_init(&path, 0, angle_parts); test->has_secondary = 0; test->wakeup_timer = core->timer_add(do_wakeup, test); return test; }
void pathwin_add_wpt(double x, double y) { printf("\npath.c add"); if (!wpt_path) wpt_path = path_init(); path_addpt(wpt_path, x, y, 0.0); }
static void john_init(char *name, int argc, char **argv) { int make_check = (argc == 2 && !strcmp(argv[1], "--make_check")); if (make_check) argv[1] = "--test=0"; #if CPU_DETECT if (!CPU_detect()) { #if CPU_REQ #if CPU_FALLBACK #if defined(__DJGPP__) || defined(__CYGWIN32__) #error CPU_FALLBACK is incompatible with the current DOS and Win32 code #endif if (!make_check) { #define CPU_FALLBACK_PATHNAME JOHN_SYSTEMWIDE_EXEC "/" CPU_FALLBACK_BINARY execv(CPU_FALLBACK_PATHNAME, argv); perror("execv: " CPU_FALLBACK_PATHNAME); } #endif fprintf(stderr, "Sorry, %s is required\n", CPU_NAME); if (make_check) exit(0); error(); #endif } #endif if (!make_check) { path_init(argv); status_init(NULL, 1); opt_init(name, argc, argv); if (options.flags & FLG_CONFIG_CLI) { cfg_init(options.config, 1); cfg_init(CFG_ALT_NAME, 0); } else { #if JOHN_SYSTEMWIDE cfg_init(CFG_PRIVATE_FULL_NAME, 1); cfg_init(CFG_PRIVATE_ALT_NAME, 1); #endif cfg_init(CFG_FULL_NAME, 1); cfg_init(CFG_ALT_NAME, 0); } } john_register_all(); common_init(); sig_init(); john_load(); }
static inline int translucent_is_whiteout2(char *path) { int i_Ret; struct nameidata n; path_init(path, 0, &n); i_Ret=path_walk(path, &n); if(i_Ret) return 0; i_Ret=translucent_is_whiteout(&n); path_release(&n); return i_Ret; }
static int a_path_walk(const char *pathname, int flags, struct nameidata *nd) { int error; error = 0; if (path_init(pathname, flags, nd)) error = path_walk(pathname, nd); return error; }
int main(int argc, char **argv) { if (!realpath(argv[0],myself)) { perror("realpath"); return 1; } path_init(xmlpath,xmlname); path_init(xslpath,xslname); // create temp files somewhere else instead of current dir // TODO: clean them up too char * testpath = strdup("/tmp/streamtest-XXXXXX"); char * testpath2; testpath2 = mkdtemp(testpath); free(testpath); if (!testpath2) { perror("mkdtemp"); return 1; } if (chdir(testpath2)) { perror("chdir"); return 1; } if (!doTest()) { printf("#### Test failed\n"); return 1; } else { printf("##### Test succeeded\n"); } return 0; }
int pruneProc( const std::vector<std::string> &args ) { if ( args.size() < 2 ) { std::cout << "gitbk prune <repo path>" << std::endl; return 1; } path_init( args[1] ); load_hash_set( false ); { signal( SIGALRM, sigroutine ); static const struct itimerval v = { { 0, 50000 }, { 0, 50000 }, }; setitimer( ITIMER_REAL, &v, nullptr ); } recordAllHash( ); signal( SIGALRM, SIG_IGN ); std::cout << "\rCounting objects " << s_object_count << std::endl; if ( store_hash_set( false ) ) { const int n = sysconf( _SC_NPROCESSORS_ONLN ); for ( int i = 0; i < n; ++i ) ++count_threads; boost::thread_group tgroup; for ( int i = 0; i < n; ++i ) tgroup.create_thread( boost::bind(&delete_file, 256*i/n, (256*(i+1)/n) ) ); tgroup.create_thread( &remove_process ); tgroup.join_all( ); printf( "\n" ); } free_hash_set( ); return 0; }
struct path_type *path_readfp_csv(FILE *fp) { struct path_type *p; double x, y, h; char buf[80]; p = path_init(); while (!feof(fp)) { if (fgets(buf, sizeof(buf), fp) == NULL) break; if (!strcmp(buf, "--\n")) break; sscanf(buf, "%lf,%lf,%lf", &x, &y, &h); path_addpt(p, x, y, h); } return(p); }
int presto_walk(const char *name, struct nameidata *nd) { int err; /* we do not follow symlinks to support symlink operations correctly. The vfs should always hand us resolved dentries so we should not be required to use LOOKUP_FOLLOW. At the reintegrating end, lento again should be working with the resolved pathname and not the symlink. SHP XXX: This code implies that direct symlinks do not work. SHP */ unsigned int flags = LOOKUP_POSITIVE; ENTRY; err = 0; if (path_init(name, flags, nd)) err = path_walk(name, nd); return err; }
SpiceServer* test_init(SpiceCoreInterface *core) { int port = 5912; SpiceServer* server = spice_server_new(); g_core = core; // some common initialization for all display tests printf("TESTER: listening on port %d (unsecure)\n", port); spice_server_set_port(server, port); spice_server_set_noauth(server); spice_server_init(server, core); cursor_init(); path_init(&path, 0, angle_parts); memset(g_primary_surface, 0, sizeof(g_primary_surface)); memset(g_secondary_surface, 0, sizeof(g_secondary_surface)); has_secondary = 0; wakeup_timer = core->timer_add(do_wakeup, NULL); return server; }
static int restoreProc( const SubCmd::Args &args ) { if ( args.size() != 3 ) { printf( "gitfs restore tag dest\n" ); return 1; } path_init( args[1] ); boost::spirit::classic::file_iterator<char> fi( args[1] ); if ( !fi ) std::cout << "error" << std::endl; else { std::auto_ptr<GitbkFs> rfp( fromItem( &*fi, args[2] ) ); RunMt( rfp.get( ) ); } return 0; }
static int mmphw_probe(struct platform_device *pdev) { struct mmp_mach_plat_info *mi; struct resource *res; int ret, i, size, irq; struct mmphw_path_plat *path_plat; struct mmphw_ctrl *ctrl = NULL; /* get resources from platform data */ res = platform_get_resource(pdev, IORESOURCE_MEM, 0); if (res == NULL) { dev_err(&pdev->dev, "%s: no IO memory defined\n", __func__); ret = -ENOENT; goto failed; } irq = platform_get_irq(pdev, 0); if (irq < 0) { dev_err(&pdev->dev, "%s: no IRQ defined\n", __func__); ret = -ENOENT; goto failed; } /* get configs from platform data */ mi = pdev->dev.platform_data; if (mi == NULL || !mi->path_num || !mi->paths) { dev_err(&pdev->dev, "%s: no platform data defined\n", __func__); ret = -EINVAL; goto failed; } /* allocate */ size = sizeof(struct mmphw_ctrl) + sizeof(struct mmphw_path_plat) * mi->path_num; ctrl = devm_kzalloc(&pdev->dev, size, GFP_KERNEL); if (!ctrl) { ret = -ENOMEM; goto failed; } ctrl->name = mi->name; ctrl->path_num = mi->path_num; ctrl->dev = &pdev->dev; ctrl->irq = irq; platform_set_drvdata(pdev, ctrl); mutex_init(&ctrl->access_ok); /* map registers.*/ if (!devm_request_mem_region(ctrl->dev, res->start, resource_size(res), ctrl->name)) { dev_err(ctrl->dev, "can't request region for resource %pR\n", res); ret = -EINVAL; goto failed; } ctrl->reg_base = devm_ioremap_nocache(ctrl->dev, res->start, resource_size(res)); if (ctrl->reg_base == NULL) { dev_err(ctrl->dev, "%s: res %x - %x map failed\n", __func__, res->start, res->end); ret = -ENOMEM; goto failed; } /* request irq */ ret = devm_request_irq(ctrl->dev, ctrl->irq, ctrl_handle_irq, IRQF_SHARED, "lcd_controller", ctrl); if (ret < 0) { dev_err(ctrl->dev, "%s unable to request IRQ %d\n", __func__, ctrl->irq); ret = -ENXIO; goto failed; } /* get clock */ ctrl->clk = devm_clk_get(ctrl->dev, mi->clk_name); if (IS_ERR(ctrl->clk)) { dev_err(ctrl->dev, "unable to get clk %s\n", mi->clk_name); ret = -ENOENT; goto failed; } clk_prepare_enable(ctrl->clk); /* init global regs */ ctrl_set_default(ctrl); /* init pathes from machine info and register them */ for (i = 0; i < ctrl->path_num; i++) { /* get from config and machine info */ path_plat = &ctrl->path_plats[i]; path_plat->id = i; path_plat->ctrl = ctrl; /* path init */ if (!path_init(path_plat, &mi->paths[i])) { ret = -EINVAL; goto failed_path_init; } } #ifdef CONFIG_MMP_DISP_SPI ret = lcd_spi_register(ctrl); if (ret < 0) goto failed_path_init; #endif dev_info(ctrl->dev, "device init done\n"); return 0; failed_path_init: for (i = 0; i < ctrl->path_num; i++) { path_plat = &ctrl->path_plats[i]; path_deinit(path_plat); } clk_disable_unprepare(ctrl->clk); failed: dev_err(&pdev->dev, "device init failed\n"); return ret; }
void * tsearch(const void *key, void **rootp, int (*compar)(const void *, const void *)) { struct path path; node_t *root, **base, **leaf, *result, *n, *x, *y, *z; int cmp; /* POSIX requires that tsearch() returns NULL if rootp is NULL. */ if (rootp == NULL) return (NULL); root = *rootp; /* * Find the leaf where the new key needs to be inserted. Return * if we've found an existing entry. Keep track of the path that * is taken to get to the node, as we will need it to adjust the * balances. */ path_init(&path); base = &root; leaf = &root; while (*leaf != NULL) { if ((*leaf)->balance != 0) { /* * If we reach a node that has a non-zero * balance on the way, we know that we won't * need to perform any rotations above this * point. In this case rotations are always * capable of keeping the subtree in balance. * Make this the base node and reset the path. */ base = leaf; path_init(&path); } cmp = compar(key, (*leaf)->key); if (cmp < 0) { path_taking_left(&path); leaf = &(*leaf)->llink; } else if (cmp > 0) { path_taking_right(&path); leaf = &(*leaf)->rlink; } else { return (&(*leaf)->key); } } /* Did not find a matching key in the tree. Insert a new node. */ result = *leaf = malloc(sizeof(**leaf)); if (result == NULL) return (NULL); result->key = (void *)key; result->llink = NULL; result->rlink = NULL; result->balance = 0; /* * Walk along the same path a second time and adjust the * balances. Except for the first node, all of these nodes must * have a balance of zero, meaning that these nodes will not get * out of balance. */ for (n = *base; n != *leaf;) { if (path_took_left(&path)) { n->balance += 1; n = n->llink; } else { n->balance -= 1; n = n->rlink; } } /* * Adjusting the balances may have pushed the balance of the * base node out of range. Perform a rotation to bring the * balance back in range. */ x = *base; if (x->balance > 1) { y = x->llink; if (y->balance < 0) { /* * Left-right case. * * x * / \ z * y D / \ * / \ --> y x * A z /| |\ * / \ A B C D * B C */ z = y->rlink; y->rlink = z->llink; z->llink = y; x->llink = z->rlink; z->rlink = x; *base = z; x->balance = z->balance > 0 ? -1 : 0; y->balance = z->balance < 0 ? 1 : 0; z->balance = 0; } else { /* * Left-left case. * * x y * / \ / \ * y C --> A x * / \ / \ * A B B C */ x->llink = y->rlink; y->rlink = x; *base = y; x->balance = 0; y->balance = 0; } } else if (x->balance < -1) { y = x->rlink; if (y->balance > 0) { /* * Right-left case. * * x * / \ z * A y / \ * / \ --> x y * z D /| |\ * / \ A B C D * B C */ node_t *z = y->llink; x->rlink = z->llink; z->llink = x; y->llink = z->rlink; z->rlink = y; *base = z; x->balance = z->balance < 0 ? 1 : 0; y->balance = z->balance > 0 ? -1 : 0; z->balance = 0; } else { /* * Right-right case. * * x y * / \ / \ * A y --> x C * / \ / \ * B C A B */ x->rlink = y->llink; y->llink = x; *base = y; x->balance = 0; y->balance = 0; } } /* Return the new entry. */ *rootp = root; return (&result->key); }
int main(int argc, char* argv[]) { // Variable declarations int i, port, sd_current, addrlen, handlingMethod, fifo, setval, max_fd; struct sockaddr_in sin, pin; configuration config; char error[1024]; pthread_t handler; pthread_attr_t att; pid_t pid; fd_set rfds; // Set execution to true execute = true; // Clear file creation mask. umask(0); // Set default handling method to thread handlingMethod = _THREAD; // Get size of pin .. addrlen = sizeof(pin); // Signal handlers signal(SIGPIPE, SIG_IGN); signal(SIGINT, sig_handle_int); signal(SIGABRT, sig_handle_int); // Set default config setDefaultConfig(&config); // Set root dir to current running directory path_init(&config); rootDir(argv[0]); // Parse config file if (parseConfig(&config) == -1) { exit(-1); } // Check arguments if(argc > 1) { for(i = 1; i < argc; i++) { switch(argv[i][1]) { // Help case 'h': printHelp(); return 3; break; // Port case 'p': i++; if(i >= argc) { printHelp(); return 3; } if(argv[i][0] != '-') { if((port = atoi(argv[i])) != 0 && port < 65536) { config.listenPort = port; printf("Port number: %d\n", port); } else { printHelp(); return 3; } } else { printHelp(); return 3; } break; // Deamonize case 'd': // Start daemon if set printf("Starting daemon...\n"); daemonfunc(); break; // Log file case 'l': i++; if(i >= argc) { printHelp(); return 3; } if(argv[i][0] != '-') { strncpy(config.accLogPath, argv[i], sizeof(config.accLogPath)); } else { printHelp(); return 3; } break; // Mode of operation case 's': i++; if(i >= argc) { printHelp(); return 3; } if(strncmp(argv[i], "thread", 6) == 0) handlingMethod = _THREAD; else if(strncmp(argv[i], "fork", 4) == 0) handlingMethod = _FORK; else { printHelp(); return 3; } break; case 'c': i++; if(i >= argc) { printHelp(); return 3; } if(argv[i][0] != '-') { strncpy(config.configPath, argv[i], sizeof(config.configPath)); } else { printHelp(); return 3; } break; } } } // Init logfunctions if (log_init(&config) == -1) { exit(-1); } // Create fifo if prefork is set if (handlingMethod == _FORK) { // Create the named fifo pipe mkfifo(config.fifoPath, 0666); // Try opening the pipe if((fifo = open(config.fifoPath, O_RDWR)) == -1) { sprintf(error, "Unable to open FIFO-pipe, %s", strerror(errno)); log_server(LOG_CRIT, error); execute = false; // Terminate } } // Check super user if (getuid() != 0) { perror("You have to be root to run this program"); exit(-1); } // Set root directory to document root chdir(config.basedir); if (chroot(config.basedir) == -1) { sprintf(error, "Unable to change root directory, %s", strerror(errno)); log_server(LOG_ERR, error); execute = false; // Terminate } // Drop root privileges if (setgid(getgid()) == -1) { sprintf(error, "Unable to change user, %s", strerror(errno)); log_server(LOG_ERR, error); execute = false; // Terminate } if (setuid(getuid()) == -1) { sprintf(error, "Unable to change user, %s", strerror(errno)); log_server(LOG_ERR, error); execute = false; // Terminate } // Create listening socket // Domain -> AF_INET = IPV4 // Type -> SOCK_STREAM = TCP if((sd = socket(AF_INET, SOCK_STREAM, 0)) == -1) { sprintf(error, "Unable to open socket, %s", strerror(errno)); log_server(LOG_ERR, error); execute = false; // Terminate } // Zeroize sin memset(&sin, 0, sizeof(sin)); // Set domain sin.sin_family = AF_INET; // Set any in address sin.sin_addr.s_addr = INADDR_ANY; // Set port, hton converts byteorder sin.sin_port = htons(config.listenPort); // Try binding the socket if(bind(sd, (struct sockaddr*) &sin, sizeof(sin)) == -1) { sprintf(error, "Unable to bind socket, %s", strerror(errno)); log_server(LOG_ERR, error); execute = false; // Terminate } // Start to listen for requests if(listen(sd, config.backlog) == -1) { sprintf(error, "Too loud unable to listen, %s", strerror(errno)); log_server(LOG_ERR, error); execute = false; // Terminate } // Init thread lock pthread_mutex_init(&thread_lock, NULL); // If handling method is set to thread if(handlingMethod == _THREAD) { // Init thread attr pthread_attr_init(&att); // Set threads to detached state pthread_attr_setdetachstate(&att, PTHREAD_CREATE_DETACHED); // Set system scope pthread_attr_setscope(&att, PTHREAD_SCOPE_SYSTEM); // Set RoundRobin scheduling pthread_attr_setschedpolicy(&att, SCHED_RR); // Not supported in LINUX pthreads // Start accepting requests while(execute) { // Accept a request from queue, blocking if ((sd_current = accept(sd, (struct sockaddr*) &pin, (socklen_t*) &addrlen)) == -1) { if (execute) { sprintf(error, "Unable to accept request, %s", strerror(errno)); log_server(LOG_ERR, error); } close(sd_current); execute = false; // Terminate } else { // Shit happens, if server is out of memory just skip the request _rqhd_args *args = malloc(sizeof(_rqhd_args)); if (args == NULL) { sprintf(error, "Unable to allocate memory, %s", strerror(errno)); log_server(LOG_CRIT, error); close(sd_current); } else { // Set arguments args->sd = sd_current; args->pin = pin; args->config = &config; } // Create thread if(pthread_create(&handler, &att, requestHandle, args) != 0) { sprintf(error, "Unable to start thread, %s", strerror(errno)); log_server(LOG_CRIT, error); close(sd_current); execute = false; // Terminate } } } // Destroy attributes pthread_attr_destroy(&att); } // Else if handling method is set to fork else if(handlingMethod == _FORK) { max_fd = sd; if (fifo > sd) max_fd = fifo; // Start accepting requests while(execute) { FD_ZERO(&rfds); FD_SET(sd, &rfds); FD_SET(fifo, &rfds); // Accept request or handle child setval = select(max_fd + 1, &rfds, NULL, NULL, NULL); if (FD_ISSET(sd, &rfds)) { // Accept a request from queue if ((sd_current = accept(sd, (struct sockaddr*) &pin, (socklen_t*) &addrlen)) == -1) { if (execute) { sprintf(error, "Unable to accept request, %s", strerror(errno)); log_server(LOG_ERR, error); } close(sd_current); execute = false; // Terminate } else { // Fork if((pid = fork()) == 0) { // CHILD ---------------------------------------------------- // Shit happens, if server is out of memory just skip the request _rqhd_args *args = malloc(sizeof(_rqhd_args)); if (args == NULL) { sprintf(error, "Unable to allocate memory, %s", strerror(errno)); log_server(LOG_CRIT, error); close(sd_current); } else { // Set arguments args->sd = sd_current; args->pin = pin; args->config = &config; // Call request handler requestHandle(args); } // Tell parent I'm done pid_t id = getpid(); if (write(fifo, &id, sizeof(pid_t)) == -1) { sprintf(error, "Unable to send pid, %s", strerror(errno)); log_server(LOG_ERR, error); } // Done execute = false; } else if(pid > 0) { // PARENT --------------------------------------------------- // Parent don't handle dirty work close(sd_current); } else { sprintf(error, "Unable to fork, %s", strerror(errno)); log_server(LOG_CRIT, error); close(sd_current); execute = false; // Terminate } } } else if (FD_ISSET(fifo, &rfds)) { // Get child pid from fifo and wait for it pid_t child; if (read(fifo, &child, sizeof(pid_t)) == -1) { sprintf(error, "Unable to read pid, %s", strerror(errno)); log_server(LOG_ERR, error); } waitpid(child, NULL, 0); } else if (setval == -1){ // Error sprintf(error, "Select failed or was interrupted, %s", strerror(errno)); log_server(LOG_ERR, error); execute = false; // Terminate } } // Close fifo close(fifo); } // Else not a valid handling method else { sprintf(error, "Invalid handling method is set"); log_server(LOG_ERR, error); } // Clean up pthread_mutex_destroy(&thread_lock); close(sd); log_destroy(); if (pid != 0) printf("Cleanup complete, no one will know I was here.\n"); return 0; }
entry_t *traverse(void) /* Get one name from the directory tree. */ { static int depth; static pathname_t path; static entry_t entry; static namelist_t **entries; static size_t *trunc; static size_t deep; static namelist_t *newentries; struct stat st; recurse: keep= KEEP_TRAVERSE; if (deep == 0) { /* Initialize for the root of the tree. */ path_init(&path); path_add(&path, tree); entries= allocate(nil, 1 * sizeof(entries[0])); entries[0]= allocate(nil, sizeof(*entries[0])); entries[0]->next= nil; entries[0]->name= copystr("/"); trunc= allocate(nil, 1 * sizeof(trunc[0])); trunc[0]= path_length(&path); deep= 1; } else if (newentries != nil) { /* Last entry was a directory, need to go down. */ if (entry.ignore) { /* Ouch, it is to be ignored! */ while (newentries != nil) (void) pop_name(&newentries); goto recurse; } if (++depth == deep) { deep++; entries= allocate(entries, deep * sizeof(entries[0])); trunc= allocate(trunc, deep * sizeof(trunc[0])); } entries[depth]= newentries; newentries= nil; trunc[depth]= path_length(&path); } else { /* Pop up out of emptied directories. */ while (entries[depth] == nil) { if (depth == 0) return nil; /* Back at the root. */ /* Go up one level. */ depth--; } } entry.name= pop_name(&entries[depth]); path_trunc(&path, trunc[depth]); path_add(&path, entry.name); if (depth == 0) { entry.path= "/"; } else { entry.path= path_name(&path) + trunc[0]; if (entry.path[0] == '/') entry.path++; } entry.depth= depth; entry.ignore= 0; if (lstat(path_name(&path), &st) < 0) { if (depth == 0 || errno != ENOENT) { /* Something wrong with this entry, complain about * it and ignore it further. */ entry.ignore= errno; report(path_name(&path)); return &entry; } else { /* Entry strangely nonexistent; simply continue. */ goto recurse; } } /* Don't cross mountpoints if -x is set. */ if (xflag) { if (xdev == NO_DEVICE) xdev= st.st_dev; if (st.st_dev != xdev) { /* Ignore the mountpoint. */ entry.ignore= EXDEV; return &entry; } } entry.mode= st.st_mode & 07777; entry.uid= st.st_uid; entry.gid= st.st_gid; entry.size= st.st_size; entry.mtime= st.st_mtime; entry.rdev= st.st_rdev; linked(&entry, &st); if (S_ISDIR(st.st_mode)) { /* A directory. */ entry.type= F_DIR; /* Gather directory entries for the next traverse. */ if ((newentries= collect(path_name(&path))) == nil && errno != 0) { entry.ignore= errno; report(path_name(&path)); } } else if (S_ISREG(st.st_mode)) { /* A plain file. */ entry.type= F_FILE; } else if (S_ISBLK(st.st_mode)) { /* A block special file. */ entry.type= F_BLK; } else if (S_ISCHR(st.st_mode)) { /* A character special file. */ entry.type= F_CHR; } else if (S_ISFIFO(st.st_mode)) { /* A named pipe. */ entry.type= F_PIPE; } else if (S_ISLNK(st.st_mode)) { /* A symbolic link. */ entry.type= F_LINK; if ((entry.link= rdlink(path_name(&path), st.st_size)) == nil) { entry.ignore= errno; report(path_name(&path)); } } else { /* Unknown type of file. */ entry.ignore= EINVAL; } return &entry; }
entry_t *readstate(void) /* Read one entry from the state file. */ { static entry_t entry; static pathname_t path; static size_t *trunc; static size_t trunc_len; static base_indent; char *line; char **argv; size_t argc; static off_t lineno; int indent, depth; recurse: keep= KEEP_STATE; if (feof(statefp) || (line= read1line(statefp)) == nil) { checkstate(); return nil; } lineno++; /* How far is this entry indented? */ indent= 0; while (*line != 0) { if (*line == ' ') indent++; else if (*line == '\t') indent= (indent + 8) & ~7; else break; line++; } if (indent > 0 && base_indent == 0) base_indent= indent; depth= (base_indent == 0 ? 0 : indent / base_indent) + 1; if (entry.ignore && depth > entry.depth) { /* If the old directory is ignored, then so are its entries. */ goto recurse; } entry.depth= depth; splitline(line, &argv, &argc); if (argc < 2) state_syntax(lineno); if (trunc == nil) { /* The root of the tree, initialize path. */ if (argv[0][0] != '/') state_syntax(lineno); path_init(&path); path_add(&path, "/"); trunc= allocate(nil, (trunc_len= 16) * sizeof(trunc[0])); /* The root has depth 0. */ entry.depth= 0; trunc[0]= 0; } else { if (entry.depth > trunc_len) { trunc= allocate(trunc, (trunc_len*= 2) * sizeof(trunc[0])); } path_trunc(&path, trunc[entry.depth - 1]); path_add(&path, argv[0]); trunc[entry.depth]= path_length(&path); } entry.path= path_name(&path); entry.name= argv[0]; entry.link= nil; if ((entry.ignore= strcmp(argv[1], "ignore") == 0)) { return &entry; } if (!getattributes(&entry, argc - 1, argv + 1)) state_syntax(lineno); return &entry; }
int main(int argc, char **argv) { graph_t graph; path_t best, candidate, best_candidate; int rot_size, rot_start; int verbose = 0; if ((argc == 2) && (strncmp(argv[1], "-v", sizeof("-v")) == 0)) { verbose = 1; } else if (argc > 1) { fprintf(stderr, "\n"); fprintf(stderr, " Parâmetros inválidos!\n"); fprintf(stderr, "\n"); fprintf(stderr, "Uso: %s [-v]\n", argv[0]); fprintf(stderr, " -v Ativa modo verbose (exibe detalhes da " "execução do algoritmo)\n"); return EXIT_FAILURE; } process_input(&graph); graph_calculate_distances(&graph); path_init(&best, &graph); path_find_greedy(&best, 1); if (verbose) { printf("1o. caminho: "); print_path(&best); } for (rot_size = 2; rot_size < graph.node_count; ++rot_size) { if (verbose) { printf("\n\n===== Trocando caminhos com tamanho %2d =====\n", rot_size); } path_copy(&best_candidate, &best); for (rot_start = 1; rot_start <= graph.node_count - rot_size; ++rot_start) { path_copy(&candidate, &best); path_rotate(&candidate, rot_size, rot_start); if (verbose) { printf("Troca # %3d: ", rot_start); print_path(&candidate); } if (candidate.distance < best_candidate.distance) { path_copy(&best_candidate, &candidate); } path_destroy(&candidate); } if (best_candidate.distance < best.distance) { path_copy(&best, &best_candidate); } if (verbose) { printf("\n MELHOR : "); print_path(&best); } } if (verbose) { printf("\n============================================\n"); } printf("Melhor caminho encontrado:\n"); print_path(&best); path_destroy(&best); path_destroy(&best_candidate); graph_destroy(&graph); return EXIT_SUCCESS; }
static void john_init(char *name, int argc, char **argv) { int make_check = (argc == 2 && !strcmp(argv[1], "--make_check")); if (make_check) argv[1] = "--test=0"; CPU_detect_or_fallback(argv, make_check); status_init(NULL, 1); if (argc < 2) john_register_all(); /* for printing by opt_init() */ opt_init(name, argc, argv); if (options.listconf && !strcasecmp(options.listconf, "?")) { puts("inc-modes, rules, externals, ext-filters, ext-filters-only,"); puts("ext-modes, build-info, hidden-options, <conf section name>"); exit(0); } if (options.listconf && !strcasecmp(options.listconf, "hidden-options")) { puts("--list=NAME list configuration, rules, etc"); puts("--mkpc=N force a lower max. keys per crypt"); exit(0); } if (!make_check) { #if defined(_OPENMP) && OMP_FALLBACK #if defined(__DJGPP__) || defined(__CYGWIN32__) #error OMP_FALLBACK is incompatible with the current DOS and Win32 code #endif if (!getenv("JOHN_NO_OMP_FALLBACK") && omp_get_max_threads() <= 1) { #define OMP_FALLBACK_PATHNAME JOHN_SYSTEMWIDE_EXEC "/" OMP_FALLBACK_BINARY execv(OMP_FALLBACK_PATHNAME, argv); perror("execv: " OMP_FALLBACK_PATHNAME); } #endif path_init(argv); if (options.listconf && !strcasecmp(options.listconf, "build-info")) { puts("Version: " JOHN_VERSION); puts("Build: " JOHN_BLD _MP_VERSION); printf("Arch: %d-bit %s\n", ARCH_BITS, ARCH_LITTLE_ENDIAN ? "LE" : "BE"); #if JOHN_SYSTEMWIDE puts("System-wide exec: " JOHN_SYSTEMWIDE_EXEC); puts("System-wide home: " JOHN_SYSTEMWIDE_HOME); puts("Private home: " JOHN_PRIVATE_HOME); #endif printf("$JOHN is %s\n", path_expand("$JOHN/")); puts("Rec file version: " RECOVERY_V); printf("CHARSET_MIN: %d (0x%02x)\n", CHARSET_MIN, CHARSET_MIN); printf("CHARSET_MAX: %d (0x%02x)\n", CHARSET_MAX, CHARSET_MAX); printf("CHARSET_LENGTH: %d\n", CHARSET_LENGTH); #ifdef __GNUC__ printf("gcc version: %d.%d.%d\n", __GNUC__, __GNUC_MINOR__, __GNUC_PATCHLEVEL__); #endif #ifdef __ICC printf("icc version: %d\n", __ICC); #endif exit(0); } if (options.flags & FLG_CONFIG_CLI) { path_init_ex(options.config); cfg_init(options.config, 1); cfg_init(CFG_FULL_NAME, 1); cfg_init(CFG_ALT_NAME, 0); } else { #if JOHN_SYSTEMWIDE cfg_init(CFG_PRIVATE_FULL_NAME, 1); cfg_init(CFG_PRIVATE_ALT_NAME, 1); #endif cfg_init(CFG_FULL_NAME, 1); cfg_init(CFG_ALT_NAME, 0); } } if (options.subformat && !strcasecmp(options.subformat, "list")) { dynamic_DISPLAY_ALL_FORMATS(); /* NOTE if we have other 'generics', like sha1, sha2, rc4, ... * then EACH of them should have a DISPLAY_ALL_FORMATS() * function and we can call them here. */ exit(0); } if (options.listconf && !strcasecmp(options.listconf, "inc-modes")) { cfg_print_subsections("Incremental", NULL, NULL); exit(0); } if (options.listconf && !strcasecmp(options.listconf, "rules")) { cfg_print_subsections("List.Rules", NULL, NULL); exit(0); } if (options.listconf && !strcasecmp(options.listconf, "externals")) { cfg_print_subsections("List.External", NULL, NULL); exit(0); } if (options.listconf && !strcasecmp(options.listconf, "ext-filters")) { cfg_print_subsections("List.External", "filter", NULL); exit(0); } if (options.listconf && !strcasecmp(options.listconf, "ext-filters-only")) { cfg_print_subsections("List.External", "filter", "generate"); exit(0); } if (options.listconf && !strcasecmp(options.listconf, "ext-modes")) { cfg_print_subsections("List.External", "generate", NULL); exit(0); } /* Catch-all for any other john.conf section name :-) */ if (options.listconf) { cfg_print_subsections(options.listconf, NULL, NULL); exit(0); } initUnicode(UNICODE_UNICODE); /* Init the unicode system */ john_register_all(); /* maybe restricted to one format by options */ common_init(); sig_init(); john_load(); if (options.encodingStr && options.encodingStr[0]) log_event("- %s input encoding enabled", options.encodingStr); #ifdef CL_VERSION_1_0 if (!options.ocl_platform) if ((options.ocl_platform = cfg_get_param(SECTION_OPTIONS, SUBSECTION_OPENCL, "Platform"))) platform_id = atoi(options.ocl_platform); if (!options.ocl_device) if ((options.ocl_device = cfg_get_param(SECTION_OPTIONS, SUBSECTION_OPENCL, "Device"))) gpu_id = atoi(options.ocl_device); #endif }
int main(int argc, char** argv) { if(argc != 2 && argc != 3) { c_print_format("Usage: %s FILE [cartridge/folder]\n", argv[0]); return 0; } Arena arena = arena_create(MB(512)); String cartridge_folder_path_name = (argc > 2) ? string_from_c_string(argv[2]) : L("SuperMarioWorld.sfc"); Path cartridge_folder_path; path_init(&cartridge_folder_path, cartridge_folder_path_name); Path manifest_path; path_init_from_c(&manifest_path, &cartridge_folder_path, "manifest.bml"); Buffer manifest_buffer = path_read_file(&manifest_path, &arena); Wdc65816MapperBuilder rom_builder = { }; char name[256]; Buffer name_buffer = buffer(name, 256); Buffer rom_buffer; for(Wdc65816RomLoader loader = wdc65816_rom_loader_begin(&rom_builder, string_from_buffer(manifest_buffer)); wdc65816_rom_loader_end(&loader); wdc65816_rom_loader_next(&loader)) { Wdc65816MemoryBufferRequest request = wdc65816_rom_loader_get_buffer_request(&loader, name_buffer); Buffer file_buffer = buffer(arena_alloc_array(&arena, request.size, u8), request.size); if(string_equal(request.name, L("program.rom")) && request.type == WDC65816_MEMORY_ROM) { rom_buffer = file_buffer; } wdc65816_rom_loader_set_buffer(&loader, file_buffer); } uint mapper_buffer_size = wdc65816_mapper_get_buffer_size(); u8* work_buffer = arena_alloc_array(&arena, mapper_buffer_size, u8); Wdc65816Mapper rom; wdc65816_mapper_init(&rom, &rom_builder, (u8**)work_buffer); nuts_global_init(); Path working_dir; path_init_working_directory(&working_dir); FreeList sentinel; free_list_init(&sentinel); ErrorList error_list; error_list_init(&error_list, arena_subarena(&arena, MB(10))); AST ast; ast_init(&ast, &arena); String file_name = string_from_c_string(argv[1]); /* struct timespec lex_start, lex_end, lex_time = { 0 }; */ /* struct timespec parse_start, parse_end, parse_time = { 0 }; */ /* struct timespec assemble_start, assemble_end, assemble_time = { 0 }; */ /* struct timespec all_start, all_end, all_time; */ /* clock_gettime(CLOCK_REALTIME, &all_start); */ Parser parser; parser_init(&parser, &arena, &sentinel, &error_list, &ast); int error_num = 0; while(1) { Path file; path_init(&file, file_name); Buffer file_buffer = path_read_file(&file, &arena); TokenList token_list; //c_print_format("read %.*s\n", file_name.length, file_name.data); Text file_text = { .buffer = file_buffer, .name = file_name }; /* clock_gettime(CLOCK_REALTIME, &lex_start); */ Result result = lex(file_text, &token_list, &arena, &error_list, &ast.identifier_map); if(result == RESULT_ERROR) { for(;error_num < error_list.length; error_num++) { describe_error(error_list.errors[error_num]); } } /* clock_gettime(CLOCK_REALTIME, &lex_end); */ /* lex_time = timespec_add(lex_time, timespec_sub(lex_start, lex_end)); */ /* clock_gettime(CLOCK_REALTIME, &parse_start); */ /* result = parse(&parser, token_list); */ /* clock_gettime(CLOCK_REALTIME, &parse_end); */ /* parse_time = timespec_add(parse_time, timespec_sub(parse_start, parse_end)); */ if(result == RESULT_NEED_TOKEN_STREAM) { file_name = parser.needed_token_stream_file_name; continue; } else if(result == RESULT_OK) { break; } else if(result == RESULT_ERROR) { for(;error_num < error_list.length; error_num++) { describe_error(error_list.errors[error_num]); } return 1; } else { invalid_code_path; } } /* clock_gettime(CLOCK_REALTIME, &assemble_start); */ Assembler assembler; assembler_init(&assembler, &error_list, &ast, &rom); Result result = RESULT_ERROR; while(result != RESULT_OK) { result = assemble(&assembler); if(result == RESULT_NEED_FILE) { String file_name = assembler_get_file_name(&assembler); Path file; path_init(&file, file_name); Buffer file_buffer = path_read_file(&file, &arena); assembler_give_buffer(&assembler, file_buffer); } else if(result == RESULT_ERROR) { break; } } /* clock_gettime(CLOCK_REALTIME, &assemble_end); */ /* assemble_time = timespec_add(assemble_time, timespec_sub(assemble_start, assemble_end)); */ for(int i = 0; i < error_list.length; i++) { describe_error(error_list.errors[i]); } /* parser_deinit(&parser); */ /* clock_gettime(CLOCK_REALTIME, &all_end); */ /* all_time = timespec_sub(all_start, all_end); */ /* c_print_format("Lex: %li.%06lims\n", lex_time.tv_sec * 1000 + lex_time.tv_nsec / 1000000, lex_time.tv_nsec % 1000000); */ /* c_print_format("Parse: %li.%06lims\n", parse_time.tv_sec * 1000 + parse_time.tv_nsec / 1000000, parse_time.tv_nsec % 1000000); */ /* c_print_format("Assemble: %li.%06lims\n", assemble_time.tv_sec * 1000 + assemble_time.tv_nsec / 1000000, assemble_time.tv_nsec % 1000000); */ /* c_print_format("All: %li.%06lims\n", all_time.tv_sec * 1000 + all_time.tv_nsec / 1000000, all_time.tv_nsec % 1000000); */ Path rom_path; path_create_from(&rom_path, &cartridge_folder_path, L("program.rom")); path_write_file(&rom_path, rom_buffer); return 0; }
static void john_init(char *name, int argc, char **argv) { int show_usage = 0; int make_check = (argc == 2 && !strcmp(argv[1], "--make_check")); if (make_check) argv[1] = "--test=0"; CPU_detect_or_fallback(argv, make_check); status_init(NULL, 1); if (argc < 2 || (argc == 2 && (!strcasecmp(argv[1], "--help") || !strcasecmp(argv[1], "-h") || !strcasecmp(argv[1], "-help")))) { john_register_all(); /* for printing by opt_init() */ show_usage = 1; } opt_init(name, argc, argv, show_usage); /* * --list=? needs to be supported, because it has been supported in the released * john-1.7.9-jumbo-6 version, and it is used by the bash completion script. * --list=? is, however, not longer mentioned in doc/OPTIONS and in the usage * output. Instead, --list=help is. */ if (options.listconf && (!strcasecmp(options.listconf, "help") || !strcmp(options.listconf, "?"))) { john_list_options(); exit(0); } if (options.listconf && (!strcasecmp(options.listconf, "help:help") || !strcasecmp(options.listconf, "help:"))) { john_list_help_options(); exit(0); } if (options.listconf && !strcasecmp(options.listconf, "help:format-methods")) { john_list_method_names(); exit(0); } if (options.listconf && !strncasecmp(options.listconf, "help:", 5)) { if (strcasecmp(options.listconf, "help:parameters") && strcasecmp(options.listconf, "help:list-data")) { fprintf(stderr, "%s is not a --list option that supports additional values.\nSupported options:\n", options.listconf+5); john_list_help_options(); exit(1); } } if (options.listconf && !strcasecmp(options.listconf, "hidden-options")) { puts("--help print usage summary, just like running the command"); puts(" without any parameters"); puts("--subformat=FORMAT pick a benchmark format for --format=crypt"); puts("--mkpc=N force a lower max. keys per crypt"); puts("--length=N force a lower max. length"); puts("--field-separator-char=C use 'C' instead of the ':' in input and pot files"); puts("--fix-state-delay=N performance tweak, see documentation"); puts("--log-stderr log to screen instead of file\n"); exit(0); } if (!make_check) { #if defined(_OPENMP) && OMP_FALLBACK #if defined(__DJGPP__) || defined(__CYGWIN32__) #error OMP_FALLBACK is incompatible with the current DOS and Win32 code #endif if (!getenv("JOHN_NO_OMP_FALLBACK") && omp_get_max_threads() <= 1) { #define OMP_FALLBACK_PATHNAME JOHN_SYSTEMWIDE_EXEC "/" OMP_FALLBACK_BINARY execv(OMP_FALLBACK_PATHNAME, argv); perror("execv: " OMP_FALLBACK_PATHNAME); } #endif path_init(argv); if (options.listconf && !strcasecmp(options.listconf, "build-info")) { puts("Version: " JOHN_VERSION); puts("Build: " JOHN_BLD _MP_VERSION); printf("Arch: %d-bit %s\n", ARCH_BITS, ARCH_LITTLE_ENDIAN ? "LE" : "BE"); #if JOHN_SYSTEMWIDE puts("System-wide exec: " JOHN_SYSTEMWIDE_EXEC); puts("System-wide home: " JOHN_SYSTEMWIDE_HOME); puts("Private home: " JOHN_PRIVATE_HOME); #endif printf("$JOHN is %s\n", path_expand("$JOHN/")); printf("Format interface version: %d\n", FMT_MAIN_VERSION); puts("Rec file version: " RECOVERY_V); puts("Charset file version: " CHARSET_V); printf("CHARSET_MIN: %d (0x%02x)\n", CHARSET_MIN, CHARSET_MIN); printf("CHARSET_MAX: %d (0x%02x)\n", CHARSET_MAX, CHARSET_MAX); printf("CHARSET_LENGTH: %d\n", CHARSET_LENGTH); printf("Max. Markov mode level: %d\n", MAX_MKV_LVL); printf("Max. Markov mode password length: %d\n", MAX_MKV_LEN); #ifdef __VERSION__ printf("Compiler version: %s\n", __VERSION__); #endif #ifdef __GNUC__ printf("gcc version: %d.%d.%d\n", __GNUC__, __GNUC_MINOR__, __GNUC_PATCHLEVEL__); #endif #ifdef __ICC printf("icc version: %d\n", __ICC); #endif #ifdef __clang_version__ printf("clang version: %s\n", __clang_version__); #endif #ifdef OPENSSL_VERSION_NUMBER // The man page suggests the type of OPENSSL_VERSION_NUMBER is long, // gcc insists it is int. printf("OpenSSL library version: %lx", (unsigned long)OPENSSL_VERSION_NUMBER); // FIXME: How do I detect a missing library? // Even if if is extremely unlikely that openssl is missing, // at least flush all output buffers... fflush(NULL); if ((unsigned long)OPENSSL_VERSION_NUMBER != (unsigned long)SSLeay()) printf("\t(loaded: %lx)", (unsigned long)SSLeay()); printf("\n"); #endif exit(0); } } if (options.listconf && !strcasecmp(options.listconf, "encodings")) { listEncodings(); exit(0); } #ifdef CL_VERSION_1_0 if (options.listconf && !strcasecmp(options.listconf, "opencl-devices")) { listOpenCLdevices(); exit(0); } #endif #ifdef HAVE_CUDA if (options.listconf && !strcasecmp(options.listconf, "cuda-devices")) { cuda_device_list(); exit(0); } #endif if (!make_check) { if (options.config) { path_init_ex(options.config); cfg_init(options.config, 1); cfg_init(CFG_FULL_NAME, 1); cfg_init(CFG_ALT_NAME, 0); } else { #if JOHN_SYSTEMWIDE cfg_init(CFG_PRIVATE_FULL_NAME, 1); cfg_init(CFG_PRIVATE_ALT_NAME, 1); #endif cfg_init(CFG_FULL_NAME, 1); cfg_init(CFG_ALT_NAME, 0); } } /* This is --crack-status. We toggle here, so if it's enabled in john.conf, we can disable it using the command line option */ if (cfg_get_bool(SECTION_OPTIONS, NULL, "CrackStatus", 0)) options.flags ^= FLG_CRKSTAT; initUnicode(UNICODE_UNICODE); /* Init the unicode system */ john_register_all(); /* maybe restricted to one format by options */ if ((options.subformat && !strcasecmp(options.subformat, "list")) || (options.listconf && !strcasecmp(options.listconf, "subformats"))) { dynamic_DISPLAY_ALL_FORMATS(); /* NOTE if we have other 'generics', like sha1, sha2, rc4, ... * then EACH of them should have a DISPLAY_ALL_FORMATS() * function and we can call them here. */ exit(0); } if (options.listconf && !strcasecmp(options.listconf, "inc-modes")) { cfg_print_subsections("Incremental", NULL, NULL, 0); exit(0); } if (options.listconf && !strcasecmp(options.listconf, "rules")) { cfg_print_subsections("List.Rules", NULL, NULL, 0); exit(0); } if (options.listconf && !strcasecmp(options.listconf, "externals")) { cfg_print_subsections("List.External", NULL, NULL, 0); exit(0); } if (options.listconf && !strcasecmp(options.listconf, "sections")) { cfg_print_section_names(0); exit(0); } if (options.listconf && !strncasecmp(options.listconf, "parameters", 10) && (options.listconf[10] == '=' || options.listconf[10] == ':') && options.listconf[11] != '\0') { cfg_print_section_params(&options.listconf[11], NULL); exit(0); } if (options.listconf && !strncasecmp(options.listconf, "list-data", 9) && (options.listconf[9] == '=' || options.listconf[9] == ':') && options.listconf[10] != '\0') { cfg_print_section_list_lines(&options.listconf[10], NULL); exit(0); } if (options.listconf && !strcasecmp(options.listconf, "ext-filters")) { cfg_print_subsections("List.External", "filter", NULL, 0); exit(0); } if (options.listconf && !strcasecmp(options.listconf, "ext-filters-only")) { cfg_print_subsections("List.External", "filter", "generate", 0); exit(0); } if (options.listconf && !strcasecmp(options.listconf, "ext-modes")) { cfg_print_subsections("List.External", "generate", NULL, 0); exit(0); } if (options.listconf && !strcasecmp(options.listconf, "formats")) { int column; struct fmt_main *format; int i, dynamics = 0; char **formats_list; i = 0; format = fmt_list; while ((format = format->next)) i++; formats_list = malloc(sizeof(char*) * i); i = 0; format = fmt_list; do { char *label = format->params.label; if (!strncmp(label, "dynamic", 7)) { if (dynamics++) continue; else label = "dynamic_n"; } formats_list[i++] = label; } while ((format = format->next)); formats_list[i] = NULL; column = 0; i = 0; do { int length; char *label = formats_list[i++]; length = strlen(label) + 2; column += length; if (column > 78) { printf("\n"); column = length; } printf("%s%s", label, formats_list[i] ? ", " : "\n"); } while (formats_list[i]); free(formats_list); exit(0); } if (options.listconf && !strcasecmp(options.listconf, "format-details")) { struct fmt_main *format; format = fmt_list; do { int ntests = 0; if(format->params.tests) { while (format->params.tests[ntests++].ciphertext); ntests--; } printf("%s\t%d\t%d\t%d\t%08x\t%d\t%s\t%s\t%s\t%d\t%d\t%d\n", format->params.label, format->params.plaintext_length, format->params.min_keys_per_crypt, format->params.max_keys_per_crypt, format->params.flags, ntests, format->params.algorithm_name, format->params.format_name, format->params.benchmark_comment, format->params.benchmark_length, format->params.binary_size, ((format->params.flags & FMT_DYNAMIC) && format->params.salt_size) ? // salts are handled internally within the format. We want to know the 'real' salt size // dynamic will alway set params.salt_size to 0 or sizeof a pointer. dynamic_real_salt_length(format) : format->params.salt_size); } while ((format = format->next)); exit(0); } if (options.listconf && !strcasecmp(options.listconf, "format-all-details")) { struct fmt_main *format; format = fmt_list; do { int ntests = 0; if(format->params.tests) { while (format->params.tests[ntests++].ciphertext); ntests--; } /* * attributes should be printed in the same sequence * as with format-details, but human-readable */ printf("Format label \t%s\n", format->params.label); printf("Max. password length in bytes \t%d\n", format->params.plaintext_length); printf("Min. keys per crypt \t%d\n", format->params.min_keys_per_crypt); printf("Max. keys per crypt \t%d\n", format->params.max_keys_per_crypt); printf("Flags\n"); printf(" Case sensitive \t%s\n", (format->params.flags & FMT_CASE) ? "yes" : "no"); printf(" Supports 8-bit characters \t%s\n", (format->params.flags & FMT_8_BIT) ? "yes" : "no"); printf(" Converts 8859-1 to UTF-16/UCS-2\t%s\n", (format->params.flags & FMT_UNICODE) ? "yes" : "no"); printf(" Honours --encoding=NAME \t%s\n", (format->params.flags & FMT_UTF8) ? "yes" : "no"); printf(" False positives possible \t%s\n", (format->params.flags & FMT_NOT_EXACT) ? "yes" : "no"); printf(" Uses a bitslice implementation \t%s\n", (format->params.flags & FMT_BS) ? "yes" : "no"); printf(" The split() method unifies case\t%s\n", (format->params.flags & FMT_SPLIT_UNIFIES_CASE) ? "yes" : "no"); printf(" A $dynamic$ format \t%s\n", (format->params.flags & FMT_DYNAMIC) ? "yes" : "no"); #ifdef _OPENMP printf(" Parallelized with OpenMP \t%s\n", (format->params.flags & FMT_OMP) ? "yes" : "no"); #endif printf("Number of test cases for --test \t%d\n", ntests); printf("Algorithm name \t%s\n", format->params.algorithm_name); printf("Format name \t%s\n", format->params.format_name); printf("Benchmark comment \t%s\n", format->params.benchmark_comment); printf("Benchmark length \t%d\n", format->params.benchmark_length); printf("Binary size \t%d\n", format->params.binary_size); printf("Salt size \t%d\n", ((format->params.flags & FMT_DYNAMIC) && format->params.salt_size) ? // salts are handled internally within the format. We want to know the 'real' salt size/ // dynamic will alway set params.salt_size to 0 or sizeof a pointer. dynamic_real_salt_length(format) : format->params.salt_size); printf("\n"); } while ((format = format->next)); exit(0); } if (options.listconf && !strncasecmp(options.listconf, "format-methods", 14)) { struct fmt_main *format; format = fmt_list; do { int ShowIt = 1, i; if (options.listconf[14] == '=' || options.listconf[14] == ':') { ShowIt = 0; if (!strcasecmp(&options.listconf[15], "set_key") || !strcasecmp(&options.listconf[15], "get_key") || !strcasecmp(&options.listconf[15], "crypt_all") || !strcasecmp(&options.listconf[15], "cmp_all") || !strcasecmp(&options.listconf[15], "cmp_one") || !strcasecmp(&options.listconf[15], "cmp_exact")) ShowIt = 1; else if (strcasecmp(&options.listconf[15], "init") && strcasecmp(&options.listconf[15], "prepare") && strcasecmp(&options.listconf[15], "valid") && strcasecmp(&options.listconf[15], "split") && strcasecmp(&options.listconf[15], "binary") && strcasecmp(&options.listconf[15], "clear_keys") && strcasecmp(&options.listconf[15], "salt") && strcasecmp(&options.listconf[15], "get_hash") && strcasecmp(&options.listconf[15], "get_hash[0]") && strcasecmp(&options.listconf[15], "get_hash[1]") && strcasecmp(&options.listconf[15], "get_hash[2]") && strcasecmp(&options.listconf[15], "get_hash[3]") && strcasecmp(&options.listconf[15], "get_hash[4]") && strcasecmp(&options.listconf[15], "get_hash[5]") && strcasecmp(&options.listconf[15], "set_salt") && strcasecmp(&options.listconf[15], "binary_hash") && strcasecmp(&options.listconf[15], "binary_hash[0]") && strcasecmp(&options.listconf[15], "binary_hash[1]") && strcasecmp(&options.listconf[15], "binary_hash[2]") && strcasecmp(&options.listconf[15], "binary_hash[3]") && strcasecmp(&options.listconf[15], "binary_hash[3]") && strcasecmp(&options.listconf[15], "binary_hash[5]") && strcasecmp(&options.listconf[15], "salt_hash")) { fprintf(stderr, "Error, invalid option (invalid method name) %s\n", options.listconf); fprintf(stderr, "Valid method names are:\n"); john_list_method_names(); exit(1); } if (format->methods.init != fmt_default_init && !strcasecmp(&options.listconf[15], "init")) ShowIt = 1; if (format->methods.prepare != fmt_default_prepare && !strcasecmp(&options.listconf[15], "prepare")) ShowIt = 1; if (format->methods.valid != fmt_default_valid && !strcasecmp(&options.listconf[15], "valid")) ShowIt = 1; if (format->methods.split != fmt_default_split && !strcasecmp(&options.listconf[15], "split")) ShowIt = 1; if (format->methods.binary != fmt_default_binary && !strcasecmp(&options.listconf[15], "binary")) ShowIt = 1; if (format->methods.salt != fmt_default_salt && !strcasecmp(&options.listconf[15], "salt")) ShowIt = 1; if (format->methods.clear_keys != fmt_default_clear_keys && !strcasecmp(&options.listconf[15], "clear_keys")) ShowIt = 1; for (i = 0; i < 6; ++i) { char Buf[20]; sprintf(Buf, "get_hash[%d]", i); if (format->methods.get_hash[i] && format->methods.get_hash[i] != fmt_default_get_hash && !strcasecmp(&options.listconf[15], Buf)) ShowIt = 1; } if (format->methods.get_hash[0] && format->methods.get_hash[0] != fmt_default_get_hash && !strcasecmp(&options.listconf[15], "get_hash")) ShowIt = 1; for (i = 0; i < 6; ++i) { char Buf[20]; sprintf(Buf, "binary_hash[%d]", i); if (format->methods.binary_hash[i] && format->methods.binary_hash[i] != fmt_default_binary_hash && !strcasecmp(&options.listconf[15], Buf)) ShowIt = 1; } if (format->methods.binary_hash[0] && format->methods.binary_hash[0] != fmt_default_binary_hash && !strcasecmp(&options.listconf[15], "binary_hash")) ShowIt = 1; if (format->methods.salt_hash != fmt_default_salt_hash && !strcasecmp(&options.listconf[15], "salt_hash")) ShowIt = 1; if (format->methods.set_salt != fmt_default_set_salt && !strcasecmp(&options.listconf[15], "set_salt")) ShowIt = 1; } if (ShowIt) { int i; printf("Methods overridden for: %s [%s] %s\n", format->params.label, format->params.algorithm_name, format->params.format_name); if (format->methods.init != fmt_default_init) printf("\tinit()\n"); if (format->methods.prepare != fmt_default_prepare) printf("\tprepare()\n"); if (format->methods.valid != fmt_default_valid) printf("\tvalid()\n"); if (format->methods.split != fmt_default_split) printf("\tsplit()\n"); if (format->methods.binary != fmt_default_binary) printf("\tbinary()\n"); if (format->methods.salt != fmt_default_salt) printf("\tsalt()\n"); for (i = 0; i < 6; ++i) if (format->methods.binary_hash[i] != fmt_default_binary_hash) { if (format->methods.binary_hash[i]) printf("\t\tbinary_hash[%d]()\n", i); else printf("\t\tbinary_hash[%d]() (NULL pointer)\n", i); } if (format->methods.salt_hash != fmt_default_salt_hash) printf("\tsalt_hash()\n"); if (format->methods.set_salt != fmt_default_set_salt) printf("\tset_salt()\n"); // there is no default for set_key() it must be defined. printf("\tset_key()\n"); // there is no default for get_key() it must be defined. printf("\tget_key()\n"); if (format->methods.clear_keys != fmt_default_clear_keys) printf("\tclear_keys()\n"); for (i = 0; i < 6; ++i) if (format->methods.get_hash[i] != fmt_default_get_hash) { if (format->methods.get_hash[i]) printf("\t\tget_hash[%d]()\n", i); else printf("\t\tget_hash[%d]() (NULL pointer)\n", i); } // there is no default for crypt_all() it must be defined. printf("\tcrypt_all()\n"); // there is no default for cmp_all() it must be defined. printf("\tcmp_all()\n"); // there is no default for cmp_one() it must be defined. printf("\tcmp_one()\n"); // there is no default for cmp_exact() it must be defined. printf("\tcmp_exact()\n"); printf("\n\n"); } } while ((format = format->next)); exit(0); } /* * Other --list=help:WHAT are processed earlier, but these require * a valid config: */ if (options.listconf && !strcasecmp(options.listconf, "help:parameters")) { cfg_print_section_names(1); exit(0); } if (options.listconf && !strcasecmp(options.listconf, "help:list-data")) { cfg_print_section_names(2); exit(0); } /* --list last resort: list subsections of any john.conf section name */ if (options.listconf) { //printf("Subsections of [%s]:\n", options.listconf); if (cfg_print_subsections(options.listconf, NULL, NULL, 1)) exit(0); else { fprintf(stderr, "Section [%s] not found.\n", options.listconf); /* Just in case the user specified an invalid value * like help or list... * print the same list as with --list=?, but exit(1) */ john_list_options(); exit(1); } } #ifdef CL_VERSION_1_0 if (!options.ocl_platform) { if ((options.ocl_platform = cfg_get_param(SECTION_OPTIONS, SUBSECTION_OPENCL, "Platform"))) platform_id = atoi(options.ocl_platform); else platform_id = -1; } if (!options.gpu_device) { if ((options.gpu_device = cfg_get_param(SECTION_OPTIONS, SUBSECTION_OPENCL, "Device"))) ocl_gpu_id = atoi(options.gpu_device); else ocl_gpu_id = -1; } if (platform_id == -1 || ocl_gpu_id == -1) opencl_find_gpu(&ocl_gpu_id, &platform_id); #endif common_init(); sig_init(); john_load(); if (options.encodingStr && options.encodingStr[0]) log_event("- %s input encoding enabled", options.encodingStr); }