Ejemplo n.º 1
0
static int cpool_addtcp(char *addr, char *port) {
    struct addrinfo hints, *res, *res2;
    struct CP_ENTRY *cpe = (struct CP_ENTRY *)&cp->pool[cp->entries-1];

    memset(&hints, 0, sizeof(hints));
    hints.ai_family = AF_UNSPEC;
    hints.ai_socktype = SOCK_STREAM;

    if(getaddrinfo(addr, port ? port : "3310", &hints, &res)) {
	logg("^Can't resolve hostname %s\n", addr ? addr : "");
	return 1;
    }
    cpe->type = 1;
    cpe->dead = 1;

    memset(&hints, 0, sizeof(hints));
    hints.ai_flags = AI_PASSIVE;
    hints.ai_socktype = SOCK_STREAM;
    hints.ai_family = AF_UNSPEC;
    if(!getaddrinfo(addr, NULL, &hints, &res2)) {
	cpe->local = islocal(res2->ai_addr, res2->ai_addrlen);
	freeaddrinfo(res2);
    } else cpe->local = 0;
    cpe->last_poll = 0;
    cpe->server = res->ai_addr;
    cpe->socklen = res->ai_addrlen;
    SETGAI(cpe, res);
    logg("*%s socket tcp:%s:%s added to the pool (slot %d)\n", cpe->local ? "Local" : "Remote", addr ? addr : "localhost", port ? port : "3310", cp->entries);
    return 0;
}
Ejemplo n.º 2
0
Archivo: labels.c Proyecto: 1tgr/mobius
void declare_as_global (char *label, char *special, efunc error) 
{
    union label *lptr;

    if (islocal(label)) {
	error(ERR_NONFATAL, "attempt to declare local symbol `%s' as"
	      " global", label);
	return;
    }
    lptr = find_label (label, 1);
    switch (lptr->defn.is_global & TYPE_MASK) {
      case NOT_DEFINED_YET:
	lptr->defn.is_global = GLOBAL_PLACEHOLDER;
	lptr->defn.special = special ? perm_copy(special, "") : NULL;
	break;
      case GLOBAL_PLACEHOLDER:	       /* already done: silently ignore */
      case GLOBAL_SYMBOL:
	break;
      case LOCAL_SYMBOL:
	if (!lptr->defn.is_global & EXTERN_BIT)
	    error(ERR_NONFATAL, "symbol `%s': GLOBAL directive must"
		  " appear before symbol definition", label);
	break;
    }
}
Ejemplo n.º 3
0
void declare_as_global(char *label, char *special)
{
    union label *lptr;

    if (islocal(label)) {
        nasm_error(ERR_NONFATAL, "attempt to declare local symbol `%s' as"
                   " global", label);
        return;
    }
    lptr = find_label(label, 1);
    if (!lptr)
        return;
    switch (lptr->defn.is_global & TYPE_MASK) {
    case NOT_DEFINED_YET:
        lptr->defn.is_global = GLOBAL_PLACEHOLDER;
        lptr->defn.special = special ? perm_copy(special) : NULL;
        break;
    case GLOBAL_PLACEHOLDER:   /* already done: silently ignore */
    case GLOBAL_SYMBOL:
        break;
    case LOCAL_SYMBOL:
        if (!(lptr->defn.is_global & EXTERN_BIT)) {
            nasm_error(ERR_WARNING, "symbol `%s': GLOBAL directive "
                       "after symbol definition is an experimental feature", label);
            lptr->defn.is_global = GLOBAL_SYMBOL;
        }
        break;
    }
}
Ejemplo n.º 4
0
Archivo: labels.c Proyecto: 1tgr/mobius
void redefine_label (char *label, long segment, long offset, char *special,
		   int is_norm, int isextrn, struct ofmt *ofmt, efunc error) 
{
    union label *lptr;

    /* This routine possibly ought to check for phase errors.  Most assemblers
     * check for phase errors at this point.  I don't know whether phase errors
     * are even possible, nor whether they are checked somewhere else
     */

    (void) segment;  /* Don't warn that this parameter is unused */
    (void) offset;   /* Don't warn that this parameter is unused */
    (void) special;  /* Don't warn that this parameter is unused */
    (void) is_norm;  /* Don't warn that this parameter is unused */
    (void) isextrn;  /* Don't warn that this parameter is unused */
    (void) ofmt;     /* Don't warn that this parameter is unused */

#ifdef DEBUG
    if (!strncmp(label, "debugdump", 9))
	fprintf(stderr, "debug: redefine_label (%s, %ld, %08lx, %s, %d, %d)\n",
		label, segment, offset, special, is_norm, isextrn);
#endif

    if (!islocal(label)) {
	lptr = find_label (label, 1);
	if (!lptr)
	    error (ERR_PANIC, "can't find label `%s' on pass two", label);
	if (*label != '.' && lptr->defn.is_norm)
	    prevlabel = lptr->defn.label;
    }
}
Ejemplo n.º 5
0
void define_label_stub (char *label, efunc error) {
    union label *lptr;

    if (!islocal(label)) {
	lptr = find_label (label, 1);
	if (!lptr)
	    error (ERR_PANIC, "can't find label `%s' on pass two", label);
	if (*label != '.')
	    prevlabel = lptr->defn.label;
    }
}
Ejemplo n.º 6
0
/*
 * Internal routine: finds the `union label' corresponding to the
 * given label name. Creates a new one, if it isn't found, and if
 * `create' is TRUE.
 */
