Пример #1
0
int router_find_policy_byname(void **msg_policy,char * name,int rjump,int ljump)
{
    DISPATCH_POLICY * policy;
    int ret;
		
    *msg_policy=NULL;
    ret=dispatch_policy_getfirst(&policy);
    if(ret<0)
        return ret;
    while(policy!=NULL)
    {
	ret=Strncmp(name,policy->name,DIGEST_SIZE);
	if(ret==0)
	{
		if((policy->rjump==0) || (policy->rjump==rjump))
		{
			if((policy->ljump==0) || (policy->ljump==ljump))
			{
				*msg_policy=policy;		
				break;
			}
		}
	}
    	ret=dispatch_policy_getnext(&policy);
    }
    
    // find policy in router policy list;
    if(policy!=NULL)
	return ret;

    // if can't find policy in router policy list, look up it in aspect policy list	
    ret=dispatch_aspect_policy_getfirst(&policy);
    if(ret<0)
        return ret;
    while(policy!=NULL)
    {
	ret=Strncmp(name,policy->newname,DIGEST_SIZE);
	if(ret==0)
	{
		if((policy->rjump==0) || (policy->rjump==rjump))
		{
			if((policy->ljump==0) || (policy->ljump==ljump))
			{
				*msg_policy=policy;		
				break;
			}
		}
	}
    	ret=dispatch_aspect_policy_getnext(&policy);
    }

    return ret;
}
Пример #2
0
int main()
{
	char p1[10]="12345abcd";
	char q1[10]="12345efgh";
	char p2[11]="12345\0abcd";
	char q2[11]="12345\0efgh";
	printf("%d\n",Strncmp(p1,q1,5));
	printf("%d\n",Strncmp(p1,q1,9));
	printf("%d\n",Strncmp(q1,p1,9));
	printf("%d\n",Strncmp(p2,q2,9));
	
	return 0;
}
Пример #3
0
static int MakeLiteral(Char *str, int len, Char addlit)
{
    int i, addlitlen = 0;
    Char *addlitptr = 0;
    if (addlit) {
	if ((addlit & LITERAL) != 0) {
	    addlitptr = litptr + (addlit & ~LITERAL) * LIT_FACTOR;
	    addlitlen = Strlen(addlitptr);
	} else {
	    addlitptr = &addlit;
	    addlitlen = 1;
	}
	for (i = 0; i < litlen; i += LIT_FACTOR)
	    if (!Strncmp(addlitptr, litptr + i, addlitlen) && !Strncmp(str, litptr + i + addlitlen, len) && litptr[i + addlitlen + len] == 0)
		return (i / LIT_FACTOR) | LITERAL;
    } else {
	addlitlen = 0;
	for (i = 0; i < litlen; i += LIT_FACTOR)
	    if (!Strncmp(str, litptr + i, len) && litptr[i + len] == 0)
		return (i / LIT_FACTOR) | LITERAL;
    }
    if (litlen + addlitlen + len + 1 + (LIT_FACTOR - 1) > litalloc) {
	Char *newlitptr;
	int add = 256;
	while (len + addlitlen + 1 + (LIT_FACTOR - 1) > add)
	    add *= 2;
	newlitptr = xrealloc(litptr, (litalloc + add) * sizeof(Char));
	if (!newlitptr)
	    return '?';
	litptr = newlitptr;
	litalloc += add;
	if (addlitptr && addlitptr != &addlit)
	    addlitptr = litptr + (addlit & ~LITERAL) * LIT_FACTOR;
    }
    i = litlen / LIT_FACTOR;
    if (i >= LITERAL || i == CHAR_DBWIDTH)
	return '?';
    if (addlitptr) {
	Strncpy(litptr + litlen, addlitptr, addlitlen);
	litlen += addlitlen;
    }
    Strncpy(litptr + litlen, str, len);
    litlen += len;
    do
	litptr[litlen++] = 0;
    while (litlen % LIT_FACTOR);
    return i | LITERAL;
}
Пример #4
0
void Swig_restore(Node *n) {
  String *temp;
  int len;
  List *l;
  String *ns;
  Iterator ki;

  ns = Getattr(n, "view");
  assert(ns);

  l = NewList();

  temp = NewStringf("%s:", ns);
  len = Len(temp);

  for (ki = First(n); ki.key; ki = Next(ki)) {
    if (Strncmp(temp, ki.key, len) == 0) {
      Append(l, ki.key);
    }
  }
  for (ki = First(l); ki.item; ki = Next(ki)) {
    DOH *obj = Getattr(n, ki.item);
    Setattr(n, Char(ki.item) + len, obj);
    Delattr(n, ki.item);
  }
  Delete(l);
  Delete(temp);
}
Пример #5
0
void 
Swig_restore(Node *n) {
  char  temp[512];
  int   len;
  List  *l;
  String *ns;
  Iterator ki;

  ns = Getattr(n,"view");
  assert(ns);

  l = NewList();

  strcpy(temp,Char(ns));
  strcat(temp,":");
  len = strlen(temp);

  for (ki = First(n); ki.key; ki = Next(ki)) {
    if (Strncmp(temp,ki.key,len) == 0) {
      Append(l,ki.key);
    }
  }
  for (ki = First(l); ki.item; ki = Next(ki)) {
    DOH *obj = Getattr(n,ki.item);
    Setattr(n,Char(ki.item)+len,obj);
    Delattr(n,ki.item);
  }
  Delete(l);
}
Пример #6
0
int router_find_aspect_policy_byname(void **msg_policy,char * name)
{
    DISPATCH_POLICY * policy;
    int ret;
		
    *msg_policy=NULL;
    ret=dispatch_policy_getfirst(&policy);
    if(ret<0)
        return ret;
    while(policy!=NULL)
    {
		
	if(policy->type==MSG_FLOW_ASPECT)
	{
		ret=Strncmp(name,policy->name,DIGEST_SIZE);
		if(ret==0)
		{
			*msg_policy=policy;		
			break;
		}
    		ret=dispatch_policy_getnext(&policy);
	}	
    }
    return ret;
}
Пример #7
0
String *SwigType_manglestr(const SwigType *s) {
#if 0
  /* Debugging checks to ensure a proper SwigType is passed in and not a stringified type */
  String *angle = Strstr(s, "<");
  if (angle && Strncmp(angle, "<(", 2) != 0)
    Printf(stderr, "SwigType_manglestr error: %s\n", s);
  else if (Strstr(s, "*") || Strstr(s, "&") || Strstr(s, "["))
    Printf(stderr, "SwigType_manglestr error: %s\n", s);
#endif
  return manglestr_default(s);
}
Пример #8
0
int swill_check_ip(const String *ip) {
   String *item;
   int     allow = 1;
  
   /* Look for denied addresses */
   if (ip_deny) {
      for (item = Firstitem(ip_deny); item; item = Nextitem(ip_deny)) {
	 if (Strncmp(item,ip,Len(item)) == 0) {
	    allow = 0;
	 }
      }
   }
   /* Look for allowed addresses */
   if (ip_allow) {
      for (item = Firstitem(ip_allow); item; item = Nextitem(ip_allow)) {
	 if (Strncmp(item,ip,Len(item)) == 0) {
	    return 1;
	 }
      }
   }
   return allow;
}
Пример #9
0
s32 handleFFSOpen(ipcmessage *msg)
{
	char name[MAX_FILENAME_SIZE];
	char *origname = msg->open.device;

	if ((emulationType == FFS_EMU_NONE) ||
		Strncmp(origname, "/dev/",5) == 0) 
	{
		return handleFFSOpen(msg);
	}

	preappend_nand_dev_name(origname, name);
	return FFS_Open(name, IPC_OPEN_RW);
}
Пример #10
0
static EMatch does_parm_match(SwigType *type, SwigType *partial_parm_type, const char *partial_parm_type_base, Symtab *tscope, int *specialization_priority) {
  static const int EXACT_MATCH_PRIORITY = 99999; /* a number bigger than the length of any conceivable type */
  int matches;
  int substitutions;
  EMatch match;
  SwigType *ty = Swig_symbol_typedef_reduce(type, tscope);
  String *base = SwigType_base(ty);
  SwigType *t = Copy(partial_parm_type);
  substitutions = Replaceid(t, partial_parm_type_base, base); /* eg: Replaceid("p.$1", "$1", "int") returns t="p.int" */
  matches = Equal(ty, t);
  *specialization_priority = -1;
  if (substitutions == 1) {
    /* we have a non-explicit specialized parameter (in partial_parm_type) because a substitution for $1, $2... etc has taken place */
    SwigType *tt = Copy(partial_parm_type);
    int len;
    /*
       check for match to partial specialization type, for example, all of the following could match the type in the %template:
       template <typename T> struct XX {};
       template <typename T> struct XX<T &> {};         // r.$1
       template <typename T> struct XX<T const&> {};    // r.q(const).$1
       template <typename T> struct XX<T *const&> {};   // r.q(const).p.$1
       %template(XXX) XX<int *const&>;                  // r.q(const).p.int

       where type="r.q(const).p.int" will match either of tt="r.", tt="r.q(const)" tt="r.q(const).p"
    */
    Replaceid(tt, partial_parm_type_base, ""); /* remove the $1, $2 etc, eg tt="p.$1" => "p." */
    len = Len(tt);
    if (Strncmp(tt, ty, len) == 0) {
      match = PartiallySpecializedMatch;
      *specialization_priority = len;
    } else {
      match = PartiallySpecializedNoMatch;
    }
    Delete(tt);
  } else {
    match = matches ? ExactMatch : ExactNoMatch;
    if (matches)
      *specialization_priority = EXACT_MATCH_PRIORITY; /* exact matches always take precedence */
  }
  /*
  Printf(stdout, "      does_parm_match %2d %5d [%s] [%s]\n", match, *specialization_priority, type, partial_parm_type);
  */
  Delete(t);
  Delete(base);
  Delete(ty);
  return match;
}
Пример #11
0
String *Swig_string_strip(String *s) {
  String *ns;
  if (!Len(s)) {
    ns = NewString(s);
  } else {
    const char *cs = Char(s);
    const char *ce = Strchr(cs, ']');
    if (*cs != '[' || !ce) {
      ns = NewString(s);
    } else {
      String *fmt = NewStringf("%%.%ds", ce-cs-1);
      String *prefix = NewStringf(fmt, cs+1);
      if (0 == Strncmp(ce+1, prefix, Len(prefix))) {
        ns = NewString(ce+1+Len(prefix));
      } else {
        ns = NewString(ce+1);
      }
    }
  }
  return ns;
}
Пример #12
0
static void
printdirs(void)
{
    struct directory *dp;
    Char *hp, *s;
    size_t cur, idx, len;

    hp = value(STRhome);
    if (*hp == '\0')
	hp = NULL;
    dp = dcwd;
    idx = 0;
    cur = 0;
    do {
	if (dp == &dhead)
	    continue;
	if (dirflag & DIR_VERT) {
	    (void)fprintf(cshout, "%zu\t", idx++);
	    cur = 0;
	}
	if (!(dirflag & DIR_LONG) && hp != NULL && !eq(hp, STRslash) &&
	    (len = Strlen(hp), Strncmp(hp, dp->di_name, len) == 0) &&
	    (dp->di_name[len] == '\0' || dp->di_name[len] == '/')) 
	    len = Strlen(s = (dp->di_name + len)) + 2;
	else
	    len = Strlen(s = dp->di_name) + 1;

	cur += len;
	if ((dirflag & DIR_LINE) && cur >= 80 - 1 && len < 80) {
	    (void)fprintf(cshout, "\n");
	    cur = len;
	}
	(void) fprintf(cshout, "%s%s%c", (s != dp->di_name)? "~" : "",
	    vis_str(s), (dirflag & DIR_VERT) ? '\n' : ' ');
    } while ((dp = dp->di_prev) != dcwd);
    if (!(dirflag & DIR_VERT))
	(void)fprintf(cshout, "\n");
}
Пример #13
0
int Swig_storage_isexternc(Node *n) {
  const String *storage = Getattr(n, "storage");
  return storage ? Strcmp(storage, "externc") == 0 || Strncmp(storage, "externc ", 8) == 0 : 0;
}
Пример #14
0
/*
 * dcanon - canonicalize the pathname, removing excess ./ and ../ etc.
 *	we are of course assuming that the file system is standardly
 *	constructed (always have ..'s, directories have links)
 */
