/**
* install: Puts the defined name and its definition into the hashtab
*
* Returns: A pointer to the nlist item
*/
nlist *install(char *name, char *defn, char **args, int numvars) {
    nlist *np;
    unsigned hashval;

    if ((np = lookup(name)) == NULL) {  // not found in hashtab
        np = (nlist*)malloc(sizeof(*np));
        if (np == NULL || (np->name = strdup2(name)) == NULL)
            return NULL;
        hashval = hash(name);
        np->next = hashtab[hashval];  // pushes any names with the same hash
        hashtab[hashval] = np;        // value back and takes its place
    }
    else {                            // already there
        free((void*)np->defn);  // free previous defn
        np->args = NULL;
    }
    if ((np->defn = strdup2(defn)) == NULL) {
        np->args = NULL;
        return NULL;
    }
    else {
        np->args = args;
        np->numvars = numvars;
    }
    return np;
}
예제 #2
0
static void handle_menu_section_packet(Simply *simply, Packet *data) {
  MenuSectionPacket *packet = (MenuSectionPacket*) data;
  SimplyMenuSection *section = malloc(sizeof(*section));
  *section = (SimplyMenuSection) {
    .section = packet->section,
    .num_items = packet->num_items,
    .title = packet->title_length ? strdup2(packet->title) : NULL,
  };
  simply_menu_add_section(simply->menu, section);
}

static void handle_menu_item_packet(Simply *simply, Packet *data) {
  MenuItemPacket *packet = (MenuItemPacket*) data;
  SimplyMenuItem *item = malloc(sizeof(*item));
  *item = (SimplyMenuItem) {
    .section = packet->section,
    .item = packet->item,
    .title = packet->title_length ? strdup2(packet->buffer) : NULL,
    .subtitle = packet->subtitle_length ? strdup2(packet->buffer + packet->title_length + 1) : NULL,
    .icon = packet->icon,
  };
  simply_menu_add_item(simply->menu, item);
}

static void handle_menu_get_selection_packet(Simply *simply, Packet *data) {
  simply_msg_send_menu_selection(simply->msg);
}
예제 #3
0
파일: grub2.c 프로젝트: noryb009/lick
int uninstall_grub2(lickdir_t *lick) {
    char drive = mount_uefi_partition();
    if(drive == '\0') {
        if(!lick->err)
            lick->err = strdup2("Could not mount EFI partition.");
        return 0;
    }

    if(!fix_grub2_inner(lick, GRUB2_FIX_UNINSTALL, drive)) {
        unmount_uefi_partition(drive);
        if(!lick->err)
            lick->err = strdup2("Could not revert boot fix.");
        return 0;
    }

    char *grub_cfg = unix_path(concat_strs(2, lick->drive, "/lickgrub.cfg"));
    if(!has_valuable_info(grub_cfg)) {
        unlink_file(grub_cfg);
    }
    free(grub_cfg);

    char *lick_cert = strdup2("?:/lick.cer");
    lick_cert[0] = drive;
    unlink_file(lick_cert);
    free(lick_cert);

    char lick_dir[] = "?:/EFI/LICK";
    lick_dir[0] = drive;
    unlink_recursive(lick_dir);
    unmount_uefi_partition(drive);

    return 1;
}
예제 #4
0
파일: fcrondyn.c 프로젝트: colmsjo/batches
/* Generator function for command completion. STATE lets us know whether
   to start from scratch; without any state (i.e. STATE == 0), then we
   start at the top of the list. */
