예제 #1
0
static struct module *new_module(char *modname)
{
	struct module *mod;
	char *p, *s;

	mod = NOFAIL(malloc(sizeof(*mod)));
	memset(mod, 0, sizeof(*mod));
	p = NOFAIL(strdup(modname));

	
	s = strrchr(p, '.');
	if (s != NULL)
		if (strcmp(s, ".o") == 0) {
			*s = '\0';
			mod->is_dot_o = 1;
		}

	
	mod->name = p;
	mod->gpl_compatible = -1;
	mod->next = modules;
	modules = mod;

	return mod;
}
예제 #2
0
static char *getline_wrapped(FILE *file, unsigned int *linenum)
{
	int size = 256;
	int i = 0;
	char *buf = NOFAIL(malloc(size));
	for(;;) {
		int ch = getc_unlocked(file);
		
		switch(ch) {
			case EOF:
				if (i == 0) {
					free(buf);
					return NULL;
				}
				/* else fall through */
			
			case '\n':
				if (linenum)
					(*linenum)++;
				if (i == size)
					buf = NOFAIL(realloc(buf, size + 1));
				buf[i] = '\0';
				return buf;
			
			case '\\':
				ch = getc_unlocked(file);
			
				if (ch == '\n') {
					if (linenum)
						(*linenum)++;
					continue;
				}
				/* else fall through */
		
			default:
				buf[i++] = ch;
	
				if (i == size) {
					size *= 2;
					buf = NOFAIL(realloc(buf, size));
				}
		}
	}
}
예제 #3
0
static void add_module(char *filename, int namelen, struct list_head *list)
{
	struct module *mod;

	/* If it's a duplicate: move it to the end, so it gets
	   inserted where it is *first* required. */
	mod = find_module(filename, list);
	if (mod)
		list_del(&mod->list);
	else {
		/* No match.  Create a new module. */
		mod = NOFAIL(malloc(sizeof(struct module) + namelen + 1));
		memcpy(mod->filename, filename, namelen);
		mod->filename[namelen] = '\0';
		mod->modname = NOFAIL(malloc(namelen + 1));
		filename2modname(mod->modname, mod->filename);
	}

	list_add_tail(&mod->list, list);
}
예제 #4
0
파일: modpost.c 프로젝트: nyyotam/u-boot
/**
 * Allocate a new symbols for use in the hash of exported symbols or
 * the list of unresolved symbols per module
 **/
static struct symbol *alloc_symbol(const char *name, unsigned int weak,
				   struct symbol *next)
{
	struct symbol *s = NOFAIL(malloc(sizeof(*s) + strlen(name) + 1));

	memset(s, 0, sizeof(*s));
	strcpy(s->name, name);
	s->weak = weak;
	s->next = next;
	return s;
}
예제 #5
0
파일: modpost.c 프로젝트: nyyotam/u-boot
static struct module *new_module(char *modname)
{
	struct module *mod;
	char *p, *s;

	mod = NOFAIL(malloc(sizeof(*mod)));
	memset(mod, 0, sizeof(*mod));
	p = NOFAIL(strdup(modname));

	/* strip trailing .o */
	if ((s = strrchr(p, '.')) != NULL)
		if (strcmp(s, ".o") == 0)
			*s = '\0';

	/* add to list */
	mod->name = p;
	mod->gpl_compatible = -1;
	mod->next = modules;
	modules = mod;

