示例#1
0
WINAPI 
hes_to_bind(LPSTR HesiodName,			
            LPSTR HesiodNameType)		
{
    register char *cp, **cpp;
    char* bindname;
    LPVOID lpvData;
    char *RHS;

    cp = NULL;
    cpp = NULL;

    bindname = (LPSTR)(TlsGetValue(dwHesIndex));
    if (bindname == NULL) 
    { 
        lpvData = LocalAlloc(LPTR, DNS_MAX_NAME_BUFFER_LENGTH); 
        if (lpvData != NULL) 
        {
            TlsSetValue(dwHesIndex, lpvData); 
            bindname = (LPSTR)lpvData;
        }
        else
            return NULL;
    }
    if (Hes_Errno == HES_ER_UNINIT || Hes_Errno == HES_ER_CONFIG)
        (void) hes_init();
    if (Hes_Errno == HES_ER_CONFIG) 
	return(NULL);
    if (cp = index(HesiodName,'@')) {
        if (index(++cp,'.'))
            RHS = cp;
        else
            if (cpp = hes_resolve(cp, "rhs-extension"))
                RHS = *cpp;
            else {
                Hes_Errno = HES_ER_NOTFOUND;
                return(NULL);
            }
        (void) strcpy(bindname,HesiodName);
        (*index(bindname,'@')) = '\0';
    } else {
        RHS = Hes_RHS;
        (void) strcpy(bindname, HesiodName);
    }
    (void) strcat(bindname, ".");
    (void) strcat(bindname, HesiodNameType);
    if (Hes_LHS) {
        if (Hes_LHS[0] != '.')
            (void) strcat(bindname,".");
        (void) strcat(bindname, Hes_LHS);
    }
    if (RHS[0] != '.')
        (void) strcat(bindname,".");
    (void) strcat(bindname, RHS);

    if(cpp != NULL )	
        hes_free(cpp);

    return(bindname);
}
示例#2
0
文件: hesmailh.c 项目: Akasurde/krb5
WINAPI
hes_getmailhost(LPSTR user)
{
    struct hes_postoffice* ret;
    char linebuf[LINESIZE];
    char *p, *tmp;
    char **cp;


    cp = hes_resolve(user, "pobox");
    if (cp == NULL) return(NULL);

    ret = (struct hes_postoffice*)(TlsGetValue(dwHesMailIndex));
    if (ret == NULL) {
	LPVOID lpvData = (LPVOID) LocalAlloc(LPTR, sizeof(struct hes_postoffice));
	if (lpvData != NULL) {
	    TlsSetValue(dwHesMailIndex, lpvData);
	    ret = (struct hes_postoffice*)lpvData;
	} else
	    return NULL;
    }
    if (!ret->po_type)
        ret->po_type = LocalAlloc(LPTR, LINESIZE);
    if (!ret->po_host)
        ret->po_host = LocalAlloc(LPTR, LINESIZE);
    if (!ret->po_name)
        ret->po_name = LocalAlloc(LPTR, LINESIZE);
    strcpy(linebuf, *cp);

    p = linebuf;
    tmp = linebuf;
    while(!isspace(*p)) p++;
    *p++ = '\0';
    strcpy(ret->po_type, tmp);
    tmp = p;
    while(!isspace(*p)) p++;
    *p++ = '\0';
    strcpy(ret->po_host, tmp);
    strcpy(ret->po_name, p);
    if (cp)
        hes_free(cp);
    return(ret);
}
示例#3
0
multi_init()
{
  int i, weight;
#ifdef HESIOD
  char **hesres, **hesptr;
  struct hostent *hent;

  DebugMulti(("multi_init:\n"));
  
  servers = NULL;
  hesres = hes_resolve(HES_NAME, HES_TYPE);
  if (!hesres || !*hesres) {
    DebugMulti(("  No servers found\n"));
    return;
  }
  for (hesptr = hesres; *hesptr; hesptr++) {
    hent = gethostbyname(*hesptr);
    if (!hent)
      fatal("Can't resolve host %s!\n", *hesptr);
#else
    FILE *fp;
    char bfr[MAXHOSTNAMELEN];
    struct hostent *hent;

    fp = fopen(SERVER_LIST_FILE, "r");
    if (!fp) {
      servers = NULL;
      return;
    }
    DebugMulti(("My name is %s\n", my_canonhostname));
    while (fgets(bfr, sizeof bfr, fp) != NULL) {
      bfr[strlen(bfr)-1] = '\0';
      hent = gethostbyname(bfr);
      if (!hent)
	fatal("Can't resolve host %s!\n", bfr);
#endif /* HESIOD */	
      if (nservers)
	servers = (struct _servers *)xrealloc(servers,
					      (nservers+1)*
					      sizeof(struct _servers));
      else
	servers = (struct _servers *)xmalloc(sizeof(struct _servers));
      memset(&servers[nservers], 0, sizeof(struct _servers));
      servers[nservers].name = xsave_string(hent->h_name);
      servers[nservers].inet_addr.s_addr = *(long *)hent->h_addr_list[0];
      servers[nservers].cl = (CLIENT*)NULL;
      servers[nservers].maybe_up = 1;

      /* "Canonical" hostnames are case-insensitive.
       * I have seen gethostbyname() return OSAGE.MIT.EDU
       * and osage.MIT.EDU in consecutive calls from the
       * same process.  Thus the use of strcasecmp below:
       */
       
      if (!strcasecmp(hent->h_name, my_canonhostname)) {
	server_me = nservers;
      }
      servers[nservers].vote_weight = 2;
      DebugMulti(("Server %s at %s\n", hent->h_name,
		  inet_ntoa(servers[nservers].inet_addr)));
      nservers++;
#ifdef HESIOD
    }
#else
  }
#endif /* HESIOD */

  if (nservers > 0)
    servers[0].vote_weight = 3;
}
示例#4
0
文件: pawd.c 项目: enukane/netbsd-src
static char *
hack_name(char *dir)
{
  char partition[MAXPATHLEN];
  char username[MAXPATHLEN];
  char hesiod_lookup[MAXPATHLEN];
  char *to, *ch, *hes_name, *dot;
  char **hes;

#ifdef DEBUG
  fprintf(stderr, "hack_name(%s)\n", dir);
#endif /* DEBUG */

  if (dir[0] == '/' && dir[1] == 'a' && dir[2] == '/') {
    /* Could be /a/server/disk/home/partition/user... */
    ch = dir + 3;
    while (*ch && *ch != '/') ch++;  /* Skip server */
    if (!NSTREQ(ch, "/disk/home/", 11))
      return NULL;		/* Nope */
    /* Looking promising, next should be the partition name */
    ch += 11;
    to = partition;
    while (*ch && *ch != '/') *to++ = *ch++;
    to = '\0';
    if (!(*ch))
      return NULL;		/* Off the end */
    /* Now the username */
    ch++;
    to = username;
    while (*ch && *ch != '/') *to++ = *ch++;
    to = '\0';
#ifdef DEBUG
    fprintf(stderr, "partition %s, username %s\n", partition, username);
#endif /* DEBUG */

    xsnprintf(hesiod_lookup, sizeof(hesiod_lookup),
	      "%s.homes-remote", username);
    hes = hes_resolve(hesiod_lookup, "amd");
    if (!hes)
      return NULL;
#ifdef DEBUG
    fprintf(stderr, "hesiod -> <%s>\n", *hes);
#endif /* DEBUG */
    hes_name = strstr(*hes, "/homes/remote/");
    if (!hes_name) return NULL;
    hes_name += 14;
#ifdef DEBUG
    fprintf(stderr, "hesiod -> <%s>\n", hes_name);
#endif /* DEBUG */
    dot = hes_name;
    while (*dot && *dot != '.') dot++;
    *dot = '\0';
#ifdef DEBUG
    fprintf(stderr, "hesiod -> <%s>\n", hes_name);
#endif /* DEBUG */

    if (strcmp(partition, hes_name)) return NULL;
#ifdef DEBUG
    fprintf(stderr, "A match, munging....\n");
#endif /* DEBUG */
    xstrlcpy(transform, "/home/", sizeof(transform));
    xstrlcat(transform, username, sizeof(transform));
    if (*ch)
      xstrlcat(transform, ch, sizeof(transform));
#ifdef DEBUG
    fprintf(stderr, "Munged to <%s>\n", transform);
#endif /* DEBUG */
    return transform;
  }
  return NULL;
}
示例#5
0
文件: hesservb.c 项目: Akasurde/krb5
WINAPI
hes_getservbyname(char *name, char *proto)
{
    struct servent *p;
    register char **cp;
    register char** hesinfo;
    register int i = 0;

    char buf[DNS_MAX_NAME_BUFFER_LENGTH];
    char* l;

    hesinfo = hes_resolve(name, "service");
    cp = hesinfo;
    if (cp == NULL)
	return(NULL);
    p = (struct servent*)(TlsGetValue(dwHesServIndex));
    if (p == NULL) {
	LPVOID lpvData = (LPVOID) LocalAlloc(LPTR, sizeof(struct servent));
	if (lpvData != NULL) {
	    TlsSetValue(dwHesServIndex, lpvData);
	    p = (struct servent*)lpvData;
	} else
	    return NULL;
    }
    if (!p->s_name)
        p->s_name = LocalAlloc(LPTR, DNS_MAX_LABEL_BUFFER_LENGTH);
    if (!p->s_proto)
        p->s_proto = LocalAlloc(LPTR, DNS_MAX_LABEL_BUFFER_LENGTH);
    if (!p->s_aliases)
        p->s_aliases = LocalAlloc(LPTR, LISTSIZE*sizeof(LPSTR));

    for (;*cp; cp++) {
	register char *servicename, *protoname, *port;
        strcpy(buf, *cp);
        l = buf;
	while(*l && (*l == ' ' || *l == '\t')) l++;
	servicename = l;
	while(*l && *l != ' ' && *l != '\t' && *l != ';') l++;
	if (*l == '\0') continue; /* malformed entry */
	*l++ = '\0';
	while(*l && (*l == ' ' || *l == '\t')) l++;
	protoname = l;
	while(*l && *l != ' ' && *l != ';') l++;
	if (*l == '\0') continue; /* malformed entry */
	*l++ = '\0';
	if (cistrcmp(proto, protoname)) continue; /* wrong port */
	while(*l && (*l == ' ' || *l == '\t' || *l == ';')) l++;
	if (*l == '\0') continue; /* malformed entry */
	port = l;
	while(*l && (*l != ' ' && *l != '\t' && *l != ';')) l++;
	if (*l) *l++ = '\0';
	if (*l != '\0') {
	    do {
		char* tmp = l;
		while(*l && !isspace(*l)) l++;
		if (*l) *l++ = 0;
                if (p->s_aliases[i])
                    p->s_aliases[i] = LocalAlloc(LPTR, strlen(tmp));
                strcpy(p->s_aliases[i], tmp);
                i++;
	    } while(*l);
	}
	p->s_aliases[i] = NULL;
        for (; i<LISTSIZE; i++)
        {
            if (p->s_aliases[i]){
                LocalFree(p->s_aliases[i]);
                p->s_aliases[i] = NULL;
            }
        }
	strcpy(p->s_name, servicename);
	p->s_port = htons((u_short)atoi(port));
	strcpy(p->s_proto, protoname);
        if (hesinfo)
            hes_free(hesinfo);
	return (p);
    }
    return(NULL);
}