char *
rl_cmpl_command_generator(const char *text, int state)
{
    static int list_index, len;
    char *name = NULL;

    /* If this is a new word to complete, initialize now.  This includes
     * saving the length of TEXT for efficiency, and initializing the index
     * variable to 0. */
    if (!state) {
        list_index = 0;
        len = strlen(text);
    }

    /* Return the next name which partially matches from the command list. */
    while (list_index < cmd_list_len) {
        name = cmd_list[list_index].cmd_name;
        list_index++;
        if (strncmp(name, text, len) == 0) {
            return (strdup2(name));
        }
    }

    /* If no names matched, then return NULL. */
    return ((char *)NULL);
}
예제 #5
0
int Widget_SetAttributeEx(LCUI_Widget w, const char *name, void *value,
			  int value_type, void (*value_destructor)(void *))
{
	LCUI_WidgetAttribute attr;

	if (!self.available) {
		self.dt_attributes = DictType_StringCopyKey;
		self.dt_attributes.valDestructor = OnClearWidgetAttribute;
		self.available = TRUE;
	}
	if (!w->attributes) {
		w->attributes = Dict_Create(&self.dt_attributes, NULL);
	}
	attr = Dict_FetchValue(w->attributes, name);
	if (attr) {
		if (attr->value.destructor) {
			attr->value.destructor(attr->value.data);
		}
	} else {
		attr = NEW(LCUI_WidgetAttributeRec, 1);
		attr->name = strdup2(name);
		Dict_Add(w->attributes, attr->name, attr);
	}
	attr->value.data = value;
	attr->value.type = value_type;
	attr->value.destructor = value_destructor;
	return 0;
}
예제 #6
0
파일: uniso.c 프로젝트: noryb009/lick
int extract_iso(uniso_status_t *s, struct archive *iso, const char *dst,
        distro_filter_f filter, uniso_progress_t total, uniso_progress_cb cb,
        void *cb_data) {
    struct archive_entry *e;
    uniso_progress_t current = 0;

    make_dir_parents(dst);

    if(cb)
        cb(current, total, cb_data);

    while(archive_read_next_header(iso, &e) == ARCHIVE_OK) {
        char *name = unix_path(strdup2(archive_entry_pathname(e)));
        if(archive_entry_filetype(e) == AE_IFDIR
                || !filter(name)) {
            free(name);
            continue;
        }
        s->files = new_string_node_t(name, s->files);
        char *dest = unix_path(create_dest(dst, "/", name));
        if(!extract_file(s, iso, dest)) {
            free(dest);
            return 0;
        }
        ++current;
        if(cb)
            cb(current, total, cb_data);
        free(dest);
    }

    return 1;
}
예제 #7
0
int main(int argc, char **argv)
{
	char * chaine1 = "Coucou c'est moi";
	char * copie = strdup2(chaine1);
	printf("Chaîne originale : %s \nChaîne copie : %s\n", chaine1, copie);
	exit(0);
}
예제 #8
0
파일: wordcount.c 프로젝트: bnjzer/c
struct tnode *addtree(struct tnode *p, char *w, int nline){
  int cond;

  if(p == NULL){ // it's a new word
    p = talloc(); //get addres for new node
    p->word = strdup2(w);
    p->count = 1;
    p->left = p->right = NULL;
    p->lines[0] = nline;
    p->indLastoccurence = 0;
  } else if((cond = strcmp(w, p->word)) < 0)
    p->left = addtree(p->left, w, nline);
  else if(cond > 0)
    p->right = addtree(p->right, w,nline);
  else {
    p->count++;
    if(p->indLastoccurence == MAXOCCURENCE-1)
      printf("Max occurences reached for word %s\n", p->word);
    else
      if(p->lines[p->indLastoccurence] != nline)
        p->lines[++p->indLastoccurence] = nline;
  }