	return mod;
}
예제 #6
0
파일: lattice_kernel.c 프로젝트: NHALX/llio
opencl_allocinfo
linext__allocnfo__(opencl_function *func, ideal_lattice *g)
{
    cl_ulong klmem;
    opencl_allocinfo nfo = { 0 };

    NOFAIL(clGetKernelWorkGroupInfo(func->kernel, func->ctx->device,
        CL_KERNEL_LOCAL_MEM_SIZE, sizeof klmem, &klmem, 0));

    nfo.fixed.global += g->edge_count * (sizeof *g->ideals + sizeof *g->neighbors);
    nfo.fixed.global += g->vertex_count * sizeof *g->counts;

    nfo.scale_pass.global += g->linext_width * sizeof(*g->ideals);
    nfo.scale_workgroup.local += klmem;
    return nfo;
}
예제 #7
0
파일: k_build_combo.c 프로젝트: NHALX/llio
opencl_allocinfo
build_combo__allocnfo__(opencl_function *func, size_t items_n)
{
    cl_ulong klmem;
    opencl_allocinfo nfo = { 0 };

    NOFAIL(clGetKernelWorkGroupInfo(func->kernel, func->ctx->device,
        CL_KERNEL_LOCAL_MEM_SIZE, sizeof klmem, &klmem, 0));
 
    nfo.fixed.constant += sizeof (item_t)* items_n;

    nfo.scale_workgroup.local += sizeof (setmax_t)* items_n;
    nfo.scale_workgroup.local += sizeof (result_t);
    nfo.scale_workgroup.local += klmem;

    nfo.scale_reduce.global = sizeof (result_t);
    return nfo;
}
예제 #8
0
static struct param *add_param(const char *name, struct param **list)
{
    struct param *i;
    unsigned int namelen = strcspn(name, ":") + 1;