static union label *find_label(char *label, int create)
{
    int hash = 0;
    char *p, *prev;
    int prevlen;
    union label *lptr;

    if (islocal(label))
        prev = prevlabel;
    else
        prev = "";
    prevlen = strlen(prev);
    p = prev;
    while (*p)
        hash += *p++;
    p = label;
    while (*p)
        hash += *p++;
    hash %= LABEL_HASHES;
    lptr = ltab[hash];
    while (lptr->admin.movingon != END_LIST) {
        if (lptr->admin.movingon == END_BLOCK) {
            lptr = lptr->admin.next;
            if (!lptr)
                break;
        }
        if (!strncmp(lptr->defn.label, prev, prevlen) &&
            !strcmp(lptr->defn.label + prevlen, label))
            return lptr;
        lptr++;
    }
    if (create) {
        if (lfree[hash]->admin.movingon == END_BLOCK) {
            /*
             * must allocate a new block
             */
            lfree[hash]->admin.next =
                (union label *)nasm_malloc(LBLK_SIZE);
            lfree[hash] = lfree[hash]->admin.next;
            init_block(lfree[hash]);
        }

        lfree[hash]->admin.movingon = BOGUS_VALUE;
        lfree[hash]->defn.label = perm_copy(prev, label);
        lfree[hash]->defn.special = NULL;
        lfree[hash]->defn.is_global = NOT_DEFINED_YET;
        return lfree[hash]++;
    } else
        return NULL;
}
Ejemplo n.º 7
0
/*
 * Internal routine: finds the `union label' corresponding to the
 * given label name. Creates a new one, if it isn't found, and if
 * `create' is true.
 */
static union label *find_label(char *label, int create)
{
    char *prev;
    int prevlen, len;
    union label *lptr, **lpp;
    char label_str[IDLEN_MAX];
    struct hash_insert ip;

    if (islocal(label)) {
        prev = prevlabel;
        prevlen = strlen(prev);
        len = strlen(label);
        if (prevlen + len >= IDLEN_MAX) {
            nasm_error(ERR_NONFATAL, "identifier length exceed %i bytes",
                       IDLEN_MAX);
            return NULL;
        }
        memcpy(label_str, prev, prevlen);
        memcpy(label_str+prevlen, label, len+1);
        label = label_str;
    } else {
        prev = "";
        prevlen = 0;
    }

    lpp = (union label **) hash_find(&ltab, label, &ip);
    lptr = lpp ? *lpp : NULL;

    if (lptr || !create)
        return lptr;

    /* Create a new label... */
    if (lfree->admin.movingon == END_BLOCK) {
        /*
         * must allocate a new block
         */
        lfree->admin.next = (union label *)nasm_malloc(LBLK_SIZE);
        lfree = lfree->admin.next;
        init_block(lfree);
    }

    lfree->admin.movingon = BOGUS_VALUE;
    lfree->defn.label = perm_copy(label);
    lfree->defn.special = NULL;
    lfree->defn.is_global = NOT_DEFINED_YET;

    hash_add(&ip, lfree->defn.label, lfree);
    return lfree++;
}
Ejemplo n.º 8
0
/*
 * Internal routine: finds the `union label' corresponding to the
 * given label name. Creates a new one, if it isn't found, and if
 * `create' is true.
 */
static union label *find_label(const char *label, bool create, bool *created)
{
    union label *lptr, **lpp;
    char *label_str = NULL;
    struct hash_insert ip;

    nasm_assert(label != NULL);

    if (islocal(label))
        label = label_str = nasm_strcat(prevlabel, label);

    lpp = (union label **) hash_find(&ltab, label, &ip);
    lptr = lpp ? *lpp : NULL;

    if (lptr || !create) {
        if (created)
            *created = false;
        return lptr;
    }

    /* Create a new label... */
    if (lfree->admin.movingon == END_BLOCK) {
        /*
         * must allocate a new block
         */
        lfree->admin.next = nasm_malloc(LBLK_SIZE);
        lfree = lfree->admin.next;
        init_block(lfree);
    }