  return p;
}
예제 #9
0
/* Take a space-separated list and return an array of (char *) */
static DEP *
makelist(char * str, size_t * n)
{
	DEP * d;
	size_t i;

	/* No depends at all? */
	if (str[0] == 0) {
		*n = 0;
		return NULL;
	}

	/* Count the number of fields */
	*n = 1;
	for (i = 0; str[i] != 0; i++)
		if (str[i] == ' ')
			(*n)++;

	/* Allocate and fill an array */
	d = malloc(*n * sizeof(DEP));
	if (d == NULL)
		err(1, "malloc(DEP)");
	for (i = 0; i < *n; i++) {
		d[i].name = strdup2(strsep(&str, " "));

		/* Strip trailing slashes */
		if (d[i].name[strlen(d[i].name) - 1] == '/')
			d[i].name[strlen(d[i].name) - 1] = 0;
	}

	return d;
}
예제 #10
0
int
main(int argc, char **argv)
{
    struct passwd *pass = NULL;
    char *cur_user = NULL;

    rootuid = get_user_uid_safe(ROOTNAME);
    rootgid = get_group_gid_safe(ROOTGROUP);

    if (strrchr(argv[0], '/') == NULL)
        prog_name = argv[0];
    else
        prog_name = strrchr(argv[0], '/') + 1;

    fcrontab_uid = get_user_uid_safe(USERNAME);

#ifdef USE_SETE_ID
    /* get user's permissions */
    if (seteuid(fcrontab_uid) != 0)
        die_e("Could not change euid to " USERNAME "[%d]", uid);
#endif                          /* USE_SETE_ID */

    if (argc == 2)
        fcronconf = argv[1];
    else if (argc > 2)
        usage();

    /* read fcron.conf and update global parameters */
    /* We deactivate output to console, because otherwise it may be used
     * by a malicious user to read some data it is not allow to read
     * (fcronsighup is suid root) */
    foreground = 0;
    read_conf();
    foreground = 1;

    uid = getuid();

    /* check if user is allowed to use this program */
    if (!(pass = getpwuid(uid)))
        die("user \"%s\" is not in passwd file. Aborting.", USERNAME);
    cur_user = strdup2(pass->pw_name);

    if (is_allowed(cur_user)) {
        /* check if daemon is running */
        if ((daemon_pid = read_pid()) != 0)
            sig_daemon();
        else
            fprintf(stderr, "fcron is not running :\n  modifications will"
                    " be taken into account at its next execution.\n");
    }
    else
        die("User \"%s\" is not allowed to use %s. Aborting.", cur_user,
            prog_name);

    if (cur_user)
        free(cur_user);
    return EXIT_OK;

}
예제 #11
0
파일: define.c 프로젝트: chrzhang/c.sandbox
/* install: put (name, defn) in hashtab */
struct nlist *install(char *name, char *defn) {
	struct nlist *np;
	unsigned hashval;
	if ((np = lookup(name)) == NULL) { /* not found */
		np = (struct nlist *) malloc(sizeof(*np));
		if (np == NULL || (np->name = strdup2(name)) == NULL)
			return NULL;
		hashval = hash(name);
		np->next = hashtab[hashval];
		hashtab[hashval] = np;
	}
	else /* already there */
		free((void *)np->defn); /*free previous defn */
	if ((np->defn = strdup2(defn)) == NULL)
		return NULL;
	return np;
}
예제 #12
0
파일: uniso.c 프로젝트: noryb009/lick
struct archive *uniso_open(uniso_status_t *s, const char *src) {
    struct archive *iso = archive_read_new();
    archive_read_support_format_iso9660(iso);
    if(archive_read_open_filename(iso, src, 10240) != ARCHIVE_OK) {
        s->error = strdup2("Could not open ISO file.");
        return NULL;
    }
    return iso;
}
예제 #13
0
파일: e06.c 프로젝트: kokosabu/exercises
struct nlist *install(char *name, char *defn)
{
    struct nlist *np;
    unsigned hashval;

    if ((np = lookup(name)) == NULL) {
        np = (struct nlist *) malloc(sizeof(*np));
        if (np == NULL || (np->name = strdup2(name)) == NULL)
            return NULL;
        hashval = hash(name);
        np->next = hashtab[hashval];
        hashtab[hashval] = np;
    } else {
        free((void *) np->defn);
    } if ((np->defn = strdup2(defn)) == NULL)
        return NULL;
    return np;
}
예제 #14
0
static void InitMapFiles(const char *path)
{
  mapFiles.items_script = strdup2(path,XITEMS_SCRIPT);
  mapFiles.items_pics = strdup2(path,XITEMS_PICS);
  mapFiles.items_dat = strdup2(path,XITEM_FILE);
  mapFiles.dialogy_scr = strdup2(path,XDLG_SCRIPT);
  mapFiles.weapons_scr = strdup2(path,XWEAPONS_SCRIPT);
  mapFiles.shops_dat = strdup2(path,XSHOP_NAME);
  mapFiles.enemy = strdup2(path,XMOB_FILE);
  mapFiles.enemy_sound = strdup2(path,XMOB_SOUND);
}
예제 #15
0
파일: uniso.c 프로젝트: noryb009/lick
uniso_progress_t count_in_iso(struct archive *iso,
        distro_filter_f filter) {
    uniso_progress_t total = 0;
    struct archive_entry *e;

    while(archive_read_next_header(iso, &e) == ARCHIVE_OK) {
        char *name = strdup2(archive_entry_pathname(e));
        if(archive_entry_filetype(e) != AE_IFDIR
                && filter(name))
            ++total;
        free(name);
    }

    return total;
}
예제 #16
0
파일: grub2.c 프로젝트: noryb009/lick
int install_grub2(lickdir_t *lick) {
    char *grub_cfg_lick = unix_path(concat_strs(2, lick->drive, "/lickgrub.cfg"));
    if(!path_exists(grub_cfg_lick)) {
        char *grub_cfg_header = unix_path(concat_strs(2, lick->res, "/lickgrub.cfg"));
        if(!copy_file(grub_cfg_lick, grub_cfg_header)) {
            free(grub_cfg_lick);
            free(grub_cfg_header);
            if(!lick->err)
                lick->err = strdup2("Error writing to grub menu.");
            return 0;
        }
        free(grub_cfg_header);
    }
    free(grub_cfg_lick);
    return 1;
}
예제 #17
0
/******************************** Word Counting with Binary Tree
 * *******************************/