Char   *
dcanon(Char *cp, Char *p)
{
    Char *sp;
    Char *p1, *p2;	/* general purpose */
    int    slash;
#ifdef HAVE_SLASHSLASH
    int    slashslash;
#endif /* HAVE_SLASHSLASH */
    size_t  clen;

#ifdef S_IFLNK			/* if we have symlinks */
    Char *mlink, *newcp;
    char *tlink;
    size_t cc;
#endif /* S_IFLNK */

    clen = Strlen(cp);

    /*
     * christos: if the path given does not start with a slash prepend cwd. If
     * cwd does not start with a slash or the result would be too long try to
     * correct it.
     */
    if (!ABSOLUTEP(cp)) {
	Char *tmpdir;
	size_t	len;

	p1 = varval(STRcwd);
	if (p1 == STRNULL || !ABSOLUTEP(p1)) {
	    Char *new_cwd = agetcwd();

	    if (new_cwd == NULL) {
		xprintf("%s: %s\n", progname, strerror(errno));
		setcopy(STRcwd, str2short("/"), VAR_READWRITE|VAR_NOGLOB);
	    }
	    else
		setv(STRcwd, new_cwd, VAR_READWRITE|VAR_NOGLOB);
	    p1 = varval(STRcwd);
	}
	len = Strlen(p1);
	tmpdir = xmalloc((len + clen + 2) * sizeof (*tmpdir));
	(void) Strcpy(tmpdir, p1);
	(void) Strcat(tmpdir, STRslash);
	(void) Strcat(tmpdir, cp);
	xfree(cp);
	cp = p = tmpdir;
    }

#ifdef HAVE_SLASHSLASH
    slashslash = (cp[0] == '/' && cp[1] == '/');
#endif /* HAVE_SLASHSLASH */

    while (*p) {		/* for each component */
	sp = p;			/* save slash address */
	while (*++p == '/')	/* flush extra slashes */
	    continue;
	if (p != ++sp)
	    for (p1 = sp, p2 = p; (*p1++ = *p2++) != '\0';)
		continue;
	p = sp;			/* save start of component */
	slash = 0;
	if (*p) 
	    while (*++p)	/* find next slash or end of path */
		if (*p == '/') {
		    slash = 1;
		    *p = 0;
		    break;
		}

#ifdef HAVE_SLASHSLASH
	if (&cp[1] == sp && sp[0] == '.' && sp[1] == '.' && sp[2] == '\0')
	    slashslash = 1;
#endif /* HAVE_SLASHSLASH */
	if (*sp == '\0') {	/* if component is null */
	    if (--sp == cp)	/* if path is one char (i.e. /) */ 
		break;
	    else
		*sp = '\0';
	}
	else if (sp[0] == '.' && sp[1] == 0) {
	    if (slash) {
		for (p1 = sp, p2 = p + 1; (*p1++ = *p2++) != '\0';)
		    continue;
		p = --sp;
	    }
	    else if (--sp != cp)
		*sp = '\0';
	    else
		sp[1] = '\0';
	}
	else if (sp[0] == '.' && sp[1] == '.' && sp[2] == 0) {
	    /*
	     * We have something like "yyy/xxx/..", where "yyy" can be null or
	     * a path starting at /, and "xxx" is a single component. Before
	     * compressing "xxx/..", we want to expand "yyy/xxx", if it is a
	     * symbolic link.
	     */
	    *--sp = 0;		/* form the pathname for readlink */
#ifdef S_IFLNK			/* if we have symlinks */
	    if (sp != cp && /* symlinks != SYM_IGNORE && */
		(tlink = areadlink(short2str(cp))) != NULL) {
		mlink = str2short(tlink);
		xfree(tlink);

		if (slash)
		    *p = '/';
		/*
		 * Point p to the '/' in "/..", and restore the '/'.
		 */
		*(p = sp) = '/';
		if (*mlink != '/') {
		    /*
		     * Relative path, expand it between the "yyy/" and the
		     * "/..". First, back sp up to the character past "yyy/".
		     */
		    while (*--sp != '/')
			continue;
		    sp++;
		    *sp = 0;
		    /*
		     * New length is "yyy/" + mlink + "/.." and rest
		     */
		    p1 = newcp = xmalloc(((sp - cp) + Strlen(mlink) +
					  Strlen(p) + 1) * sizeof(Char));
		    /*
		     * Copy new path into newcp
		     */
		    for (p2 = cp; (*p1++ = *p2++) != '\0';)
			continue;
		    for (p1--, p2 = mlink; (*p1++ = *p2++) != '\0';)
			continue;
		    for (p1--, p2 = p; (*p1++ = *p2++) != '\0';)
			continue;
		    /*
		     * Restart canonicalization at expanded "/xxx".
		     */
		    p = sp - cp - 1 + newcp;
		}
		else {
		    newcp = Strspl(mlink, p);
		    /*
		     * Restart canonicalization at beginning
		     */
		    p = newcp;
		}
		xfree(cp);
		cp = newcp;
#ifdef HAVE_SLASHSLASH
                slashslash = (cp[0] == '/' && cp[1] == '/');
#endif /* HAVE_SLASHSLASH */
		continue;	/* canonicalize the link */
	    }
#endif /* S_IFLNK */
	    *sp = '/';
	    if (sp != cp)
		while (*--sp != '/')
		    continue;
	    if (slash) {
		for (p1 = sp + 1, p2 = p + 1; (*p1++ = *p2++) != '\0';)
		    continue;
		p = sp;
	    }
	    else if (cp == sp)
		*++sp = '\0';
	    else
		*sp = '\0';
	}
	else {			/* normal dir name (not . or .. or nothing) */

#ifdef S_IFLNK			/* if we have symlinks */
	    if (sp != cp && symlinks == SYM_CHASE &&
		(tlink = areadlink(short2str(cp))) != NULL) {
		mlink = str2short(tlink);
		xfree(tlink);

		/*
		 * restore the '/'.
		 */
		if (slash)
		    *p = '/';

		/*
		 * point sp to p (rather than backing up).
		 */
		sp = p;

		if (*mlink != '/') {
		    /*
		     * Relative path, expand it between the "yyy/" and the
		     * remainder. First, back sp up to the character past
		     * "yyy/".
		     */
		    while (*--sp != '/')
			continue;
		    sp++;
		    *sp = 0;
		    /*
		     * New length is "yyy/" + mlink + "/.." and rest
		     */
		    p1 = newcp = xmalloc(((sp - cp) + Strlen(mlink) +
					  Strlen(p) + 1) * sizeof(Char));
		    /*
		     * Copy new path into newcp
		     */
		    for (p2 = cp; (*p1++ = *p2++) != '\0';)
			continue;
		    for (p1--, p2 = mlink; (*p1++ = *p2++) != '\0';)
			continue;
		    for (p1--, p2 = p; (*p1++ = *p2++) != '\0';)
			continue;
		    /*
		     * Restart canonicalization at expanded "/xxx".
		     */
		    p = sp - cp - 1 + newcp;
		}
		else {
		    newcp = Strspl(mlink, p);
		    /*
		     * Restart canonicalization at beginning
		     */
		    p = newcp;
		}
		xfree(cp);
		cp = newcp;
#ifdef HAVE_SLASHSLASH
                slashslash = (cp[0] == '/' && cp[1] == '/');
#endif /* HAVE_SLASHSLASH */
		continue;	/* canonicalize the mlink */
	    }
#endif /* S_IFLNK */
	    if (slash)
		*p = '/';
	}
    }

    /*
     * fix home...
     */
#ifdef S_IFLNK
    p1 = varval(STRhome);
    cc = Strlen(p1);
    /*
     * See if we're not in a subdir of STRhome
     */
    if (p1 && *p1 == '/' && (Strncmp(p1, cp, cc) != 0 ||
	(cp[cc] != '/' && cp[cc] != '\0'))) {
	static ino_t home_ino = (ino_t) -1;
	static dev_t home_dev = (dev_t) -1;
	static Char *home_ptr = NULL;
	struct stat statbuf;
	int found;
	Char *copy;

	/*
	 * Get dev and ino of STRhome
	 */
	if (home_ptr != p1 &&
	    stat(short2str(p1), &statbuf) != -1) {
	    home_dev = statbuf.st_dev;
	    home_ino = statbuf.st_ino;
	    home_ptr = p1;
	}
	/*
	 * Start comparing dev & ino backwards
	 */
	p2 = copy = Strsave(cp);
	found = 0;
	while (*p2 && stat(short2str(p2), &statbuf) != -1) {
	    if (DEV_DEV_COMPARE(statbuf.st_dev, home_dev) &&
			statbuf.st_ino == home_ino) {
			found = 1;
			break;
	    }
	    if ((sp = Strrchr(p2, '/')) != NULL)
		*sp = '\0';
	}
	/*
	 * See if we found it
	 */
	if (*p2 && found) {
	    /*
	     * Use STRhome to make '~' work
	     */
	    newcp = Strspl(p1, cp + Strlen(p2));
	    xfree(cp);
	    cp = newcp;
	}
	xfree(copy);
    }
#endif /* S_IFLNK */

#ifdef HAVE_SLASHSLASH
    if (slashslash) {
	if (cp[1] != '/') {
	    p = xmalloc((Strlen(cp) + 2) * sizeof(Char));
	    *p = '/';
	    (void) Strcpy(&p[1], cp);
	    xfree(cp);
	    cp = p;
	}
    }
    if (cp[1] == '/' && cp[2] == '/') {
	for (p1 = &cp[1], p2 = &cp[2]; (*p1++ = *p2++) != '\0';)
	    continue;
    }
#endif /* HAVE_SLASHSLASH */
    return cp;
}
Пример #15
0
static __inline__ int comp_name(void * src,void * desc)
{
	return Strncmp(src,desc,DIGEST_SIZE);
}
Пример #16
0
/*  Returns 0 on success; 1 on error. */
int wipspool(const char *file)
{
    char *lpr, *ptr;
    char fmt[BUFSIZ];
    char outbuf[BUFSIZ];
    int okayState;

#ifdef WIPVMS
    okayState = 1;
#else
    okayState = 0;
#endif /* WIPVMS */

    if ((ptr = wipgetstring("print")) == (char *)NULL) {
        wipoutput(stderr, "HARDCOPY: Error finding printing command.\n");
        return(1);
    }

    if (wiplenc(ptr) < 1)  /* If string is empty, no printing desired. */
        return(0);

    if (Strncmp(ptr, "ignore", 6) == 0) /* Still, no printing desired. */
        return(0);

    lpr = Strcpy(outbuf, ptr);

    if ((ptr = Strchr(lpr, '&')) != (char *)NULL) {
        while(*ptr) {                      /* Remove all '&' characters. */
            if (*ptr == '&') *ptr = ' ';
            ptr++;
        }
    }

#ifdef WIPVMS
    if (Strstr(lpr, "%s") == (char *)NULL) {
        SPrintf(fmt, "%s %%s", lpr);
    } else {
        SPrintf(fmt, "%s", lpr);
    }
#else
    if (Strstr(lpr, "%s") == (char *)NULL) {
        SPrintf(fmt, "%s %%s &\n", lpr);
    } else {
        SPrintf(fmt, "%s &\n", lpr);
    }
#endif /* WIPVMS */

    /*
     *  "fmt" now contains the printer command along with a "%s" for
     *  the file name.
     */

    if ((ptr = wipleading(file)) == (char *)NULL) {
        wipoutput(stderr, "HARDCOPY: Can't get the name of the file to spool.\n");
        return(1);
    }

    SPrintf(outbuf, fmt, ptr);
    wipoutput(stdout, "HARDCOPY: Spooling command:\n %s", outbuf);
    if (System(outbuf) != okayState) {
        wipoutput(stderr, "HARDCOPY: Error spooling WIP printer file.\n");
        return(1);
    }

    return(0);
}
Пример #17
0
/*
 * dcanon - canonicalize the pathname, removing excess ./ and ../ etc.
 *	we are of course assuming that the file system is standardly
 *	constructed (always have ..'s, directories have links)
 */