    if (created)
        *created = true;

    nasm_zero(*lfree);
    lfree->defn.label     = perm_copy(label);
    lfree->defn.subsection = NO_SEG;
    if (label_str)
        nasm_free(label_str);

    hash_add(&ip, lfree->defn.label, lfree);
    return lfree++;
}
Ejemplo n.º 9
0
struct hostent *
mdns_gethostbyname2 (
	const char *name,
	int af
)
{
	hostent *result_buf;
	char buf[1024];
	size_t buflen=1024;
	int errnop;
	int h_errnop;

	char lookup_name [k_hostname_maxlen + 1];
	result_map_t result;
	int err_status;

	if(!islocal(name))
#ifdef _WINDOWS
		return (gethostbyname(name));
#else
		return (gethostbyname2(name, af));
#endif

	result_buf=malloc(sizeof(hostent));

	// Initialize Zeroconf - does run time linking of dns-sd functions
	// if it fails, return null
	if(InitializeZeroconf())
		return NULL;

	// Initialise result
	err_status = init_result (&result, result_buf, buf, buflen);
	if (err_status)
	{
		errnop = err_status;
		h_errnop = NETDB_INTERNAL;
		return NULL;
	}
		
	if (is_applicable_name (&result, name, lookup_name))
	{
		// Try using mdns
		nss_status rv;

		LOG(PHIDGET_LOG_DEBUG,
			"mdns: Local name: %s",
			name
		);

		rv = mdns_lookup_name (name, af, &result);
		if (rv == NSS_STATUS_SUCCESS)
		{
			return result_buf;
		}
	}

	// Return current error status (defaults to NOT_FOUND)
	
	errnop = result.r_errno;
	h_errnop = result.r_h_errno;

	return NULL;
}
Ejemplo n.º 10
0
const char *local_scope(const char *label)
{
   return islocal(label) ? prevlabel : "";
}
Ejemplo n.º 11
0
void define_label(char *label, int32_t segment, int64_t offset, char *special,
                  bool is_norm, bool isextrn)
{
    union label *lptr;
    int exi;

#ifdef DEBUG
#if DEBUG<3
    if (!strncmp(label, "debugdump", 9))
#endif
        nasm_error(ERR_DEBUG, "define_label (%s, %"PRIx32", %"PRIx64", %s, %d, %d)",
                   label, segment, offset, special, is_norm, isextrn);
#endif
    lptr = find_label(label, 1);
    if (!lptr)
        return;
    if (lptr->defn.is_global & DEFINED_BIT) {
        nasm_error(ERR_NONFATAL, "symbol `%s' redefined", label);
        return;
    }
    lptr->defn.is_global |= DEFINED_BIT;
    if (isextrn)
        lptr->defn.is_global |= EXTERN_BIT;

    if (!islocalchar(label[0]) && is_norm) {
        /* not local, but not special either */
        prevlabel = lptr->defn.label;
    } else if (islocal(label) && !*prevlabel) {
        nasm_error(ERR_NONFATAL, "attempt to define a local label before any"
                   " non-local labels");
    }

    lptr->defn.segment = segment;
    lptr->defn.offset = offset;
    lptr->defn.is_norm = (!islocalchar(label[0]) && is_norm);

    if (pass0 == 1 || (!is_norm && !isextrn && (segment > 0) && (segment & 1))) {
        exi = !!(lptr->defn.is_global & GLOBAL_BIT);
        if (exi) {
            char *xsymbol;
            int slen;
            slen = strlen(lprefix);
            slen += strlen(lptr->defn.label);
            slen += strlen(lpostfix);
            slen++;             /* room for that null char */
            xsymbol = nasm_malloc(slen);
            snprintf(xsymbol, slen, "%s%s%s", lprefix, lptr->defn.label,
                     lpostfix);

            ofmt->symdef(xsymbol, segment, offset, exi,
                         special ? special : lptr->defn.special);
            ofmt->current_dfmt->debug_deflabel(xsymbol, segment, offset, exi,
                                               special ? special : lptr->defn.special);
            /**	nasm_free(xsymbol);  ! outobj.c stores the pointer; ouch!!! **/
        } else {
            if ((lptr->defn.is_global & (GLOBAL_BIT | EXTERN_BIT)) != EXTERN_BIT) {
                ofmt->symdef(lptr->defn.label, segment, offset, exi,
                             special ? special : lptr->defn.special);
                ofmt->current_dfmt->debug_deflabel(label, segment, offset, exi,
                                                   special ? special : lptr->defn.special);
            }
        }
    }   /* if (pass0 == 1) */
}
Ejemplo n.º 12
0
void redefine_label(char *label, int32_t segment, int64_t offset, char *special,
                    bool is_norm, bool isextrn)
{
    union label *lptr;
    int exi;

    /* This routine possibly ought to check for phase errors.  Most assemblers
     * check for phase errors at this point.  I don't know whether phase errors
     * are even possible, nor whether they are checked somewhere else
     */

    (void)special;              /* Don't warn that this parameter is unused */
    (void)is_norm;              /* Don't warn that this parameter is unused */
    (void)isextrn;              /* Don't warn that this parameter is unused */

#ifdef DEBUG
#if DEBUG < 3
    if (!strncmp(label, "debugdump", 9))
#endif
        nasm_error(ERR_DEBUG, "redefine_label (%s, %"PRIx32", %"PRIx64", %s, %d, %d)",
                   label, segment, offset, special, is_norm, isextrn);
#endif

    lptr = find_label(label, 1);
    if (!lptr)
        nasm_error(ERR_PANIC, "can't find label `%s' on pass two", label);

    if (!islocal(label)) {
        if (!islocalchar(*label) && lptr->defn.is_norm)
            prevlabel = lptr->defn.label;
    }

    if (lptr->defn.offset != offset)
        global_offset_changed++;

    lptr->defn.offset = offset;
    lptr->defn.segment = segment;

    if (pass0 == 1) {
        exi = !!(lptr->defn.is_global & GLOBAL_BIT);
        if (exi) {
            char *xsymbol;
            int slen;
            slen = strlen(lprefix);
            slen += strlen(lptr->defn.label);
            slen += strlen(lpostfix);
            slen++;             /* room for that null char */
            xsymbol = nasm_malloc(slen);
            snprintf(xsymbol, slen, "%s%s%s", lprefix, lptr->defn.label,
                     lpostfix);

            ofmt->symdef(xsymbol, segment, offset, exi,
                         special ? special : lptr->defn.special);
            ofmt->current_dfmt->debug_deflabel(xsymbol, segment, offset, exi,
                                               special ? special : lptr->defn.special);
            /**	nasm_free(xsymbol);  ! outobj.c stores the pointer; ouch!!! **/
        } else {
            if ((lptr->defn.is_global & (GLOBAL_BIT | EXTERN_BIT)) != EXTERN_BIT) {
                ofmt->symdef(lptr->defn.label, segment, offset, exi,
                             special ? special : lptr->defn.special);
                ofmt->current_dfmt->debug_deflabel(label, segment, offset, exi,
                                                   special ? special : lptr->defn.special);
            }
        }
    }   /* if (pass0 == 1) */
}
Ejemplo n.º 13
0
int
send_mbox(char *mbox, int letnum)
{
	char file[PATH_MAX];
	char biffmsg[PATH_MAX];
	int mbfd;
	FILE *malf;
	int rc;
	uid_t useruid, saved_uid;
	void (*istat)(), (*qstat)(), (*hstat)();

	if (!islocal(mbox, &useruid))
		return (1);
	(void) strlcpy(file, maildir, sizeof (file));
	if (strlcat(file, mbox, sizeof (file)) >= sizeof (file)) {
		rc = FALSE;
		goto done;
	}

	/*
	 * We need to setgid and seteuid here since the users's mail box
	 * might be NFS mounted and since root can't write across NFS.
	 * Note this won't work with Secure NFS/RPC's.  Since delivering to
	 * NFS mounted directories isn't really supported that's OK for now.
	 */
	setgid(mailgrp);
	saved_uid = geteuid();
	seteuid(useruid);
	lock(mbox);

	/* ignore signals */
	istat = signal(SIGINT, SIG_IGN);
	qstat = signal(SIGQUIT, SIG_IGN);
	hstat = signal(SIGHUP, SIG_IGN);
	/* now access mail box */
	mbfd = accessmf(file);
	if (mbfd == -1) {	/* mail box access failed, bail out */
		unlock();
		rc = FALSE;
		sav_errno = EACCES;
		goto done;
	} else {
				/* mail box is ok, now do append */
		if ((malf = fdopen(mbfd, "a")) != NULL) {
			(void) snprintf(biffmsg, sizeof (biffmsg),
			    "%s@%d\n", mbox, ftell(malf));
			rc = copylet(letnum, malf, ORDINARY);
			fclose(malf);
		}
	}

	if (rc == FALSE)
		fprintf(stderr, "%s: Cannot append to %s\n", program, file);
	else
		notifybiff(biffmsg);

done:
	/* restore signal */
	(void) signal(SIGINT, istat);
	(void) signal(SIGQUIT, qstat);
	(void) signal(SIGHUP, hstat);
	unlock();
	seteuid(saved_uid);
	return (rc);
}