WordNode *addWord(WordNode *p, char *w) {
	int cond;

	if (p == NULL) {  /* a new word has arrived */
		p = walloc(); /* make a new node */
		p->word = strdup2(w);
		p->count = 1;
		p->left = p->right = NULL;
	} else if ((cond = strcmp(p->word, w)) == 0)
		p->count++;    /* repeated word */
	else if (cond < 0) /* less than into left subtree */
		p->left = addWord(p->left, w);
	else /* greater than into right subtree */
		p->right = addWord(p->right, w);
	return p;
}
/* addtree */
struct tnode *addtree(struct tnode *p, char *w) {
    int cond;

    if (p == NULL) {    // a new word has arrived
        p = talloc();   // make a new node
        p->word = strdup2(w);
        p->count = 1;
        p->left = p->right = NULL;
    }
    else if ((cond = strcmp(w, p->word)) == 0)
        p->count++;     // repeated word
    else if (cond < 0)  // less than into left subtree
        p->left = addtree(p->left, w);
    else                // greater than into right subtree
        p->right = addtree(p->right, w);
    return p;
}
예제 #19
0
파일: tree.c 프로젝트: gkeown/cProgramming
/* addtree: add a node with w, at or below p */
struct tnode *
addtree(struct tnode *p, char *w)
{
    int cond;

    if (p == NULL) {    /* a new word has arrived */
        p = talloc();   /* make a nnew node */
        p->word = strdup2(w);
        p->count = 1;
        p->left = p->right = NULL;
    } else if ((cond = strcmp(w, p->word)) == 0) {
        p->count++; /* repeated word */
    } else if (cond < 0) { /* less than into left subtree */
        p->left = addtree(p->left, w);
    } else { /* greater than into right subtree */
        p->right = addtree(p->right, w);
    }
    return p;
}
예제 #20
0
/* Take a port's describe line and split it into fields */
static PORT *
portify(char * line)
{
	PORT * p;
	size_t i, n;

	/* Verify that line has the right number of fields */
	for (n = i = 0; line[i] != 0; i++)
		if (line[i] == '|')
			n++;
	if (n != 12)
		errx(1, "Port describe line is corrupt:\n%s\n", line);

	p = malloc(sizeof(PORT));
	if (p == NULL)
		err(1, "malloc(PORT)");

	p->pkgname = strdup2(strsep(&line, "|"));
	p->portdir = strdup2(strsep(&line, "|"));
	p->prefix = strdup2(strsep(&line, "|"));
	p->comment = strdup2(strsep(&line, "|"));
	p->pkgdescr = strdup2(strsep(&line, "|"));
	p->maintainer = strdup2(strsep(&line, "|"));
	p->categories = strdup2(strsep(&line, "|"));
	p->edep = makelist(strsep(&line, "|"), &p->n_edep);
	p->pdep = makelist(strsep(&line, "|"), &p->n_pdep);
	p->fdep = makelist(strsep(&line, "|"), &p->n_fdep);
	p->bdep = makelist(strsep(&line, "|"), &p->n_bdep);
	p->rdep = makelist(strsep(&line, "|"), &p->n_rdep);
	p->www = strdup2(strsep(&line, "|"));

	p->recursed = 0;

	/*
	 * line will now be equal to NULL -- we counted the field
	 * separators at the top of the function.
	 */

	return p;
}
예제 #21
0
파일: widget_base.c 프로젝트: lc-soft/LCUI
LCUI_Widget LCUIWidget_New(const char *type)
{
	ASSIGN(widget, LCUI_Widget);
	Widget_Init(widget);
	widget->node.data = widget;
	widget->node_show.data = widget;
	widget->node.next = widget->node.prev = NULL;
	widget->node_show.next = widget->node_show.prev = NULL;
	if (type) {
		widget->proto = LCUIWidget_GetPrototype(type);
		if (widget->proto) {
			widget->type = widget->proto->name;
			widget->proto->init(widget);
		} else {
			widget->type = strdup2(type);
		}
	}
	Widget_AddTask(widget, LCUI_WTASK_REFRESH_STYLE);
	return widget;
}
예제 #22
0
파일: nt.c 프로젝트: noryb009/lick
char *install_to_boot_ini(char *boot, lickdir_t *lick) {
    char *start, *end;
    if(!find_section(boot, "[operating systems]", &start, &end)) {
        if(!lick->err)
            lick->err = strdup2("Invalid boot.ini");
        return NULL;
    }

    char *after = after_last_entry(start, end, "=");
    const char *pupldr = "C:\\pupldr";

    // print start of file, newline,
    //   C:\pupldr="Start Puppy Linux", rest of file
    char *ret = concat_strs(6,
            boot,
            "\n", pupldr, BOOT_ITEM, "\n",
            after);

    return check_timeout(ret, "timeout", "=");
}
예제 #23
0
int Widget_SetAttribute(LCUI_Widget w, const char *name, const char *value)
{
	char *value_str;
	if (strcmp(name, "disabled") == 0) {
		if (!value || strcmp(value, "false") != 0) {
			Widget_SetDisabled(w, TRUE);
		} else {
			Widget_SetDisabled(w, FALSE);
		}
		return 0;
	}
	if (!value) {
		return Widget_SetAttributeEx(w, name, NULL, LCUI_STYPE_NONE,
					     NULL);
	}
	value_str = strdup2(value);
	if (!value_str) {
		return -ENOMEM;
	}
	return Widget_SetAttributeEx(w, name, value_str, LCUI_STYPE_STRING,
				     free);
}
예제 #24
0
파일: sequenceData.c 프로젝트: 713/project
/* reverse and complement a sequence */
Sequence *revcomp(Sequence *seq){
  Int64 i,j,n;
  char c;
  Sequence *newSeq;
  newSeq = (Sequence *)emalloc(sizeof(Sequence));

/*   n = strlen(seq->seq); */
  n = seq->len;
  newSeq->seq = (char *) emalloc((size_t)(n+1)*sizeof(char));

  newSeq->id = strdup2(seq->id);
  j=0;
  for(i = n-1; i >= 0; i--){
    c = seq->seq[i];
    switch(c){
      case BORDER:
					newSeq->seq[j++] = BORDER;
				break;
      case 'A':
				newSeq->seq[j++] = 'T';
				break;
      case 'C':
				newSeq->seq[j++] = 'G';
				break;
      case 'G':
				newSeq->seq[j++] = 'C';
				break;
      case 'T':
				newSeq->seq[j++] = 'A';
				break;
      default:
				newSeq->seq[j++] = c;
				break;
    }
  } // end for
  newSeq->seq[n]='\0';
  return newSeq; 
}
예제 #25
0
파일: request.c 프로젝트: jes/serve
/* Extracts the filename from the request.
   new array. You must free the new array when you are done with it. */