    for (i = *list; i; i = i->next)
        if (strncmp(i->name, name, namelen) == 0)
            return i;
    i = NOFAIL(malloc(sizeof(*i) + namelen+1));
    strncpy((char *)(i + 1), name, namelen);
    ((char *)(i + 1))[namelen] = '\0';
    i->name = (char *)(i + 1);
    i->param = NULL;
    i->type = NULL;
    i->next = *list;
    *list = i;
    return i;
}
예제 #9
0
intptr_t WINAPI GetFindDataW(GetFindDataInfo* info) {
  PluginInstance* plugin = (PluginInstance*) info->hPanel;
  bool show_error = (info->OpMode & (OPM_SILENT | OPM_FIND | OPM_QUICKVIEW)) == 0;
  try {
    UiLink ui((info->OpMode & OPM_SILENT) != 0);
    PluginItemList file_list;
    plugin->last_object = plugin->current_dir;
    FileListOptions options;
    options.hide_rom_files = g_plugin_options.hide_rom_files;
    gen_file_list(plugin->current_dir, plugin->session, file_list, options, ui);
    plugin->file_lists += file_list;
    info->PanelItem = (PluginPanelItem*) plugin->file_lists.last().data();
    info->ItemsNumber = plugin->file_lists.last().size();
    if (!(info->OpMode & OPM_FIND)) NOFAIL(refresh_system_info(plugin));
    return TRUE;
  }
  HANDLE_ERROR(FALSE, TRUE);
}
예제 #10
0
파일: mkpasswd.c 프로젝트: freddy36/whois
void* get_random_bytes(const int count)
{
    char *buf;
    int fd;

    buf = NOFAIL(malloc(count));
    fd = open(RANDOM_DEVICE, O_RDONLY);
    if (fd < 0) {
	perror("open(" RANDOM_DEVICE ")");
	exit(2);
    }
    if (read(fd, buf, count) != count) {
	if (count < 0)
	    perror("read(" RANDOM_DEVICE ")");
	else
	    fprintf(stderr, "Short read of %s.\n", RANDOM_DEVICE);
	exit(2);
    }
    close(fd);

    return buf;
}
예제 #11
0
파일: mkpasswd.c 프로젝트: freddy36/whois
int main(int argc, char *argv[])
{
    int ch, i;
    int password_fd = -1;
    unsigned int salt_minlen = 0;
    unsigned int salt_maxlen = 0;
    unsigned int rounds_support = 0;
    const char *salt_prefix = NULL;
    const char *salt_arg = NULL;
    unsigned int rounds = 0;
    char *salt = NULL;
    char rounds_str[30];
    char *password = NULL;

#ifdef ENABLE_NLS
    setlocale(LC_ALL, "");
    bindtextdomain(NLS_CAT_NAME, LOCALEDIR);
    textdomain(NLS_CAT_NAME);
#endif

    /* prepend options from environment */
    argv = merge_args(getenv("MKPASSWD_OPTIONS"), argv, &argc);

    while ((ch = GETOPT_LONGISH(argc, argv, "hH:m:5P:R:sS:V", longopts, 0))
	    > 0) {
	switch (ch) {
	case '5':
	    optarg = (char *) "md5";
	    /* fall through */
	case 'm':
	case 'H':
	    if (!optarg || strcaseeq("help", optarg)) {
		display_methods();
		exit(0);
	    }
	    for (i = 0; methods[i].method != NULL; i++)
		if (strcaseeq(methods[i].method, optarg)) {
		    salt_prefix = methods[i].prefix;
		    salt_minlen = methods[i].minlen;
		    salt_maxlen = methods[i].maxlen;
		    rounds_support = methods[i].rounds;
		    break;
		}
	    if (!salt_prefix) {
		fprintf(stderr, _("Invalid method '%s'.\n"), optarg);
		exit(1);
	    }
	    break;
	case 'P':
	    {
		char *p;
		password_fd = strtol(optarg, &p, 10);
		if (p == NULL || *p != '\0' || password_fd < 0) {
		    fprintf(stderr, _("Invalid number '%s'.\n"), optarg);
		    exit(1);
		}
	    }
	    break;
	case 'R':
	    {
		char *p;
		long r;

		r = strtol(optarg, &p, 10);
		if (p == NULL || *p != '\0' || r < 0) {
		    fprintf(stderr, _("Invalid number '%s'.\n"), optarg);
		    exit(1);
		}
		rounds = r;
	    }
	    break;
	case 's':
	    password_fd = 0;
	    break;
	case 'S':
	    salt_arg = optarg;
	    break;
	case 'V':
	    display_version();
	    exit(0);
	case 'h':
	    display_help(EXIT_SUCCESS);
	default:
	    fprintf(stderr, _("Try '%s --help' for more information.\n"),
		    argv[0]);
	    exit(1);
	}
    }
    argc -= optind;
    argv += optind;

    if (argc == 2 && !salt_arg) {
	password = argv[0];
	salt_arg = argv[1];
    } else if (argc == 1) {
	password = argv[0];
    } else if (argc == 0) {
    } else {
	display_help(EXIT_FAILURE);
    }

    /* default: DES password */
    if (!salt_prefix) {
	salt_minlen = methods[0].minlen;
	salt_maxlen = methods[0].maxlen;
	salt_prefix = methods[0].prefix;
    }

    if (streq(salt_prefix, "$2a$") || streq(salt_prefix, "$2y$")) {
	/* OpenBSD Blowfish and derivatives */
	if (rounds <= 5)
	    rounds = 5;
	/* actually for 2a/2y it is the logarithm of the number of rounds */
	snprintf(rounds_str, sizeof(rounds_str), "%02u$", rounds);
    } else if (rounds_support && rounds)
	snprintf(rounds_str, sizeof(rounds_str), "rounds=%u$", rounds);
    else
	rounds_str[0] = '\0';

    if (salt_arg) {
	unsigned int c = strlen(salt_arg);
	if (c < salt_minlen || c > salt_maxlen) {
	    if (salt_minlen == salt_maxlen)
		fprintf(stderr, ngettext(
			"Wrong salt length: %d byte when %d expected.\n",
			"Wrong salt length: %d bytes when %d expected.\n", c),
			c, salt_maxlen);
	    else
		fprintf(stderr, ngettext(
			"Wrong salt length: %d byte when %d <= n <= %d"
			" expected.\n",
			"Wrong salt length: %d bytes when %d <= n <= %d"
			" expected.\n", c),
			c, salt_minlen, salt_maxlen);
	    exit(1);
	}
	while (c-- > 0) {
	    if (strchr(valid_salts, salt_arg[c]) == NULL) {
		fprintf(stderr, _("Illegal salt character '%c'.\n"),
			salt_arg[c]);
		exit(1);
	    }
	}

	salt = NOFAIL(malloc(strlen(salt_prefix) + strlen(rounds_str)
		+ strlen(salt_arg) + 1));
	*salt = '\0';
	strcat(salt, salt_prefix);
	strcat(salt, rounds_str);
	strcat(salt, salt_arg);
    } else {
#ifdef HAVE_SOLARIS_CRYPT_GENSALT
	salt = crypt_gensalt(salt_prefix, NULL);
	if (!salt)
		perror("crypt_gensalt");
#elif defined HAVE_LINUX_CRYPT_GENSALT
	void *entropy = get_random_bytes(64);

	salt = crypt_gensalt(salt_prefix, rounds, entropy, 64);
	if (!salt) {
		fprintf(stderr, "crypt_gensalt failed.\n");
		exit(2);
	}
	free(entropy);
#else
	unsigned int salt_len = salt_maxlen;

	if (salt_minlen != salt_maxlen) { /* salt length can vary */
	    srand(time(NULL) + getpid());
	    salt_len = rand() % (salt_maxlen - salt_minlen + 1) + salt_minlen;
	}

	salt = NOFAIL(malloc(strlen(salt_prefix) + strlen(rounds_str)
		+ salt_len + 1));
	*salt = '\0';
	strcat(salt, salt_prefix);
	strcat(salt, rounds_str);
	generate_salt(salt + strlen(salt), salt_len);
#endif
    }

    if (password) {
    } else if (password_fd != -1) {
	FILE *fp;
	char *p;

	if (isatty(password_fd))
	    fprintf(stderr, _("Password: "******"r");
	if (!fp) {
	    perror("fdopen");
	    exit(2);
	}
	if (!fgets(password, 128, fp)) {
	    perror("fgets");
	    exit(2);
	}

	p = strpbrk(password, "\n\r");
	if (p)
	    *p = '\0';
    } else {
	password = getpass(_("Password: "******"getpass");
	    exit(2);
	}
    }

    {
	const char *result;
	result = crypt(password, salt);
	/* xcrypt returns "*0" on errors */
	if (!result || result[0] == '*') {
	    fprintf(stderr, "crypt failed.\n");
	    exit(2);
	}
	/* yes, using strlen(salt_prefix) on salt. It's not
	 * documented whether crypt_gensalt may change the prefix */
	if (!strneq(result, salt, strlen(salt_prefix))) {
	    fprintf(stderr, _("Method not supported by crypt(3).\n"));
	    exit(2);
	}
	printf("%s\n", result);
    }

    exit(0);
}
예제 #12
0
int main(int argc, char *argv[])
{
	unsigned int i;
	long int ret;
	unsigned long len;
	void *file;
	char *filename, *options = strdup("");
	char *p, *progname = argv[0];

	if (!options) {
		fprintf(stderr,
			"insmod: can't allocate memory: %s\n", strerror(errno));
		exit(1);
	}

	p = my_basename(argv[0]);

	if (argv[1] && (streq(argv[1], "--version") || streq(argv[1], "-V"))) {
		puts(PACKAGE " version " VERSION);
		exit(0);
	}

	/*
	 * kdi-addition
	 */
	if (argv[1] && streq(argv[1], "-K")) {
		flag_kdi = 1;
		flag_use_kdi = 1;
		argv++;
		argc--;
		kdi_name = NOFAIL(strdup(argv[1]));
		argv++;
		argc--;
	}

	if (argv[1] && streq(argv[1], "-F")) {
		flag_kdi = 1;
		flag_inject_faults = 1;
		argv++;
		argc--;
	}

	if (argv[1] && streq(argv[1], "-T")) {
		flag_kdi = 1;
		flag_use_kdi_shadow = 1;
		argv++;
		argc--;
		shadow_type = NOFAIL(strdup(argv[1]));
		argv++;
		argc--;
	}

	if (argv[1] && streq(argv[1], "-N")) {
		flag_kdi = 1;
		flag_use_kdi = 1;
		flag_clobber_kdi = 1;
		argv++;
		argc--;
		clobber_module_name = NOFAIL(strdup(argv[1]));
		argv++;
		argc--;
	}
	/*
	 * kdi-end
	 */

	/* Ignore old options, for backwards compat. */
	while (argv[1] && (streq(argv[1], "-p")
			   || streq(argv[1], "-s")
			   || streq(argv[1], "-f"))) {
		argv++;
		argc--;
	}

	filename = argv[1];
	if (!filename)
		print_usage(progname);

	/* Rest is options */
	for (i = 2; i < argc; i++) {
		options = realloc(options,
				  strlen(options) + 1 + strlen(argv[i]) + 1);
		if (!options) {
			fprintf(stderr,
				"insmod: can't allocate memory: %s\n",
				strerror(errno));
			exit(1);
		}
		strcat(options, argv[i]);
		strcat(options, " ");
	}

	file = grab_file(filename, &len);
	if (!file) {
		fprintf(stderr, "insmod: can't read '%s': %s\n",
			filename, strerror(errno));
		exit(1);
	}

	/*
	 * kdi-addition
	 */
	if (flag_kdi) {
		if (init_kdi() != 0)
			exit(1);
		struct kdi_uargs *kdi_opts = malloc(sizeof(struct kdi_uargs));
		kdi_opts->use_kdi = flag_use_kdi;
		kdi_opts->use_kdi_shadow = flag_use_kdi_shadow;
		kdi_opts->inject_faults = flag_inject_faults;
		kdi_opts->clobber_kdi = flag_clobber_kdi;
		if (kdi_name)
			strncpy(kdi_opts->kdi_name, kdi_name, 100);
		if (clobber_module_name)
			strncpy(kdi_opts->clobber_module_name, clobber_module_name, 100);
		if (shadow_type)
			strncpy(kdi_opts->shadow_type, shadow_type, 100);

		ret = syscall(SYS_kdi_init_module, file, len, options, kdi_opts);
	} else
		ret = init_module(file, len, options);
	/*
	 * kdi-end
	 */
	if (ret != 0) {
		fprintf(stderr, "insmod: error inserting '%s': %li %s\n",
			filename, ret, moderror(errno));
	}
	free(file);

	/*
	 * kdi-addition
	 */
	if (ret != 0 && flag_created_kdi == 1)
		syscall(SYS_kdi_delete_kdi, kdi_name);
	/*
	 * kdi-end
	 */
	if (ret != 0)
		exit(1);
	exit(0);
}
예제 #13
0
static struct index_node_f *index_read(FILE *in, uint32_t offset)
{
	struct index_node_f *node;
	char *prefix;
	int i, child_count = 0;

	if ((offset & INDEX_NODE_MASK) == 0)
		return NULL;

	fseek(in, offset & INDEX_NODE_MASK, SEEK_SET);

	if (offset & INDEX_NODE_PREFIX) {
		struct buffer buf;
		buf_init(&buf);
		buf_freadchars(&buf, in);
		prefix = buf_steal(&buf);
	} else
		prefix = NOFAIL(strdup(""));

	if (offset & INDEX_NODE_CHILDS) {
		char first = read_char(in);
		char last = read_char(in);
		child_count = last - first + 1;

		node = NOFAIL(malloc(sizeof(struct index_node_f) +
				     sizeof(uint32_t) * child_count));

		node->first = first;
		node->last = last;

		for (i = 0; i < child_count; i++)
			node->children[i] = read_long(in);
	} else {
		node = NOFAIL(malloc(sizeof(struct index_node_f)));
		node->first = INDEX_CHILDMAX;
		node->last = 0;
	}

	node->values = NULL;
	if (offset & INDEX_NODE_VALUES) {
		int value_count;
		struct buffer buf;
		const char *value;
		unsigned int priority;

		value_count = read_long(in);

		buf_init(&buf);
		while (value_count--) {
			priority = read_long(in);
			buf_freadchars(&buf, in);
			value = buf_str(&buf);
			add_value(&node->values, value, buf.used, priority);
			buf_clear(&buf);
		}
		buf_release(&buf);
	}

	node->prefix = prefix;
	node->file = in;
	return node;
}
예제 #14
0
HANDLE WINAPI OpenW(const OpenInfo* info) {
  try {
    if (info->OpenFrom == OPEN_COMMANDLINE) {
      // test if plugin is already open on active panel
      for (unsigned i = 0; i < g_plugin_objects.size(); i++) {
        PanelInfo pi;
        if (far_control_ptr(g_plugin_objects[i], FCTL_GETPANELINFO, &pi)) {
          if (pi.Flags & PFLAGS_FOCUS) {
            // change current directory of active plugin
            set_dir(g_plugin_objects[i], reinterpret_cast<OpenCommandLineInfo*>(info->Data)->CommandLine, true);
            far_control_int(INVALID_HANDLE_VALUE, FCTL_UPDATEPANEL, 0);
            PanelRedrawInfo pri = { sizeof(PanelRedrawInfo) };
            pri.CurrentItem = 0;
            pri.TopPanelItem = 0;
            far_control_ptr(INVALID_HANDLE_VALUE, FCTL_REDRAWPANEL, &pri);
            // do not create new plugin instance
            return nullptr;
          }
        }
      }
    }
    init_if_needed();
    ObjectArray<DeviceInfo> dev_list;
    get_device_list(dev_list);
    if (dev_list.size() == 0) FAIL(MsgError(far_get_msg(MSG_ERR_NO_DEVICE)));
    intptr_t mi = 0;
    if (dev_list.size() > 1) {
      ObjectArray<UnicodeString> menu_str;
      for (unsigned i = 0; i < dev_list.size(); i++) {
        menu_str += UnicodeString::format(L"%S %S (%S)", &dev_list[i].name, &dev_list[i].platform, &dev_list[i].con_type);
      }
      mi = far_menu(c_device_list_menu_guid, far_get_msg(MSG_DEVICE_LIST_TITLE), menu_str);
      if (mi == -1) BREAK;
    }
    PluginInstance* plugin = new PluginInstance();
    try {
      plugin->device_info = dev_list[mi];
      create_session(plugin->device_info.id, plugin);
      if (info->OpenFrom == OPEN_COMMANDLINE) {
        // directory is specified on command line
        plugin->current_dir = reinterpret_cast<OpenCommandLineInfo*>(info->Data)->CommandLine;
        if (!dir_exists(plugin->current_dir, plugin->session)) plugin->current_dir = L"\\";
      }
      else if (g_plugin_options.save_last_dir) {
        // restore last directory
        plugin->current_dir = load_last_dir(plugin->device_info.strid());
        if (!dir_exists(plugin->current_dir, plugin->session)) plugin->current_dir = L"\\";
      }
      else {
        plugin->current_dir = L"\\";
      }
      NOFAIL(refresh_system_info(plugin));
      g_plugin_objects += plugin;
    }
    catch (...) {
      delete plugin;
      throw;
    }
    return plugin;
  }
  catch (Break&) {
  }
  catch (MsgError& e) {
    msg_dlg(e.message());
  }
  catch (Error& e) {
    LOG_ERR(e);
    error_dlg(e, far_get_msg(MSG_ERR_PLUGIN_INIT));
  }
  catch (...) {
    far_message(c_error_dialog_guid, L"\nFailure!", 0, FMSG_WARNING | FMSG_MB_OK);
  }
  return nullptr;
}