Char   *
dcanon(Char *cp, Char *p)
{
    Char *sp;
    Char *p1, *p2;	/* general purpose */
    bool    slash;

    Char    link[PATH_MAX];
    char    tlink[PATH_MAX];
    int     cc;
    Char   *newcp;

    /*
     * christos: if the path given does not start with a slash prepend cwd. If
     * cwd does not start with a path or the result would be too long abort().
     */
    if (*cp != '/') {
	Char    tmpdir[PATH_MAX];

	p1 = value(STRcwd);
	if (p1 == NULL || *p1 != '/')
	    abort();
	if (Strlen(p1) + Strlen(cp) + 1 >= PATH_MAX)
	    abort();
	(void) Strlcpy(tmpdir, p1, sizeof tmpdir/sizeof(Char));
	(void) Strlcat(tmpdir, STRslash, sizeof tmpdir/sizeof(Char));
	(void) Strlcat(tmpdir, cp, sizeof tmpdir/sizeof(Char));
	free(cp);
	cp = p = Strsave(tmpdir);
    }

    while (*p) {		/* for each component */
	sp = p;			/* save slash address */
	while (*++p == '/')	/* flush extra slashes */
	    continue;
	if (p != ++sp)
	    for (p1 = sp, p2 = p; (*p1++ = *p2++) != '\0';)
		continue;
	p = sp;			/* save start of component */
	slash = 0;
	while (*p)		/* find next slash or end of path */
	    if (*++p == '/') {
		slash = 1;
		*p = 0;
		break;
	    }

	if (*sp == '\0')	/* if component is null */
	    if (--sp == cp)	/* if path is one char (i.e. /) */
		break;
	    else
		*sp = '\0';
	else if (sp[0] == '.' && sp[1] == 0) {
	    if (slash) {
		for (p1 = sp, p2 = p + 1; (*p1++ = *p2++) != '\0';)
		    continue;
		p = --sp;
	    }
	    else if (--sp != cp)
		*sp = '\0';
	}
	else if (sp[0] == '.' && sp[1] == '.' && sp[2] == 0) {
	    /*
	     * We have something like "yyy/xxx/..", where "yyy" can be null or
	     * a path starting at /, and "xxx" is a single component. Before
	     * compressing "xxx/..", we want to expand "yyy/xxx", if it is a
	     * symbolic link.
	     */
	    *--sp = 0;		/* form the pathname for readlink */
	    if (sp != cp && !adrof(STRignore_symlinks) &&
		(cc = readlink(short2str(cp), tlink,
			       sizeof tlink-1)) >= 0) {
		tlink[cc] = '\0';
		(void) Strlcpy(link, str2short(tlink), sizeof link/sizeof(Char));

		if (slash)
		    *p = '/';
		/*
		 * Point p to the '/' in "/..", and restore the '/'.
		 */
		*(p = sp) = '/';
		/*
		 * find length of p
		 */
		for (p1 = p; *p1++;)
		    continue;
		if (*link != '/') {
		    /*
		     * Relative path, expand it between the "yyy/" and the
		     * "/..". First, back sp up to the character past "yyy/".
		     */
		    while (*--sp != '/')
			continue;
		    sp++;
		    *sp = 0;
		    /*
		     * New length is "yyy/" + link + "/.." and rest
		     */
		    p1 = newcp = xreallocarray(NULL,
			(sp - cp) + cc + (p1 - p), sizeof(Char));
		    /*
		     * Copy new path into newcp
		     */
		    for (p2 = cp; (*p1++ = *p2++) != '\0';)
			continue;
		    for (p1--, p2 = link; (*p1++ = *p2++) != '\0';)
			continue;
		    for (p1--, p2 = p; (*p1++ = *p2++) != '\0';)
			continue;
		    /*
		     * Restart canonicalization at expanded "/xxx".
		     */
		    p = sp - cp - 1 + newcp;
		}
		else {
		    /*
		     * New length is link + "/.." and rest
		     */
		    p1 = newcp = xreallocarray(NULL, cc + (p1 - p),
		        sizeof(Char));
		    /*
		     * Copy new path into newcp
		     */
		    for (p2 = link; (*p1++ = *p2++) != '\0';)
			continue;
		    for (p1--, p2 = p; (*p1++ = *p2++) != '\0';)
			continue;
		    /*
		     * Restart canonicalization at beginning
		     */
		    p = newcp;
		}
		free(cp);
		cp = newcp;
		continue;	/* canonicalize the link */
	    }
	    *sp = '/';
	    if (sp != cp)
		while (*--sp != '/')
		    continue;
	    if (slash) {
		for (p1 = sp + 1, p2 = p + 1; (*p1++ = *p2++) != '\0';)
		    continue;
		p = sp;
	    }
	    else if (cp == sp)
		*++sp = '\0';
	    else
		*sp = '\0';
	}
	else {			/* normal dir name (not . or .. or nothing) */

	    if (sp != cp && adrof(STRchase_symlinks) &&
		!adrof(STRignore_symlinks) &&
		(cc = readlink(short2str(cp), tlink,
			       sizeof tlink-1)) >= 0) {
		tlink[cc] = '\0';
		(void) Strlcpy(link, str2short(tlink), sizeof link/sizeof(Char));

		/*
		 * restore the '/'.
		 */
		if (slash)
		    *p = '/';

		/*
		 * point sp to p (rather than backing up).
		 */
		sp = p;

		/*
		 * find length of p
		 */
		for (p1 = p; *p1++;)
		    continue;
		if (*link != '/') {
		    /*
		     * Relative path, expand it between the "yyy/" and the
		     * remainder. First, back sp up to the character past
		     * "yyy/".
		     */
		    while (*--sp != '/')
			continue;
		    sp++;
		    *sp = 0;
		    /*
		     * New length is "yyy/" + link + "/.." and rest
		     */
		    p1 = newcp = xreallocarray(NULL,
			  (sp - cp) + cc + (p1 - p), sizeof(Char));
		    /*
		     * Copy new path into newcp
		     */
		    for (p2 = cp; (*p1++ = *p2++) != '\0';)
			continue;
		    for (p1--, p2 = link; (*p1++ = *p2++) != '\0';)
			continue;
		    for (p1--, p2 = p; (*p1++ = *p2++) != '\0';)
			continue;
		    /*
		     * Restart canonicalization at expanded "/xxx".
		     */
		    p = sp - cp - 1 + newcp;
		}
		else {
		    /*
		     * New length is link + the rest
		     */
		    p1 = newcp = xreallocarray(NULL, cc + (p1 - p), sizeof(Char));
		    /*
		     * Copy new path into newcp
		     */
		    for (p2 = link; (*p1++ = *p2++) != '\0';)
			continue;
		    for (p1--, p2 = p; (*p1++ = *p2++) != '\0';)
			continue;
		    /*
		     * Restart canonicalization at beginning
		     */
		    p = newcp;
		}
		free(cp);
		cp = newcp;
		continue;	/* canonicalize the link */
	    }
	    if (slash)
		*p = '/';
	}
    }

    /*
     * fix home...
     */
    p1 = value(STRhome);
    cc = Strlen(p1);
    /*
     * See if we're not in a subdir of STRhome
     */
    if (p1 && *p1 == '/' &&
	(Strncmp(p1, cp, cc) != 0 || (cp[cc] != '/' && cp[cc] != '\0'))) {
	static ino_t home_ino = -1;
	static dev_t home_dev = -1;
	static Char *home_ptr = NULL;
	struct stat statbuf;

	/*
	 * Get dev and ino of STRhome
	 */
	if (home_ptr != p1 &&
	    stat(short2str(p1), &statbuf) != -1) {
	    home_dev = statbuf.st_dev;
	    home_ino = statbuf.st_ino;
	    home_ptr = p1;
	}
	/*
	 * Start comparing dev & ino backwards
	 */
	Strlcpy(link, cp, sizeof link/sizeof(Char));
	p2 = link;
	for (sp = NULL; *p2 && stat(short2str(p2), &statbuf) != -1;) {
	    if (statbuf.st_dev == home_dev &&
		statbuf.st_ino == home_ino) {
		sp = (Char *) - 1;
		break;
	    }
	    if ((sp = Strrchr(p2, '/')) != NULL)
		*sp = '\0';
	}
	/*
	 * See if we found it
	 */
	if (*p2 && sp == (Char *) -1) {
	    /*
	     * Use STRhome to make '~' work
	     */
	    newcp = Strspl(p1, cp + Strlen(p2));
	    free(cp);
	    cp = newcp;
	}
    }
    return cp;
}
Пример #18
0
int
parse_cmd(char *cmd_str, long int **cmd, int *cmd_len)
    /* read a command string, check if it is valid and translate it */
{
    long int buf[SOCKET_MSG_LEN];
    int word_size = 0;
    int i = 0, j = 0, rank = -1;
    long int int_buf = 0;
    struct passwd *pass = NULL;
#ifdef SYSFCRONTAB
    long int sysfcrontab_uid = SYSFCRONTAB_UID;
#endif

    bzero(buf, sizeof(buf));
    *cmd_len = 0;
    remove_blanks(cmd_str);     /* at the end of the string */

    if ((word_size = get_word(&cmd_str)) == 0) {
        fprintf(stderr, "Warning : Zero-length command name : line ignored.\n");
        return ZEROLEN_CMD;
    }

    for (i = 0; i < cmd_list_len; i++) {
        int j;
        if (Strncmp(cmd_str, cmd_list[i].cmd_name, word_size) == 0) {
            rank = i;
            break;
        }
        for (j = 0; j < MAX_NUM_ALIAS && cmd_list[i].cmd_alias[j] != NULL; j++) {
            if (Strncmp(cmd_str, cmd_list[i].cmd_alias[j], word_size) == 0) {
                rank = i;
                break;
            }
        }
    }
    if (rank == (-1)) {
        fprintf(stderr, "Error : Unknown command.\n");
        return CMD_NOT_FOUND;
    }
    else if (cmd_list[rank].cmd_code == QUIT_CMD) {
        if (debug_opt)
            fprintf(stderr, "quit command\n");
        return QUIT_CMD;
    }
    else if (cmd_list[rank].cmd_code == HELP_CMD) {
        if (debug_opt)
            fprintf(stderr, "Help command\n");
        return HELP_CMD;
    }

    Write_cmd(cmd_list[rank].cmd_code);

    if (debug_opt)
        fprintf(stderr, "command : %s\n", cmd_list[i].cmd_name);

    cmd_str += word_size;
    for (i = 0; i < cmd_list[rank].cmd_numopt; i++) {

        if ((word_size = get_word(&cmd_str)) == 0) {

            if (cmd_list[rank].cmd_default[i] == ARG_REQUIRED) {
                fprintf(stderr, "Error : arg required !\n");
                return INVALID_ARG;
            }

            /* use default value : currently, works only with CUR_USER */
            if (user_uid == rootuid) {
                /* default for root = all */
                int_buf = ALL;
                Write_cmd(int_buf);
                if (debug_opt)
                    fprintf(stderr, "  uid = ALL\n");
            }
            else {
                Write_cmd(user_uid);
                if (debug_opt)
                    fprintf(stderr, "  uid = %d\n", (int)user_uid);
            }

        }

        else {

            /* get value from line ... */
            switch (cmd_list[rank].cmd_opt[i]) {

            case USER:
                int_buf = (long int)*(cmd_str + word_size);
                *(cmd_str + word_size) = '\0';
#ifdef SYSFCRONTAB
                if (strcmp(cmd_str, SYSFCRONTAB) == 0) {
                    Write_cmd(sysfcrontab_uid);
                }
                else {
#endif
                    if ((pass = getpwnam(cmd_str)) == NULL) {
                        fprintf(stderr,
                                "Error : '%s' isn't a valid username.\n",
                                cmd_str);
                        return INVALID_ARG;
                    }
                    Write_cmd(pass->pw_uid);
#ifdef SYSFCRONTAB
                }
#endif
                *(cmd_str + word_size) = (char)int_buf;
                cmd_str += word_size;
                if (debug_opt)
                    fprintf(stderr, "  uid = %d\n",
#ifdef SYSFCRONTAB
                            (pass) ? (int)pass->pw_uid : (int)SYSFCRONTAB_UID
#else
                            (int)pass->pw_uid
#endif
                        );
                break;

            case JOBID:
                /* after strtol(), cmd_str will be updated (first non-number char) */
                if ((int_buf = strtol(cmd_str, &cmd_str, 10)) < 0
                    || int_buf >= LONG_MAX || (!isspace((int)*cmd_str)
                                               && *cmd_str != '\0')) {
                    fprintf(stderr, "Error : invalid jobid.\n");
                    return INVALID_ARG;
                }
                Write_cmd(int_buf);
                if (debug_opt)
                    fprintf(stderr, "  jobid = %ld\n", int_buf);
                break;

            case TIME_AND_DATE:
                /* argghh !!! no standard function ! */
                break;

            case NICE_VALUE:
                /* after strtol(), cmd_str will be updated (first non-number char) */
                if ((int_buf = strtol(cmd_str, &cmd_str, 10)) > 20
                    || (int_buf < 0 && getuid() != rootuid) || int_buf < -20
                    || (!isspace((int)*cmd_str) && *cmd_str != '\0')) {
                    fprintf(stderr, "Error : invalid nice value.\n");
                    return INVALID_ARG;
                }
                Write_cmd(int_buf);
                if (debug_opt)
                    fprintf(stderr, "  nicevalue = %ld\n", int_buf);
                break;

            case SIGNAL:
                if (isalpha((int)*cmd_str)) {
                    for (j = 0; j < word_size; j++)
                        *(cmd_str + j) = tolower(*(cmd_str + j));
                    if (Strncmp(cmd_str, "hup", word_size) == 0)
                        int_buf = SIGHUP;
                    else if (Strncmp(cmd_str, "int", word_size) == 0)
                        int_buf = SIGINT;
                    else if (Strncmp(cmd_str, "quit", word_size) == 0)
                        int_buf = SIGQUIT;
                    else if (Strncmp(cmd_str, "kill", word_size) == 0)
                        int_buf = SIGKILL;
                    else if (Strncmp(cmd_str, "alrm", word_size) == 0)
                        int_buf = SIGALRM;
                    else if (Strncmp(cmd_str, "term", word_size) == 0)
                        int_buf = SIGTERM;
                    else if (Strncmp(cmd_str, "usr1", word_size) == 0)
                        int_buf = SIGUSR1;
                    else if (Strncmp(cmd_str, "usr2", word_size) == 0)
                        int_buf = SIGUSR2;
                    else if (Strncmp(cmd_str, "cont", word_size) == 0)
                        int_buf = SIGCONT;
                    else if (Strncmp(cmd_str, "stop", word_size) == 0)
                        int_buf = SIGSTOP;
                    else if (Strncmp(cmd_str, "tstp", word_size) == 0)
                        int_buf = SIGTSTP;
                    else {
                        fprintf(stderr,
                                "Error : unknow signal (try integer value)\n");
                        return INVALID_ARG;
                    }
                    cmd_str += word_size;
                }
                /* after strtol(), cmd_str will be updated (first non-number char) */
                else if ((int_buf = strtol(cmd_str, &cmd_str, 10)) <= 0
                         || int_buf >= LONG_MAX || (!isspace((int)*cmd_str)
                                                    && *cmd_str != '\0')) {
                    fprintf(stderr, "Error : invalid signal value.\n");
                    return INVALID_ARG;
                }
                Write_cmd(int_buf);
                if (debug_opt)
                    fprintf(stderr, "  signal = %ld\n", int_buf);
                break;

            default:
                fprintf(stderr, "Error : Unknown arg !");
                return INVALID_ARG;
            }
        }
    }

    Skip_blanks(cmd_str);
    if (*cmd_str != '\0')
        fprintf(stderr, "Warning : too much arguments : '%s' ignored.\n",
                cmd_str);

    /* This is a valid command ... */
    *cmd = alloc_safe(*cmd_len * sizeof(long int), "command string");
    memcpy(*cmd, buf, *cmd_len * sizeof(long int));

    return OK;
}
Пример #19
0
int Swig_storage_isstatic_custom(Node *n, const_String_or_char_ptr storage_name) {
  const String *storage = Getattr(n, storage_name);
  return storage ? Strncmp(storage, "static", 6) == 0 : 0;
}
Пример #20
0
int proc_verify(void * sub_proc,void * message)
{
	int type;
	int subtype;
	int ret;
	printf("begin proc login_verify \n");

	type=message_get_type(message);
	if(type!=DTYPE_CRYPTO_DEMO)
		return -EINVAL;
	subtype=message_get_subtype(message);
	if(subtype!=SUBTYPE_LOGIN_INFO)
		return -EINVAL;

	void * new_msg;
	void * record;
	
	struct login_info * login_data;
	struct login_info * lib_data;
	struct verify_return * return_data;

	new_msg=message_create(DTYPE_CRYPTO_DEMO,SUBTYPE_VERIFY_RETURN,message);
	return_data=Talloc0(sizeof(*return_data));

	ret=message_get_record(message,&login_data,0);
	if(ret<0)
		return ret;

	lib_data=memdb_get_first_record(type,subtype);
	while(lib_data!=NULL)
	{
		if(Strncmp(lib_data->user,login_data->user,DIGEST_SIZE)==0)
			break;
		lib_data=memdb_get_next_record(type,subtype);
	}
	if(lib_data==NULL)
	{
		return_data->ret_data=dup_str("no such user!",0);
		return_data->retval=-1;
	}
	else
	{
		if (Strncmp(lib_data->passwd,login_data->passwd,DIGEST_SIZE)!=0)
		{
			return_data->ret_data=dup_str("error passwd!",0);
			return_data->retval=0;
		}
		else
		{
			return_data->ret_data=dup_str("login_succeed!",0);
			return_data->retval=1;
			ret=user_addr_store(sub_proc,message);
			if(ret<0)
				return ret;
		}
	}
	return_data->ret_data_size=Strlen(return_data->ret_data)+1;
	message_add_record(new_msg,return_data);
	ex_module_sendmsg(sub_proc,new_msg);
	return ret;
}
Пример #21
0
/*ARGSUSED*/
int
xxxinit(
	unsigned int fc,
	struct vddrv *vdp,
	addr_t vdin,
	struct vdstat *vds
	)
{
	extern struct fmodsw fmodsw[];
	extern int fmodcnt;

	struct fmodsw *fm    = fmodsw;
	struct fmodsw *fmend = &fmodsw[fmodcnt];
	struct fmodsw *ifm   = (struct fmodsw *)0;
	char *mname          = parseinfo.st_rdinit->qi_minfo->mi_idname;

	switch (fc)
	{
	    case VDLOAD:
		vdp->vdd_vdtab = (struct vdlinkage *)&parsesync_vd;
		/*
		 * now, jog along fmodsw scanning for an empty slot
		 * and deposit our name there
		 */
		while (fm <= fmend)
		{
			if (!Strncmp(fm->f_name, mname, FMNAMESZ))
			{
				printf("vddrinit[%s]: STREAMS module already loaded.\n", mname);
				return(EBUSY);
			}
			else
			    if ((ifm == (struct fmodsw *)0) &&
				(fm->f_name[0] == '\0') &&
				(fm->f_str == (struct streamtab *)0))
			    {
				    /*
				     * got one - so move in
				     */
				    ifm = fm;
				    break;
			    }
			fm++;
		}

		if (ifm == (struct fmodsw *)0)
		{
			printf("vddrinit[%s]: no slot free for STREAMS module\n", mname);
			return (ENOSPC);
		}
		else
		{
			static char revision[] = "4.7";
			char *s, *S, *t;

			s = rcsid;		/* NOOP - keep compilers happy */

			Strncpy(ifm->f_name, mname, FMNAMESZ);
			ifm->f_name[FMNAMESZ] = '\0';
			ifm->f_str = &parseinfo;
			/*
			 * copy RCS revision into Drv_name
			 *
			 * are we forcing RCS here to do things it was not built for ?
			 */
			s = revision;
			if (*s == '$')
			{
				/*
				 * skip "$Revision: "
				 * if present. - not necessary on a -kv co (cvs export)
				 */
				while (*s && (*s != ' '))
				{
					s++;
				}
				if (*s == ' ') s++;
			}

			t = parsesync_vd.Drv_name;
			while (*t && (*t != ' '))
			{
				t++;
			}
			if (*t == ' ') t++;

			S = s;
			while (*S && (((*S >= '0') && (*S <= '9')) || (*S == '.')))
			{
				S++;
			}

			if (*s && *t && (S > s))
			{
				if (Strlen(t) >= (S - s))
				{
					(void) Strncpy(t, s, S - s);
				}
			}
			return (0);
		}
		break;

	    case VDUNLOAD:
		if (parsebusy > 0)
		{
			printf("vddrinit[%s]: STREAMS module has still %d instances active.\n", mname, parsebusy);
			return (EBUSY);
		}
		else
		{
			while (fm <= fmend)
			{
				if (!Strncmp(fm->f_name, mname, FMNAMESZ))
				{
					/*
					 * got it - kill entry
					 */
					fm->f_name[0] = '\0';
					fm->f_str = (struct streamtab *)0;
					fm++;

					break;
				}
				fm++;
			}
			if (fm > fmend)
			{
				printf("vddrinit[%s]: cannot find entry for STREAMS module\n", mname);
				return (ENXIO);
			}
			else
			    return (0);
		}


	    case VDSTAT:
		return (0);

	    default:
		return (EIO);

	}
	return EIO;
}
Пример #22
0
int dispatch_match_message(void * policy,void * message)
{
	int ret;
	int result=0;
	int prev_result=0;
	int match_rule_num=0;
	DISPATCH_POLICY * dispatch_policy=(DISPATCH_POLICY *)policy;
	MATCH_RULE * match_rule;
	MSG_HEAD * msg_head;
	void * msg_record;
	void * record_template;
	
	msg_head=message_get_head(message);
	if(msg_head==NULL)
		return -EINVAL;

	if(dispatch_policy->name!=NULL)
	{
		if(msg_head->route[0]!=0)
			if(Strncmp(dispatch_policy->name,msg_head->route,DIGEST_SIZE)!=0)
				return 0;	
	}

	ret=dispatch_policy_getfirstmatchrule(policy,&match_rule);
	if(ret<0)
		return ret;
	while(match_rule!=NULL)
	{
		if((match_rule->area==0)||(match_rule->area==MATCH_AREA_HEAD))
		{
			if(match_rule->type==0)
				result=1;
			else if(match_rule->type ==msg_head->record_type)
			{
				if(match_rule->subtype==0)
					result= 1;
				else if(match_rule->subtype==msg_head->record_subtype)
					result = 1;
			}
			else
			{
				result = 0;
			}
		}
		else if(match_rule->area==MATCH_AREA_RECORD)
		{	
			if(match_rule->type==0)
				result = 1;
			else if((match_rule->type!=msg_head->record_type)||
				(match_rule->subtype!=msg_head->record_subtype))
				result = 0;
			else if(match_rule->match_template==NULL)
				result = 1;
			else
			{
				ret=message_get_record(message,&msg_record,0);
				if(ret<0)
					result =ret;
				else if(msg_record==NULL)
					result = 0;
	
				else if(!struct_part_compare(match_rule->value,msg_record,match_rule->match_template,match_flag))
					result = 1;
				else
					result = 0;
			}
		}
		else if(match_rule->area==MATCH_AREA_EXPAND)
		{
			MSG_EXPAND * msg_expand;			
			void * expand_template;
			ret=message_get_define_expand(message,&msg_expand,match_rule->type,match_rule->subtype);
			if(msg_expand==NULL)
				result=0;
			else if(match_rule->value==NULL)
				result=1;
			else
			{
			//	expand_template=memdb_get_template(match_rule->type,match_rule->subtype);
				if(match_rule->match_template==NULL)
					result=0;
				else
				{
					if(!struct_part_compare(match_rule->value,msg_expand->expand,
							match_rule->match_template,match_flag))
						result = 1;
					else
						result = 0;
				}
			}	
		}
		else
		{
			result = 0;
		}
		
		if(result<0)
			return result;
		switch(match_rule->op)
		{
			case DISPATCH_MATCH_AND:
				if(result==0)
					return result;	
				prev_result=1;
				break;				
			case DISPATCH_MATCH_OR:
				if(result>0)
					return result;	
				break;				

			case DISPATCH_MATCH_NOT:
				if(result>0)
					return 0;	
				prev_result=1;
				break;
			case DISPATCH_MATCH_ORNOT:
				if(result==0)
					return 1;
				break;	
			
			default:
				return -EINVAL;	
		}
		match_rule_num++;
		ret=dispatch_policy_getnextmatchrule(policy,&match_rule);
		if(ret<0)
			return ret;
	}	
	if(match_rule_num==0)
		return 0;
	return prev_result;
}