char *requ_file(const char *buf) {
  char *ptr, *end;
  char *reqfile;

  /* eg. "GET /filename HTTP/1.1" */

  /* skip whitespace at start */
  for(ptr = (char*)buf; *ptr && iswhite(*ptr); ptr++);

  /* now find the end of the method */
  for(; *ptr && !iswhite(*ptr); ptr++);

  /* now skip more whitespace */
  for(; *ptr && iswhite(*ptr); ptr++);

  /* and find the end of the filename */
  for(end = ptr; *end && !iswhite(*end); end++);/* find space */

  /* allocate the path */
  reqfile = strdup2(ptr, end - ptr);

  return reqfile;
}
예제 #26
0
파일: string.c 프로젝트: lc-soft/LCUI
static int strsaddone(char ***strlist, const char *str)
{
	int i = 0;
	char **newlist;

	if (!*strlist) {
		newlist = (char **)malloc(sizeof(char *) * 2);
		goto check_done;
	}
	for (i = 0; (*strlist)[i]; ++i) {
		if (strcmp((*strlist)[i], str) == 0) {
			return 0;
		}
	}
	newlist = (char **)realloc(*strlist, (i + 2) * sizeof(char *));
check_done:
	if (!newlist) {
		return 0;
	}
	newlist[i] = strdup2(str);
	newlist[i + 1] = NULL;
	*strlist = newlist;
	return 1;
}
예제 #27
0
파일: job.c 프로젝트: colmsjo/batches
void
setup_user_and_env(struct cl_t *cl, struct passwd *pas,
                   char ***sendmailenv, char ***jobenv, char **curshell,
                   char **curhome, char **content_type, char **encoding)
/* Check PAM authorization, and setup the environment variables
 * to run sendmail and to run the job itself. Change dir to HOME and check if SHELL is ok */
/* (*curshell) and (*curhome) will be allocated and should thus be freed
 * if curshell and curhome are not NULL. */
/* Return the the two env var sets, the shell to use to execle() commands and the home dir */
{
    env_list_t *env_list = env_list_init();
    env_t *e = NULL;
    char *path = NULL;
    char *myshell = NULL;
#ifdef HAVE_LIBPAM
    int retcode = 0;
    char **env;
#endif

    if (pas == NULL)
        die("setup_user_and_env() called with a NULL struct passwd");

    env_list_setenv(env_list, "USER", pas->pw_name, 1);
    env_list_setenv(env_list, "LOGNAME", pas->pw_name, 1);
    env_list_setenv(env_list, "HOME", pas->pw_dir, 1);
    /* inherit fcron's PATH for sendmail. We will later change it to DEFAULT_JOB_PATH
     * or a user defined PATH for the job itself */
    path = getenv("PATH");
    env_list_setenv(env_list, "PATH", (path != NULL) ? path : DEFAULT_JOB_PATH,
                    1);

    if (cl->cl_tz != NULL)
        env_list_setenv(env_list, "TZ", cl->cl_tz, 1);
    /* To ensure compatibility with Vixie cron, we don't use the shell defined
     * in /etc/passwd by default, but the default value from fcron.conf instead: */
    if (shell != NULL && shell[0] != '\0')
        /* default: use value from fcron.conf */
        env_list_setenv(env_list, "SHELL", shell, 1);
    else
        /* shell is empty, ie. not defined: fail back to /etc/passwd's value */
        env_list_setenv(env_list, "SHELL", pas->pw_shell, 1);

#if ( ! defined(RUN_NON_PRIVILEGED)) && defined(HAVE_LIBPAM)
    /* Open PAM session for the user and obtain any security
     * credentials we might need */

    retcode = pam_start("fcron", pas->pw_name, &apamconv, &pamh);
    if (retcode != PAM_SUCCESS)
        die_pame(pamh, retcode, "Could not start PAM for '%s'", cl->cl_shell);
    /* Some system seem to need that pam_authenticate() call.
     * Anyway, we have no way to authentificate the user :
     * we must set auth to pam_permit. */
    retcode = pam_authenticate(pamh, PAM_SILENT);
    if (retcode != PAM_SUCCESS)
        die_mail_pame(cl, retcode, pas,
                      "Could not authenticate PAM user", env_list);
    retcode = pam_acct_mgmt(pamh, PAM_SILENT);  /* permitted access? */
    if (retcode != PAM_SUCCESS)
        die_mail_pame(cl, retcode, pas,
                      "Could not init PAM account management", env_list);
    retcode = pam_setcred(pamh, PAM_ESTABLISH_CRED | PAM_SILENT);
    if (retcode != PAM_SUCCESS)
        die_mail_pame(cl, retcode, pas, "Could not set PAM credentials",
                      env_list);
    retcode = pam_open_session(pamh, PAM_SILENT);
    if (retcode != PAM_SUCCESS)
        die_mail_pame(cl, retcode, pas, "Could not open PAM session", env_list);

    for (env = pam_getenvlist(pamh); env && *env; env++) {
        env_list_putenv(env_list, *env, 1);
    }

    /* Close the log here, because PAM calls openlog(3) and
     * our log messages could go to the wrong facility */
    xcloselog();
#endif                          /* ( ! defined(RUN_NON_PRIVILEGED)) && defined(HAVE_LIBPAM) */

    /* export the environment for sendmail before we apply user customization */
    if (sendmailenv != NULL)
        *sendmailenv = env_list_export_envp(env_list);

    /* Now add user customizations to the environment to form jobenv */

    if (jobenv != NULL) {

        /* Make sure we don't keep fcron daemon's PATH (which we used for sendmail) */
        env_list_setenv(env_list, "PATH", DEFAULT_JOB_PATH, 1);

        for (e = env_list_first(cl->cl_file->cf_env_list); e != NULL;
             e = env_list_next(cl->cl_file->cf_env_list)) {
            env_list_putenv(env_list, e->e_envvar, 1);
        }

        /* make sure HOME is defined */
        env_list_putenv(env_list, "HOME=/", 0); /* don't overwrite if already defined */
        if (curhome != NULL) {
            (*curhome) = strdup2(env_list_getenv(env_list, "HOME"));
        }

        /* check that SHELL is valid */
        myshell = env_list_getenv(env_list, "SHELL");
        if (myshell == NULL || myshell[0] == '\0') {
            myshell = shell;
        }
        else if (access(myshell, X_OK) != 0) {
            if (errno == ENOENT)
                error("shell \"%s\" : no file or directory. SHELL set to %s",
                      myshell, shell);
            else
                error_e("shell \"%s\" not valid : SHELL set to %s", myshell,
                        shell);

            myshell = shell;
        }
        env_list_setenv(env_list, "SHELL", myshell, 1);
        if (curshell != NULL)
            *curshell = strdup2(myshell);

        *jobenv = env_list_export_envp(env_list);

    }

    if (content_type != NULL) {
        (*content_type) = strdup2(env_list_getenv(env_list, "CONTENT_TYPE"));
    }
    if (encoding != NULL) {
        (*encoding) =
            strdup2(env_list_getenv(env_list, "CONTENT_TRANSFER_ENCODING"));
    }

    env_list_destroy(env_list);

}
예제 #28
0
파일: socket.c 프로젝트: yangyan/RV_XJTU_CS
void
auth_client(struct fcrondyn_cl *client)
    /* check client identity */
{
    char *pass_cry = NULL;
    char *pass_sys = NULL;
    char *pass_str = NULL;

#ifdef HAVE_LIBSHADOW
    struct spwd *pass_sp = NULL;
    if ( (pass_sp = getspnam((char *) client->fcl_cmd )) == NULL ) {
	error_e("could not getspnam %s", (char *) client->fcl_cmd);
	send(client->fcl_sock_fd, "0", sizeof("0"), 0);
	return;
    }
    pass_sys = pass_sp->sp_pwdp;
#else
    struct passwd *pass = NULL;
    if ( (pass = getpwnam((char *) client->fcl_cmd )) == NULL ) {
	error_e("could not getpwnam %s", (char *) client->fcl_cmd);
	send(client->fcl_sock_fd, "0", sizeof("0"), 0);
	return;
    }
    pass_sys = pass->pw_passwd;
#endif

    /* */
    debug("auth_client() : socket : %d", client->fcl_sock_fd);
    /* */

    /* we need to limit auth failures : otherwise fcron may be used to "read"
     * shadow password !!! (or to crack it using a test-all-possible-password attack) */
    if (auth_fail > 0 && auth_nofail_since + AUTH_WAIT <= now )
	/* no auth time exceeded : set counter to 0 */
	auth_fail = 0;
    if (auth_fail >= MAX_AUTH_FAIL) {
	error("Too many authentication failures : try to connect later.");
	send(client->fcl_sock_fd, "0", sizeof("0"), 0);	    
	auth_fail = auth_nofail_since = 0;
	return;    
    }

    /* password is stored after user name */
    pass_str = &( (char *)client->fcl_cmd ) [ strlen( (char*)client->fcl_cmd ) + 1 ];
    if ( (pass_cry = crypt(pass_str, pass_sys)) == NULL ) {
	error_e("could not crypt()");
	send(client->fcl_sock_fd, "0", sizeof("0"), 0);
	return;
    }

/*      debug("pass_sp->sp_pwdp : %s", pass_sp->sp_pwdp); */
/*      debug("pass_cry : %s", pass_cry); */
    if (strcmp(pass_cry, pass_sys) == 0) {
	client->fcl_user = strdup2( (char *) client->fcl_cmd );
	send(client->fcl_sock_fd, "1", sizeof("1"), 0);
    }
    else {
	auth_fail++;
	auth_nofail_since = now;
	error("Invalid passwd for %s from socket %d",
	      (char *) client->fcl_cmd, client->fcl_sock_fd);
	send(client->fcl_sock_fd, "0", sizeof("0"), 0);
    }
}
예제 #29
0
파일: arguments.c 프로젝트: noryb009/lick
program_args_t *handle_args(program_status_t *p, int argc, char **argv) {
    program_args_t *a = malloc(sizeof(program_args_t));
    a->check_program = 0;
    a->try_uac = 1;
    a->ignore_errors = 0;
    a->me_check = 1;
    a->check_loader = 0;
    a->install_loader = -1;
    a->fix_loader = 0;
    a->check_fix_loader = 0;
    a->install = NULL;
    a->uninstall = NULL;
    a->uninstall_all = 0;
    a->reinstall = 0;

    struct option ops[] = {
        // meta
        {"help", no_argument, 0, 'h'},
        {"version", no_argument, 0, 'v'},
        {"check-program", no_argument, &a->check_program, 1},
        {"no-try-uac", no_argument, &a->try_uac, 0},
        {"ignore-errors", no_argument, &a->ignore_errors, 1},
        {"no-me-check", no_argument, &a->me_check, 0},
        // volume
        {"verbose", no_argument, 0, 'V'},
        {"no-menu", no_argument, 0, 'm'},
        {"no-questions", no_argument, 0, 'Q'},
        {"silent", no_argument, 0, 's'},
        // install/uninstall
        {"check-loader", no_argument, 0, 'c'},
        {"install-loader", no_argument, &a->install_loader, 1},
        {"uninstall-loader", no_argument, &a->install_loader, 0},
        {"fix-loader", no_argument, &a->fix_loader, 1},
        {"check-fix-loader", no_argument, &a->check_fix_loader, 1},
        {"install", required_argument, 0, 'i'},
        {"uninstall", required_argument, 0, 'u'},
        {"uninstall-all", no_argument, &a->uninstall_all, 1},
        {"reinstall", no_argument, &a->reinstall, 1},
        {0, 0, 0, 0}
    };
    int c;
    while((c = getopt_long(argc, argv, "chi:msu:v", ops, NULL)) != -1) {
        switch(c) {
        case 0: // set flag
            break;
        case 'm':
            p->volume = VOLUME_NO_MENU;
            break;
        case 'Q':
            p->volume = VOLUME_NO_QUESTIONS;
            break;
        case 's':
            p->volume = VOLUME_SILENCE;
            break;
        case 'i':
            if(strcmp(optarg, "--") == 0) {
                for(int i = optind; i < argc; ++i)
                    a->install = new_string_node_t(strdup2(argv[i]), a->install);
                optind = argc;
            } else
                a->install = new_string_node_t(strdup2(optarg), a->install);
            break;
        case 'u':
            if(strcmp(optarg, "--") == 0) {
                for(int i = optind; i < argc; ++i)
                    a->uninstall = new_string_node_t(strdup2(argv[i]), a->uninstall);
                optind = argc;
            } else
                a->uninstall = new_string_node_t(strdup2(optarg), a->uninstall);
            break;
        case 'c':
            a->check_loader = 1;
            break;
        case 'v':
            printf("%s\n", LIBLICK_VERSION);
            free_program_status(p);
            free_program_args(a);
            exit(0);
        case 'h':
        case '?':
        default:
            print_help();
            free_program_status(p);
            free_program_args(a);
            if(c == 'h')
                exit(0);
            else
                exit(1);
        }
    }
    a->install = string_node_t_reverse(a->install);
    a->uninstall = string_node_t_reverse(a->uninstall);
    return a;
}
예제 #30
0
파일: request.c 프로젝트: jes/serve
/* Takes the given requ_file()-returned name, sorts out user directories, url
   decodes it, and places it in a new array. You must free the new array when
   you are done with it.
   Returns NULL if the filename given can not be url decoded. */
char *filename(const char *buf) {
  char *ptr, *end;
  char *p, *s;
  char *path, *newpath;
  struct passwd *pw;
  char *user = NULL;
  int len, userdir = 0;

  /* no path given, get root */
  if(*buf == '\0') return strdup(".");

  /* get just the file part */
  ptr = (char*)buf;
  while(iswhite(*ptr)) ptr++;
	
  /* get a url decoded copy */
  if((end = strchr(ptr, '?'))) path = strdup2(ptr, end - ptr);
  else path = strdup(ptr);
  if(url_decode(path) == NULL) {
    free(path);
    return NULL;
  }
  ptr = path;

  /* sort out leading slashes */
  while(*ptr == '/') ptr++;

  /* sort out double slashes */
  for(p = ptr, s = ptr; *s; s++) {
    if(*s != '/') *p++ = *s;
    else if(*(s+1) != '/') *p++ = *s;
  }
  *p = '\0';
  len = strlen(ptr);

  /* sort out trailing /. */
  if(len >= 2)
    if((ptr[len - 1] == '.') && (ptr[len - 2] == '/')) len--;

  /* sort out trailing slashes */
  while((ptr[len - 1] == '/') && (len > 0)) len--;

  /* NUL-terminate */
  ptr[len] = '\0';

  /* sort out empty path */
  if(len == 0) {
    free(path);
    ptr = path = strdup(".");
  }

  /* and now get user directories */
  /* Valgrind complains about using getpwnam() because it allocates a buffer
     that never gets freed. This isn't a problem because it is reused on
     subsequent calls to getpwnam(). */
  if(*ptr == '~') {
    if((end = strchr(ptr, '/'))) {/* user directory at start of path */
      user = strdup2(ptr + 1, end - (ptr + 1));
      pw = getpwnam(user);
    } else {/* index */
      end = ptr + len;
      pw = getpwnam(ptr + 1);
    }
    if(pw) {/* user exists, construct path */
      userdir = 1;
      len = strlen(pw->pw_dir);
      newpath = malloc(len + /* strlen("/public_html") */ 12 +
                       strlen(end) + 1);
      strcpy(newpath, pw->pw_dir);
      if(newpath[len - 1] != '/') newpath[len++] = '/';
      strcpy(newpath + len, "public_html");
      strcpy(newpath + len + /* strlen("public_html") */ 11, end);
      free(path);
      free(user);
    }
  }

  /* sort out the path if it's not a userdir */
  if(!userdir) {
    newpath = strdup(ptr);
    free(path);
  }

  return newpath;
}