예제 #1
0
int main()
{
    FILE *pascal_file,*lex_file;
    char file_name[40], file_name2[40];
    char is_token[40];
    char current_char;
    char before_current_char;
    int i=0,j,is_comment=0,is_assignment=0;
    printf("Please enter the source file name: ");
    fflush(stdin);
    gets(file_name);
    strcpy(file_name2,file_name);
    strcat(file_name,".pas");
    strcat(file_name2,".lex");


    for(j=0;j<40;j++)
        is_token[j]=0;
    if((pascal_file = fopen(file_name,"r")) == NULL)
        printf("dosya acilamadi!\n");
    else
    {
        lex_file = fopen(file_name2,"w");
        while(!feof(pascal_file))
        {

            current_char=getc(pascal_file);
            if(isLetter(current_char)==1)//current_char harfse string e eklenir
            {
                is_token[i]=current_char;
                i++;
            }
            else if(isLetter(current_char)==0 && i!=0)// current char harf degilse ondan onceki stringi(is_letter) yazdýr
            {
                if(strcmp("writeln",is_token)==0 || strcmp("write",is_token)==0)
                {
                    fputs("output(",lex_file);
                    fputs(is_token,lex_file);
                    fputs("),",lex_file);
                }
                else if(strcmp("readln",is_token)==0 || strcmp("read",is_token)==0)
                {
                    fputs("input(",lex_file);
                    fputs(is_token,lex_file);
                    fputs("),",lex_file);
                }
                else if(isReservedWord(is_token)==1)
                {
                    fputs("reservedWord(",lex_file);
                    fputs(is_token,lex_file);
                    fputs("),",lex_file);
                }
                else if(isAdvMathFunc(is_token)==1)
                {
                    fputs("advancedMathFunction(",lex_file);
                    fputs(is_token,lex_file);
                    fputs("),",lex_file);
                }
                else if(isOrdinalFunc(is_token)==1)
                {
                    fputs("ordinalFunction(",lex_file);
                    fputs(is_token,lex_file);
                    fputs("),",lex_file);
                }
                else if(isVariableType(is_token)==1)
                {
                    fputs("variableType(",lex_file);
                    fputs(is_token,lex_file);
                    fputs("),",lex_file);
                }
                else if(isBoolOperator(is_token)==1)
                {
                    fputs("booleanOperator(",lex_file);
                    fputs(is_token,lex_file);
                    fputs("),",lex_file);
                }
                else if(isFileHandlingFunc(is_token)==1)
                {
                    fputs("fileHandlingFunction(",lex_file);
                    fputs(is_token,lex_file);
                    fputs("),",lex_file);
                }
                else if(strcmp(is_token,"div")==0 || strcmp(is_token,"mod")==0)
                {
                    fputs("arithmeticOperation(",lex_file);
                    fputs(is_token,lex_file);
                    fputs("),",lex_file);
                }
                else
                {
                    fputs("variable(",lex_file);
                    fputs(is_token,lex_file);
                    fputs("),",lex_file);
                }
                i=0;
                for(j=0;j<40;j++)
                    is_token[j]=0;
            }

            if(current_char==':')
            {
                current_char=getc(pascal_file);
                if(current_char=='=')
                {
                    fputs("assignmentOperator(:=),",lex_file);
                    is_assignment=1;
                }
                else
                {
                    fputs("colon(:),",lex_file);
                    ungetc(current_char,pascal_file);
                }
            }


            if(current_char=='{')
            {
                comment(pascal_file,current_char,lex_file);
            }


            if(current_char=='*' && is_comment==1)
            {
                comment(pascal_file,current_char,lex_file);
                is_comment=0;
            }
            if(is_comment==1)
            {
                fputs("leftParentheses((),",lex_file);
            }
            if(current_char==')')
            {
                fputs("rightParentheses()),",lex_file);
            }
            if(current_char==';')
            {
                fputs("endOfLine(;),",lex_file);
            }
            if(current_char=='[')
            {
                fputs("openingBracket([)",lex_file);
            }
            if(current_char==']')
            {
                fputs("closingBracket(])",lex_file);
            }



           if(is_assignment==0 && (current_char=='<' || current_char=='>' || current_char=='='))
            {
                before_current_char=current_char;
                current_char=getc(pascal_file);
                if(before_current_char=='<' && (current_char=='=' || current_char=='>'))
                {
                    fputs("compOperator(",lex_file);
                    fputc(before_current_char,lex_file);
                    fputc(current_char,lex_file);
                    fputs("),",lex_file);
                }
                else if(before_current_char=='>' && current_char=='=')
                {
                    fputs("compOperator(",lex_file);
                    fputc(before_current_char,lex_file);
                    fputc(current_char,lex_file);
                    fputs("),",lex_file);
                }
                else if(before_current_char=='<' || before_current_char=='>' || before_current_char=='=')
                {
                    fputs("compOperator(",lex_file);
                    fputc(before_current_char,lex_file);
                    fputs("),",lex_file);
                    ungetc(current_char,pascal_file);
                }

            }
            is_assignment=0;




            if(current_char=='+' || current_char =='-' || current_char=='*' || current_char=='/')
            {
                fputs("arithOperator(",lex_file);
                fputc(current_char,lex_file);
                fputs("),",lex_file);
            }

            is_comment=0;
            if(current_char=='(')
            {
                is_comment=1;
            }
            if(current_char==39)
            {
                skip_string(pascal_file,lex_file);
            }

            if(current_char==9 || current_char==10 || current_char==' ')
            {
                fputc(current_char,lex_file);
            }
            /*if(current_char==';')
            {

                i=0;
                for(j=0;j<40;j++)
                    is_token[j]='\0';
            }*/
            if(isNumeric(current_char)==1)
            {
                constant(pascal_file,lex_file,current_char);
            }

        }
        fclose(lex_file);
        lex_file = fopen(file_name2,"r");
        current_char=getc(lex_file);
        while(!feof(lex_file))
        {
            printf("%c",current_char);
            current_char=getc(lex_file);
        }
    }

    return 0;
}
예제 #2
0
int cli_RNetShareEnum(struct cli_state *cli, void (*fn)(const char *, uint32_t, const char *, void *), void *state)
{
	char *rparam = NULL;
	char *rdata = NULL;
	char *p;
	unsigned int rdrcnt,rprcnt;
	char param[1024];
	int count = -1;

	/* now send a SMBtrans command with api RNetShareEnum */
	p = param;
	SSVAL(p,0,0); /* api number */
	p += 2;
	strlcpy(p,"WrLeh",sizeof(param)-PTR_DIFF(p,param));
	p = skip_string(param,sizeof(param),p);
	strlcpy(p,"B13BWz",sizeof(param)-PTR_DIFF(p,param));
	p = skip_string(param,sizeof(param),p);
	SSVAL(p,0,1);
	/*
	 * Win2k needs a *smaller* buffer than 0xFFFF here -
	 * it returns "out of server memory" with 0xFFFF !!! JRA.
	 */
	SSVAL(p,2,0xFFE0);
	p += 4;

	if (cli_api(cli,
		    param, PTR_DIFF(p,param), 1024,  /* Param, length, maxlen */
		    NULL, 0, 0xFFE0,            /* data, length, maxlen - Win2k needs a small buffer here too ! */
		    &rparam, &rprcnt,                /* return params, length */
		    &rdata, &rdrcnt))                /* return data, length */
		{
			int res = rparam? SVAL(rparam,0) : -1;

			if (res == 0 || res == ERRmoredata) {
				int converter=SVAL(rparam,2);
				int i;
				char *rdata_end = rdata + rdrcnt;

				count=SVAL(rparam,4);
				p = rdata;

				for (i=0;i<count;i++,p+=20) {
					char *sname;
					int type;
					int comment_offset;
					const char *cmnt;
					const char *p1;
					char *s1, *s2;
					size_t len;
					TALLOC_CTX *frame = talloc_stackframe();

					if (p + 20 > rdata_end) {
						TALLOC_FREE(frame);
						break;
					}

					sname = p;
					type = SVAL(p,14);
					comment_offset = (IVAL(p,16) & 0xFFFF) - converter;
					if (comment_offset < 0 ||
							comment_offset > (int)rdrcnt) {
						TALLOC_FREE(frame);
						break;
					}
					cmnt = comment_offset?(rdata+comment_offset):"";

					/* Work out the comment length. */
					for (p1 = cmnt, len = 0; *p1 &&
							p1 < rdata_end; len++)
						p1++;
					if (!*p1) {
						len++;
					}
					pull_string_talloc(frame,rdata,0,
						&s1,sname,14,STR_ASCII);
					pull_string_talloc(frame,rdata,0,
						&s2,cmnt,len,STR_ASCII);
					if (!s1 || !s2) {
						TALLOC_FREE(frame);
						continue;
					}

					fn(s1, type, s2, state);

					TALLOC_FREE(frame);
				}
			} else {
				DEBUG(4,("NetShareEnum res=%d\n", res));
			}
		} else {
			DEBUG(4,("NetShareEnum failed\n"));
		}

	SAFE_FREE(rparam);
	SAFE_FREE(rdata);

	return count;
}
예제 #3
0
bool cli_oem_change_password(struct cli_state *cli, const char *user, const char *new_password,
                             const char *old_password)
{
	char param[1024];
	unsigned char data[532];
	char *p = param;
	unsigned char old_pw_hash[16];
	unsigned char new_pw_hash[16];
	unsigned int data_len;
	unsigned int param_len = 0;
	char *rparam = NULL;
	char *rdata = NULL;
	unsigned int rprcnt, rdrcnt;

	if (strlen(user) >= sizeof(fstring)-1) {
		DEBUG(0,("cli_oem_change_password: user name %s is too long.\n", user));
		return False;
	}

	SSVAL(p,0,214); /* SamOEMChangePassword command. */
	p += 2;
	strlcpy(p, "zsT", sizeof(param)-PTR_DIFF(p,param));
	p = skip_string(param,sizeof(param),p);
	strlcpy(p, "B516B16", sizeof(param)-PTR_DIFF(p,param));
	p = skip_string(param,sizeof(param),p);
	strlcpy(p,user, sizeof(param)-PTR_DIFF(p,param));
	p = skip_string(param,sizeof(param),p);
	SSVAL(p,0,532);
	p += 2;

	param_len = PTR_DIFF(p,param);

	/*
	 * Get the Lanman hash of the old password, we
	 * use this as the key to make_oem_passwd_hash().
	 */
	E_deshash(old_password, old_pw_hash);

	encode_pw_buffer(data, new_password, STR_ASCII);

#ifdef DEBUG_PASSWORD
	DEBUG(100,("make_oem_passwd_hash\n"));
	dump_data(100, data, 516);
#endif
	arcfour_crypt( (unsigned char *)data, (unsigned char *)old_pw_hash, 516);

	/*
	 * Now place the old password hash in the data.
	 */
	E_deshash(new_password, new_pw_hash);

	E_old_pw_hash( new_pw_hash, old_pw_hash, (uchar *)&data[516]);

	data_len = 532;

	if (!cli_api(cli,
		     param, param_len, 4,		/* param, length, max */
		     (char *)data, data_len, 0,		/* data, length, max */
		     &rparam, &rprcnt,
		     &rdata, &rdrcnt)) {
		DEBUG(0,("cli_oem_change_password: Failed to send password change for user %s\n",
			user ));
		return False;
	}

	if (rparam) {
		cli->rap_error = SVAL(rparam,0);
	}

	SAFE_FREE(rparam);
	SAFE_FREE(rdata);

	return (cli->rap_error == 0);
}
예제 #4
0
파일: sign.c 프로젝트: SylvestreG/bitrig
static int
embed_signature(struct key *key, FILE *fin, FILE *fout)
{
	struct gzip_header gh;
	struct gzip_xfield *gx;
	struct gzsig_data *gd;
	u_char *sig, digest[20], buf[8192];
	SHA_CTX ctx;
	int i, siglen;
	long offset;

	/* Read gzip header. */
	if (fread((u_char *)&gh, 1, sizeof(gh), fin) != sizeof(gh)) {
		fprintf(stderr, "Error reading gzip header: %s\n",
		    strerror(errno));
		return (-1);
	}
	/* Verify gzip header. */
	if (memcmp(gh.magic, GZIP_MAGIC, sizeof(gh.magic)) != 0) {
		fprintf(stderr, "Invalid gzip file\n");
		return (-1);
	}
	if (gh.flags & GZIP_FCONT) {
		fprintf(stderr, "Multi-part gzip files not supported\n");
		return (-1);
	}
	/* Skip over any existing signature. */
	if (gh.flags & GZIP_FEXTRA) {
		gx = (struct gzip_xfield *)buf;
		gd = (struct gzsig_data *)(gx + 1);

		if (fread((u_char *)gx, 1, sizeof(*gx), fin) != sizeof(*gx)) {
			fprintf(stderr, "Error reading extra field: %s\n",
			    strerror(errno));
			return (-1);
		}
		if (memcmp(gx->subfield.id, GZSIG_ID, 2) != 0) {
			fprintf(stderr, "Unknown extra field\n");
			return (-1);
		}
		gx->subfield.len = letoh16(gx->subfield.len);
		
		if (gx->subfield.len < sizeof(*gd) ||
		    gx->subfield.len > sizeof(buf) - sizeof(*gx)) {
			fprintf(stderr, "Invalid signature length\n");
			return (-1);
		}
		if (fread((u_char *)gd, 1, gx->subfield.len, fin) !=
		    gx->subfield.len) {
			fprintf(stderr, "Error reading signature: %s\n",
			    strerror(errno));
			return (-1);
		}
		fprintf(stderr, "Overwriting existing signature\n");
	}
	/* Skip over any options. */
	offset = ftell(fin);

	if (gh.flags & GZIP_FNAME) {
		if (skip_string(fin))
			return (-1);
	}
	if (gh.flags & GZIP_FCOMMENT) {
		if (skip_string(fin))
			return (-1);
	}
	if (gh.flags & GZIP_FENCRYPT) {
		if (fread(buf, 1, GZIP_FENCRYPT_LEN, fin) != GZIP_FENCRYPT_LEN)
			return (-1);
	}
	/* Compute checksum over compressed data and trailer. */
	SHA1_Init(&ctx);
	
	while ((i = fread(buf, 1, sizeof(buf), fin)) > 0) {
		SHA1_Update(&ctx, buf, i);
	}
	SHA1_Final(digest, &ctx);
	
	/* Generate signature. */
	gx = (struct gzip_xfield *)buf;
	gd = (struct gzsig_data *)(gx + 1);
	sig = (u_char *)(gd + 1);
	
	siglen = key_sign(key, digest, sizeof(digest), sig,
	    sizeof(buf) - (sig - buf));
	
	if (siglen < 0) {
		fprintf(stderr, "Error signing checksum\n");
		return (-1);
	}
	i = sizeof(*gd) + siglen;
	gx->subfield.len = htole16(i);
	gx->len = htole16(sizeof(gx->subfield) + i);
	memcpy(gx->subfield.id, GZSIG_ID, sizeof(gx->subfield.id));
	gd->version = GZSIG_VERSION;
	
	/* Write out gzip header. */
	gh.flags |= GZIP_FEXTRA;

	if (fwrite((u_char *)&gh, 1, sizeof(gh), fout) != sizeof(gh)) {
		fprintf(stderr, "Error writing output: %s\n", strerror(errno));
		return (-1);
	}
	/* Write out signature. */
	if (fwrite(buf, 1, sizeof(*gx) + i, fout) != sizeof(*gx) + i) {
		fprintf(stderr, "Error writing output: %s\n", strerror(errno));
		return (-1);
	}
	/* Write out options, compressed data, and trailer. */
	if (fseek(fin, offset, SEEK_SET) < 0) {
		fprintf(stderr, "Error writing output: %s\n", strerror(errno));
		return (-1);
	}
	while ((i = fread(buf, 1, sizeof(buf), fin)) > 0) {		
		if (fwrite(buf, 1, i, fout) != i) {
			fprintf(stderr, "Error writing output: %s\n",
			    strerror(errno));
			return (-1);
		}
	}
	if (ferror(fin)) {
		fprintf(stderr, "Error reading input: %s\n", strerror(errno));
		return (-1);
	}
	return (0);
}
예제 #5
0
파일: t_vobj.c 프로젝트: deplinenoise/vlink
static void read_section(struct GlobalVars *gv,struct ObjectUnit *u,
                         uint32_t index,struct vobj_symbol *vsyms,int nsyms)
{
  struct Section *s;
  lword dsize,fsize;
  int nrelocs;
  uint8_t type = ST_DATA;
  uint8_t prot = SP_READ;
  uint8_t flags = 0;
  uint8_t align,*data;
  char *attr;
  char *name = p;
  struct Reloc *last_reloc;
  int last_sym = -1;
  lword last_offs;
  uint16_t last_bpos = INVALID;

  skip_string();  /* section name */
  for (attr=p; *attr; attr++) {
    switch (tolower((unsigned char)*attr)) {
      case 'w': prot |= SP_WRITE; break;
      case 'x': prot |= SP_EXEC; break;
      case 'c': type = ST_CODE; break;
      case 'd': type = ST_DATA; break;
      case 'u': type = ST_UDATA; flags |= SF_UNINITIALIZED; break;
      case 'a': flags |= SF_ALLOC;
    }
  }
  skip_string();
  read_number();                  /* ignore flags */
  align = (uint8_t)lshiftcnt(read_number());
  dsize = read_number();          /* total size of section */
  nrelocs = (int)read_number();   /* number of relocation entries */
  fsize = read_number();          /* size in file, without 0-bytes */

  if (type == ST_UDATA) {
    data = NULL;
  }
  else if (dsize > fsize) {       /* recreate 0-bytes at end of section */
    data = alloczero((size_t)dsize);
    memcpy(data,p,(size_t)fsize);
  }
  else
    data = p;

  /* create and add section */
  p += fsize;
  s = add_section(u,name,data,(unsigned long)dsize,type,flags,prot,align,0);
  s->id = index;

  /* create relocations and unkown symbol references for this section */
  for (last_reloc=NULL,last_offs=-1; nrelocs>0; nrelocs--) {
    struct Reloc *r;
    char *xrefname = NULL;
    lword offs,mask,addend;
    uint16_t bpos,bsiz;
    uint8_t flags;
    int sym_idx;

    /* read one relocation entry */
    type = (uint8_t)read_number();
    offs = read_number();
    bpos = (uint16_t)read_number();
    bsiz = (uint16_t)read_number();
    mask = read_number();
    addend = read_number();
    sym_idx = (int)read_number() - 1;  /* symbol index */
    flags = 0;

    if (type>R_NONE && type<=LAST_STANDARD_RELOC &&
        offs>=0 && bsiz<=(sizeof(lword)<<3) &&
        sym_idx>=0 && sym_idx<nsyms) {
      if (vsyms[sym_idx].type == LABSYM) {
        xrefname = NULL;
        index = vsyms[sym_idx].sec;
      }
      else if (vsyms[sym_idx].type == IMPORT) {
        xrefname = vsyms[sym_idx].name;
        if (vsyms[sym_idx].flags & WEAK)
          flags |= RELF_WEAK;  /* undefined weak symbol */
        index = 0;
      }
      else {
        /* VOBJ relocation not supported */
        error(115,getobjname(u),fff[u->lnkfile->format]->tname,
              (int)type,(lword)offs,(int)bpos,(int)bsiz,(lword)mask,
              vsyms[sym_idx].name,(int)vsyms[sym_idx].type);
      }

      if (sym_idx==last_sym && offs==last_offs && bpos==last_bpos &&
          last_reloc!=NULL) {
        r = last_reloc;
      }
      else {
        r = newreloc(gv,s,xrefname,NULL,index,(unsigned long)offs,type,addend);
        r->flags |= flags;
        last_reloc = r;
        last_offs = offs;
        last_bpos = bpos;
        last_sym = sym_idx;
      }

      addreloc(s,r,bpos,bsiz,mask);

      /* make sure that section reflects the addend for other formats */
      writesection(gv,data+(uint32_t)offs,r,addend);
    }

    else if (type != R_NONE) {
      /* VOBJ relocation not supported */
      error(115,getobjname(u),fff[u->lnkfile->format]->tname,
            (int)type,(lword)offs,(int)bpos,(int)bsiz,(lword)mask,
            (sym_idx>=0&&sym_idx<nsyms) ? vsyms[sym_idx].name : "?",
            (sym_idx>=0&&sym_idx<nsyms) ? (int)vsyms[sym_idx].type : 0);
    }
  }
}
예제 #6
0
/****************************************************************************
call a NetServerEnum for the specified workgroup and servertype mask.  This
function then calls the specified callback function for each name returned.

The callback function takes 4 arguments: the machine name, the server type,
the comment and a state pointer.
****************************************************************************/
BOOL cli_NetServerEnum(struct cli_state *cli, char *workgroup, uint32 stype,
		       void (*fn)(const char *, uint32, const char *, void *),
		       void *state)
{
	char *rparam = NULL;
	char *rdata = NULL;
	unsigned int rdrcnt,rprcnt;
	char *p;
	pstring param;
	int uLevel = 1;
	int count = -1;

	errno = 0; /* reset */

	/* send a SMBtrans command with api NetServerEnum */
	p = param;
	SSVAL(p,0,0x68); /* api number */
	p += 2;
	pstrcpy_base(p,"WrLehDz", param);
	p = skip_string(p,1);
  
	pstrcpy_base(p,"B16BBDz", param);

	p = skip_string(p,1);
	SSVAL(p,0,uLevel);
	SSVAL(p,2,CLI_BUFFER_SIZE);
	p += 4;
	SIVAL(p,0,stype);
	p += 4;

	p += push_ascii(p, workgroup, sizeof(pstring)-PTR_DIFF(p,param)-1, STR_TERMINATE|STR_UPPER);
	
	if (cli_api(cli, 
                    param, PTR_DIFF(p,param), 8,        /* params, length, max */
                    NULL, 0, CLI_BUFFER_SIZE,               /* data, length, max */
                    &rparam, &rprcnt,                   /* return params, return size */
                    &rdata, &rdrcnt                     /* return data, return size */
                   )) {
		int res = rparam? SVAL(rparam,0) : -1;
			
		if (res == 0 || res == ERRmoredata) {
			int i;
			int converter=SVAL(rparam,2);

			count=SVAL(rparam,4);
			p = rdata;
					
			for (i = 0;i < count;i++, p += 26) {
				char *sname = p;
				int comment_offset = (IVAL(p,22) & 0xFFFF)-converter;
				const char *cmnt = comment_offset?(rdata+comment_offset):"";
				pstring s1, s2;

				if (comment_offset < 0 || comment_offset > (int)rdrcnt) continue;

				stype = IVAL(p,18) & ~SV_TYPE_LOCAL_LIST_ONLY;

				pull_ascii_pstring(s1, sname);
				pull_ascii_pstring(s2, cmnt);
				fn(s1, stype, s2, state);
			}
		}
	}
  
	SAFE_FREE(rparam);
	SAFE_FREE(rdata);

	if (count < 0) {
	    errno = cli_errno(cli);
	} else {
	    if (!count) {
		/* this is a very special case, when the domain master for the 
		   work group isn't part of the work group itself, there is something
		   wild going on */
		errno = ENOENT;
	    }
	}
			
	return(count > 0);
}
예제 #7
0
파일: clirap.c 프로젝트: aosm/samba
BOOL cli_oem_change_password(struct cli_state *cli, const char *user, const char *new_password,
                             const char *old_password)
{
	pstring param;
	unsigned char data[532];
	char *p = param;
	unsigned char old_pw_hash[16];
	unsigned char new_pw_hash[16];
	unsigned int data_len;
	unsigned int param_len = 0;
	char *rparam = NULL;
	char *rdata = NULL;
	unsigned int rprcnt, rdrcnt;

	if (strlen(user) >= sizeof(fstring)-1) {
		DEBUG(0,("cli_oem_change_password: user name %s is too long.\n", user));
		return False;
	}

	SSVAL(p,0,214); /* SamOEMChangePassword command. */
	p += 2;
	pstrcpy_base(p, "zsT", param);
	p = skip_string(param,sizeof(param),p);
	pstrcpy_base(p, "B516B16", param);
	p = skip_string(param,sizeof(param),p);
	pstrcpy_base(p,user, param);
	p = skip_string(param,sizeof(param),p);
	SSVAL(p,0,532);
	p += 2;

	param_len = PTR_DIFF(p,param);

	/*
	 * Get the Lanman hash of the old password, we
	 * use this as the key to make_oem_passwd_hash().
	 */
	E_deshash(old_password, old_pw_hash);

	encode_pw_buffer(data, new_password, STR_ASCII);
  
#ifdef DEBUG_PASSWORD
	DEBUG(100,("make_oem_passwd_hash\n"));
	dump_data(100, (char *)data, 516);
#endif
	SamOEMhash( (unsigned char *)data, (unsigned char *)old_pw_hash, 516);

	/* 
	 * Now place the old password hash in the data.
	 */
	E_deshash(new_password, new_pw_hash);

	E_old_pw_hash( new_pw_hash, old_pw_hash, (uchar *)&data[516]);

	data_len = 532;
    
	if (cli_send_trans(cli,SMBtrans,
                    PIPE_LANMAN,                          /* name */
                    0,0,                                  /* fid, flags */
                    NULL,0,0,                             /* setup, length, max */
                    param,param_len,2,                    /* param, length, max */
                    (char *)data,data_len,0                       /* data, length, max */
                   ) == False) {
		DEBUG(0,("cli_oem_change_password: Failed to send password change for user %s\n",
			user ));
		return False;
	}

	if (!cli_receive_trans(cli,SMBtrans,
                       &rparam, &rprcnt,
                       &rdata, &rdrcnt)) {
		DEBUG(0,("cli_oem_change_password: Failed to recieve reply to password change for user %s\n",
			user ));
		return False;
	}
  
	if (rparam) {
		cli->rap_error = SVAL(rparam,0);
	}
  
	SAFE_FREE(rparam);
	SAFE_FREE(rdata);

	return (cli->rap_error == 0);
}
예제 #8
0
파일: parser.c 프로젝트: abderrahim/anjuta
static IAnjutaDebuggerDataType
get_type (gchar **buf)
{
	gchar *pos;
	
	if (!*buf || !*(*buf = skip_next_token_start (*buf)))
		return IANJUTA_DEBUGGER_UNKNOWN_TYPE;

	// A reference, probably from a parameter value.
	if (**buf == '@')
		return IANJUTA_DEBUGGER_REFERENCE_TYPE;

	// Structures and arrays - (but which one is which?)
	// {void (void)} 0x804a944 <__builtin_new+41> - this is a fn pointer
	// (void (*)(void)) 0x804a944 <f(E *, char)> - so is this - ugly!!!
	if (**buf == '{')
	{
		(*buf)++;
		if (**buf ==  '{')
			return IANJUTA_DEBUGGER_ARRAY_TYPE;

		if (strncmp (*buf, "<No data fields>}", 17) == 0)
		{
			(*buf) += 17;
			return IANJUTA_DEBUGGER_VALUE_TYPE;
		}

		pos = *buf;
		while (*pos)
		{
			switch (*pos)
			{
			case '=':
				return IANJUTA_DEBUGGER_STRUCT_TYPE;
			case '"':
				pos = skip_string (pos);
				break;
			case '\'':
				pos = skip_quotes (pos, '\'');
				break;
			case ',':
				if (*(pos - 1) == '}')
				{
					g_warning ("??????\n");
				}
				return IANJUTA_DEBUGGER_ARRAY_TYPE;
			case '}':
				if (*(pos + 1) == ',' || *(pos + 1) == '\n' || !*(pos + 1))
					return IANJUTA_DEBUGGER_ARRAY_TYPE;			 // Hmm a single element
												 // array??
				if (strncmp (pos + 1, " 0x", 3) == 0)
					return IANJUTA_DEBUGGER_POINTER_TYPE;		 // What about references?
				return IANJUTA_DEBUGGER_UNKNOWN_TYPE;			 // very odd?
			case '(':
				pos = skip_delim (pos, '(', ')');
				break;
			case '<':
				pos = skip_delim (pos, '<', '>');
				break;
			default:
				pos++;
				break;
			}
		}
		return IANJUTA_DEBUGGER_UNKNOWN_TYPE;
	}

	// some sort of address. We need to sort out if we have
	// a 0x888888 "this is a char*" type which we'll term a value
	// or whether we just have an address
	if (strncmp (*buf, "0x", 2) == 0)
	{
		pos = *buf;
		while (*pos)
		{
			if (!isspace (*pos))
				pos++;
			else if (*(pos + 1) == '\"')
				return IANJUTA_DEBUGGER_VALUE_TYPE;
			else
				break;
		}
		return IANJUTA_DEBUGGER_POINTER_TYPE;
	}

	// Pointers and references - references are a bit odd
	// and cause GDB to fail to produce all the local data
	// if they haven't been initialised. but that's not our problem!!
	// (void (*)(void)) 0x804a944 <f(E *, char)> - this is a fn pointer
	if (**buf == '(')
	{
		pos = *buf;
		pos = skip_delim (pos, '(', ')');
		pos -= 2;
		switch (*pos)
		{
		case ')':
		case '*':
			return IANJUTA_DEBUGGER_POINTER_TYPE;
		case '&':
			return IANJUTA_DEBUGGER_REFERENCE_TYPE;
		default:
			/* fix (char * const) - case */
			while(*pos && (isalpha(*pos) || *pos == ' ')) --pos;
			switch(*pos)
			{
			  case '*':	return IANJUTA_DEBUGGER_POINTER_TYPE;
			  case '&':	return IANJUTA_DEBUGGER_REFERENCE_TYPE;
			  default:	return IANJUTA_DEBUGGER_UNKNOWN_TYPE;
			}
		}
	}

	pos = skip_token_value (*buf);
	if ((strncmp (pos, " = ", 3) == 0) || (*pos == '='))
		return IANJUTA_DEBUGGER_NAME_TYPE;

	return IANJUTA_DEBUGGER_VALUE_TYPE;
}
예제 #9
0
         
	if(!AM_LOCAL_MASTER_BROWSER(work)) {
		DEBUG(5,("browse_sync_remote: We can only do this if we are a local master browser \
for workgroup %s on subnet %s.\n", lp_workgroup(), FIRST_SUBNET->subnet_name ));
		return;
	} 

	memset(outbuf,'\0',sizeof(outbuf));
	p = outbuf;
	SCVAL(p,0,ANN_MasterAnnouncement);
	p++;

	unstrcpy(myname, global_myname());
	strupper_m(myname);
	myname[15]='\0';
	push_pstring_base(p, myname, outbuf);

	p = skip_string(outbuf,sizeof(outbuf),p);

	for (ptr=s; next_token(&ptr,s2,NULL,sizeof(s2)); ) {
		/* The entries are of the form a.b.c.d */
		addr = *interpret_addr2(s2);

		DEBUG(5,("announce_remote: Doing remote browse sync announce for server %s to IP %s.\n",
			global_myname(), inet_ntoa(addr) ));

		send_mailslot(True, BROWSE_MAILSLOT, outbuf,PTR_DIFF(p,outbuf),
			global_myname(), 0x0, "*", 0x0, addr, FIRST_SUBNET->myip, DGRAM_PORT);
	}
}
예제 #10
0
파일: syntax.c 프로젝트: kusma/vasm
static void handle_print(char *s)
{
  while (!ISEOL(s)) {
    if (*s == '\"') {
      size_t len;
      char *txt;

      skip_string(s,'\"',&len);
      if (len > 0) {
        txt = mymalloc(len+1);
        s = read_string(txt,s,'\"',8);
        txt[len] = '\0';
        add_atom(0,new_text_atom(txt));
      }
    }
    else {
      int type = PEXP_HEX;
      int size = 16;

      while (*s == '/') {
        /* format character */
        char f;

        s = skip(s+1);
        f = tolower((unsigned char)*s);
        if (s = skip_identifier(s)) {
          switch (f) {
            case 'x':
              type = PEXP_HEX;
              break;
            case 'd':
              type = PEXP_SDEC;
              break;
            case 'u':
              type = PEXP_UDEC;
              break;
            case 'w':
              size = 16;
              break;
            case 'l':
              size = 32;
              break;
            default:
              syntax_error(7,f);  /* unknown print format flag */
              break;
          }
        }
        else {
          syntax_error(9);  /* print format corrupted */
          break;
        }
        s = skip(s);
      }
      add_atom(0,new_expr_atom(parse_expr(&s),type,size));
    }
    s = skip(s);
    if (*s != ',')
      break;
    s = skip(s+1);
  }
  add_atom(0,new_text_atom(NULL));  /* new line */
  eol(s);
}
예제 #11
0
static gboolean
read_gzip_header (GInputStream *is,
                  time_t *modification_time)
{
	guchar buffer[GZIP_HEADER_SIZE];
	gssize bytes, to_skip;
	guint mode;
	guint flags;

	bytes = g_input_stream_read (is, buffer, GZIP_HEADER_SIZE,
                               NULL, NULL);
  if (bytes == -1) {
    return FALSE;
  }

	if (bytes != GZIP_HEADER_SIZE)
		return FALSE;

	if (buffer[0] != GZIP_MAGIC_1 || buffer[1] != GZIP_MAGIC_2)
		return FALSE;

	mode = buffer[2];
	if (mode != 8) /* Mode: deflate */
		return FALSE;

	flags = buffer[3];

	if (flags & GZIP_FLAG_RESERVED)
		return FALSE;

	if (flags & GZIP_FLAG_EXTRA_FIELD) {
		guchar tmp[2];

    bytes = g_input_stream_read (is, tmp, 2, NULL, NULL);
  
    if (bytes != 2) {
			return FALSE;
    }

    to_skip = tmp[0] | (tmp[0] << 8);
    bytes = g_input_stream_skip (is, to_skip, NULL, NULL);
    if (bytes != to_skip) {
      return FALSE;
    }
	}

	if (flags & GZIP_FLAG_ORIG_NAME) {
    if (!skip_string (is)) {
      return FALSE;
    }
  }

	if (flags & GZIP_FLAG_COMMENT) {
    if (!skip_string (is)) {
      return FALSE;
    }
  }

	if (flags & GZIP_FLAG_HEAD_CRC) {
    bytes = g_input_stream_skip (is, 2, NULL, NULL);
		if (bytes != 2) {
      return FALSE;
    }
  }

  *modification_time = (buffer[4] | (buffer[5] << 8)
                        | (buffer[6] << 16) | (buffer[7] << 24));

	return TRUE;
}
예제 #12
0
void JsonIn::skip_member()
{
    skip_string();
    skip_pair_separator();
    skip_value();
}
예제 #13
0
/*
 * c_entries --
 *	read .c and .h files and call appropriate routines
 */
void
c_entries(void)
{
	int	c;			/* current character */
	int	level;			/* brace level */
	int	token;			/* if reading a token */
	int	t_def;			/* if reading a typedef */
	int	t_level;		/* typedef's brace level */
	char	*sp;			/* buffer pointer */
	char	tok[MAXTOKEN];		/* token buffer */

	lineftell = ftell(inf);
	sp = tok; token = t_def = NO; t_level = -1; level = 0; lineno = 1;
	while (GETC(!=, EOF)) {
		switch (c) {
		/*
		 * Here's where it DOESN'T handle: {
		 *	foo(a)
		 *	{
		 *	#ifdef notdef
		 *		}
		 *	#endif
		 *		if (a)
		 *			puts("hello, world");
		 *	}
		 */
		case '{':
			++level;
			goto endtok;
		case '}':
			/*
			 * if level goes below zero, try and fix
			 * it, even though we've already messed up
			 */
			if (--level < 0)
				level = 0;
			goto endtok;

		case '\n':
			SETLINE;
			/*
			 * the above 3 cases are similar in that they
			 * are special characters that also end tokens.
			 */
	endtok:			if (sp > tok) {
				*sp = EOS;
				token = YES;
				sp = tok;
			}
			else
				token = NO;
			continue;

		/*
		 * We ignore quoted strings and character constants
		 * completely.
		 */
		case '"':
		case '\'':
			skip_string(c);
			break;

		/*
		 * comments can be fun; note the state is unchanged after
		 * return, in case we found:
		 *	"foo() XX comment XX { int bar; }"
		 */
		case '/':
			if (GETC(==, '*') || c == '/') {
				skip_comment(c);
				continue;
			}
			(void)ungetc(c, inf);
			c = '/';
			goto storec;

		/* hash marks flag #define's. */
		case '#':
			if (sp == tok) {
				hash_entry();
				break;
			}
			goto storec;

		/*
		 * if we have a current token, parenthesis on
		 * level zero indicates a function.
		 */
		case '(':
			if (!level && token) {
				int	curline;

				if (sp != tok)
					*sp = EOS;
				/*
				 * grab the line immediately, we may
				 * already be wrong, for example,
				 *	foo\n
				 *	(arg1,
				 */
				getline();
				curline = lineno;
				if (func_entry()) {
					++level;
					pfnote(tok, curline);
				}
				break;
			}
			goto storec;

		/*
		 * semi-colons indicate the end of a typedef; if we find a
		 * typedef we search for the next semi-colon of the same
		 * level as the typedef.  Ignoring "structs", they are
		 * tricky, since you can find:
		 *
		 *	"typedef long time_t;"
		 *	"typedef unsigned int u_int;"
		 *	"typedef unsigned int u_int [10];"
		 *
		 * If looking at a typedef, we save a copy of the last token
		 * found.  Then, when we find the ';' we take the current
		 * token if it starts with a valid token name, else we take
		 * the one we saved.  There's probably some reasonable
		 * alternative to this...
		 */
		case ';':
			if (t_def && level == t_level) {
				t_def = NO;
				getline();
				if (sp != tok)
					*sp = EOS;
				pfnote(tok, lineno);
				break;
			}
			goto storec;

		/*
		 * store characters until one that can't be part of a token
		 * comes along; check the current token against certain
		 * reserved words.
		 */
		default:
			/* ignore whitespace */
			if (c == ' ' || c == '\t') {
				int save = c;
				while (GETC(!=, EOF) && (c == ' ' || c == '\t'))
					;
				if (c == EOF)
					return;
				(void)ungetc(c, inf);
				c = save;
			}
	storec:		if (!intoken(c)) {
				if (sp == tok)
					break;
				*sp = EOS;
				if (tflag) {
					/* no typedefs inside typedefs */
					if (!t_def &&
						   !memcmp(tok, "typedef",8)) {
						t_def = YES;
						t_level = level;
						break;
					}
					/* catch "typedef struct" */
					if ((!t_def || t_level < level)
					    && (!memcmp(tok, "struct", 7)
					    || !memcmp(tok, "union", 6)
					    || !memcmp(tok, "enum", 5))) {
						/*
						 * get line immediately;
						 * may change before '{'
						 */
						getline();
						if (str_entry(c))
							++level;
						break;
						/* } */
					}
				}
				sp = tok;
			}
			else if (sp != tok || begtoken(c)) {
				if (sp == tok + sizeof tok - 1)
					/* Too long -- truncate it */
					*sp = EOS;
				else 
					*sp++ = c;
				token = YES;
			}
			continue;
		}

		sp = tok;
		token = NO;
	}
예제 #14
0
파일: verify.c 프로젝트: SylvestreG/bitrig
static int
verify_signature(struct key *key, FILE *fin)
{
	struct gzip_header gh;
	struct gzip_xfield *gx;
	struct gzsig_data *gd;
	u_char *sig, digest[20], buf[8192], sbuf[4096];
	SHA_CTX ctx;
	int i, siglen;

	/* Read gzip header. */
	if ((i = fread((u_char *)&gh, 1, sizeof(gh), fin)) != sizeof(gh)) {
		fprintf(stderr, "Error reading gzip header: %s\n",
		    strerror(errno));
		return (-1);
	}
	/* Verify gzip header. */
	if (memcmp(gh.magic, GZIP_MAGIC, sizeof(gh.magic)) != 0) {
		fprintf(stderr, "Invalid gzip file\n");
		return (-1);
	} else if (gh.flags & GZIP_FCONT){
		fprintf(stderr, "Multi-part gzip files not supported\n");
		return (-1);
	} else if ((gh.flags & GZIP_FEXTRA) == 0) {
		fprintf(stderr, "No gzip signature found\n");
		return (-1);
	}
	/* Read signature. */
	gx = (struct gzip_xfield *)buf;
	
	if ((i = fread((u_char *)gx, 1, sizeof(*gx), fin)) != sizeof(*gx)) {
		fprintf(stderr, "Error reading extra field: %s\n",
		    strerror(errno));
		return (-1);
	}
	if (memcmp(gx->subfield.id, GZSIG_ID, sizeof(gx->subfield.id)) != 0) {
		fprintf(stderr, "Unknown extra field\n");
		return (-1);
	}
	gx->subfield.len = letoh16(gx->subfield.len);

	if (gx->subfield.len <= 0 || gx->subfield.len > sizeof(sbuf)) {
		fprintf(stderr, "Invalid signature length\n");
		return (-1);
	}
	gd = (struct gzsig_data *)sbuf;
	
	if ((i = fread((u_char *)gd, 1, gx->subfield.len, fin)) !=
	    gx->subfield.len) {
		fprintf(stderr, "Error reading signature: %s\n",
		    strerror(errno));
		return (-1);
	}
	/* Skip over any options. */
	if (gh.flags & GZIP_FNAME) {
		if (skip_string(fin))
			return (-1);
	}
	if (gh.flags & GZIP_FCOMMENT) {
		if (skip_string(fin))
			return (-1);
	}
	if (gh.flags & GZIP_FENCRYPT &&
	    fread(buf, 1, GZIP_FENCRYPT_LEN, fin) != GZIP_FENCRYPT_LEN)
		return (-1);
	
	/* Check signature version. */
	if (gd->version != GZSIG_VERSION) {
		fprintf(stderr, "Unknown signature version: %d\n",
		    gd->version);
		return (-1);
	}
	/* Compute SHA1 checksum over compressed data and trailer. */
	sig = (u_char *)(gd + 1);
	siglen = gx->subfield.len - sizeof(*gd);

	SHA1_Init(&ctx);
	
	while ((i = fread(buf, 1, sizeof(buf), fin)) > 0) {
		SHA1_Update(&ctx, buf, i);
	}
	SHA1_Final(digest, &ctx);
	
	/* Verify signature. */
	if (key_verify(key, digest, sizeof(digest), sig, siglen) < 0) {
		fprintf(stderr, "Error verifying signature\n");
		return (-1);
	}
	return (0);
}
예제 #15
0
static bool cli_prep_mailslot(bool unique, const char *mailslot,
		       uint16_t priority,
		       char *buf, int len,
		       const char *srcname, int src_type,
		       const char *dstname, int dest_type,
		       const struct sockaddr_storage *dest_ss,
		       int dgm_id,
		       struct packet_struct *p)
{
	struct dgram_packet *dgram = &p->packet.dgram;
	char *ptr, *p2;
	char tmp[4];
	char addr[INET6_ADDRSTRLEN];

	ZERO_STRUCTP(p);

	/*
	 * Next, build the DGRAM ...
	 */

	/* DIRECT GROUP or UNIQUE datagram. */
	dgram->header.msg_type = unique ? 0x10 : 0x11;
	dgram->header.flags.node_type = M_NODE;
	dgram->header.flags.first = True;
	dgram->header.flags.more = False;
	dgram->header.dgm_id = dgm_id;
	/* source ip is filled by nmbd */
	dgram->header.dgm_length = 0; /* Let build_dgram() handle this. */
	dgram->header.packet_offset = 0;

	make_nmb_name(&dgram->source_name,srcname,src_type);
	make_nmb_name(&dgram->dest_name,dstname,dest_type);

	ptr = &dgram->data[0];

	/* Setup the smb part. */
	ptr -= 4; /* XXX Ugliness because of handling of tcp SMB length. */
	memcpy(tmp,ptr,4);

	if (smb_size + 17*2 + strlen(mailslot) + 1 + len > MAX_DGRAM_SIZE) {
		DEBUG(0, ("cli_send_mailslot: Cannot write beyond end of packet\n"));
		return False;
	}

	cli_set_message(ptr,17,strlen(mailslot) + 1 + len,True);
	memcpy(ptr,tmp,4);

	SCVAL(ptr,smb_com,SMBtrans);
	SSVAL(ptr,smb_vwv1,len);
	SSVAL(ptr,smb_vwv11,len);
	SSVAL(ptr,smb_vwv12,70 + strlen(mailslot));
	SSVAL(ptr,smb_vwv13,3);
	SSVAL(ptr,smb_vwv14,1);
	SSVAL(ptr,smb_vwv15,priority);
	SSVAL(ptr,smb_vwv16,2);
	p2 = smb_buf(ptr);
	fstrcpy(p2,mailslot);
	p2 = skip_string(ptr,MAX_DGRAM_SIZE,p2);
	if (!p2) {
		return False;
	}

	memcpy(p2,buf,len);
	p2 += len;

	dgram->datasize = PTR_DIFF(p2,ptr+4); /* +4 for tcp length. */

	p->packet_type = DGRAM_PACKET;
	p->ip = ((const struct sockaddr_in *)dest_ss)->sin_addr;
	p->timestamp = time(NULL);

	DEBUG(4,("send_mailslot: Sending to mailslot %s from %s ",
		 mailslot, nmb_namestr(&dgram->source_name)));
	print_sockaddr(addr, sizeof(addr), dest_ss);

	DEBUGADD(4,("to %s IP %s\n", nmb_namestr(&dgram->dest_name), addr));

	return true;
}
예제 #16
0
Parser::FunctionSigFlags *
Parser::parse_function_sig(void) {
    size_t id = read_uint();

    FunctionSigState *sig = lookup(functions, id);

    if (!sig) {
        /* parse the signature */
        sig = new FunctionSigState;
        sig->id = id;
        sig->name = read_string();
        sig->num_args = read_uint();
        const char **arg_names = new const char *[sig->num_args];
        for (unsigned i = 0; i < sig->num_args; ++i) {
            arg_names[i] = read_string();
        }
        sig->arg_names = arg_names;
        sig->flags = lookupCallFlags(sig->name);
        sig->offset = file->currentOffset();
        functions[id] = sig;

        /**
         * Try to autodetect the API.
         *
         * XXX: Ideally we would allow to mix multiple APIs in a single trace,
         * but as it stands today, retrace is done separately for each API.
         */
        if (api == API_UNKNOWN) {
            const char *n = sig->name;
            if ((n[0] == 'g' && n[1] == 'l' && n[2] == 'X') || // glX*
                (n[0] == 'w' && n[1] == 'g' && n[2] == 'l' && n[3] >= 'A' && n[3] <= 'Z') || // wgl[A-Z]*
                (n[0] == 'C' && n[1] == 'G' && n[2] == 'L')) { // CGL*
                api = trace::API_GL;
            } else if (n[0] == 'e' && n[1] == 'g' && n[2] == 'l' && n[3] >= 'A' && n[3] <= 'Z') { // egl[A-Z]*
                api = trace::API_EGL;
            } else if ((n[0] == 'D' &&
                        ((n[1] == 'i' && n[2] == 'r' && n[3] == 'e' && n[4] == 'c' && n[5] == 't') || // Direct*
                         (n[1] == '3' && n[2] == 'D'))) || // D3D*
                       (n[0] == 'C' && n[1] == 'r' && n[2] == 'e' && n[3] == 'a' && n[4] == 't' && n[5] == 'e')) { // Create*
                api = trace::API_DX;
            } else {
                /* TODO */
            }
        }

        /**
         * Note down the signature of special functions for future reference.
         *
         * NOTE: If the number of comparisons increases we should move this to a
         * separate function and use bisection.
         */
        if (sig->num_args == 0 &&
            strcmp(sig->name, "glGetError") == 0) {
            glGetErrorSig = sig;
        }

    } else if (file->currentOffset() < sig->offset) {
        /* skip over the signature */
        skip_string(); /* name */
        unsigned num_args = read_uint();
        for (unsigned i = 0; i < num_args; ++i) {
             skip_string(); /*arg_name*/
        }
    }

    assert(sig);
    return sig;
}
예제 #17
0
char *
unix2vms_path(char *dst, const char *src)
{
#if !SYS_VMS
    char tmp2[NFILEN];
#endif
    char tmp[NFILEN];
    char leading[NFILEN];
    char *t;
    char *s = strcpy(tmp, src);	/* ... to permit src == dst */
    char *d = dst;
    char c = '?';
    int bracket = FALSE;	/* true when "[" passed. */
    int on_top = FALSE;		/* true when no "[." lead */
    int node = FALSE;		/* true when node found */
    int device = FALSE;		/* true when device found */
    int len;

    /*
     * If VMS 'getenv()' is given an upper-case name, it assumes that it
     * corresponds to a logical device assignment.  As a special case, if
     * we have a leading token of this form, translate it.
     */
    if ((len = leading_uc(leading, s)) != 0) {
	s += len;
	len = strlen(strcpy(d, leading));
	while (len > 1 && d[len - 1] == ' ')
	    len--;
	if (*s) {		/* text follows leading token */
	    s++;		/* skip (assumed) SLASHC */
	    if ((len > 1)
		&& (d[len - 1] == COLON)) {
		on_top = TRUE;
	    } else if (strchr(s, SLASHC)) {	/* must do a splice */
		if ((len > 2)
		    && (d[len - 1] == R_BLOCK)) {
		    bracket++;
		    if (d[len - 2] == PERIOD)
			/* rooted-device ? */
			len -= 2;
		    else
			len--;
		}
	    }
	}
	d[len] = EOS;
	if ((t = strchr(d, COLON)) != NULL) {
	    if (t[1] == COLON) {
		node = TRUE;
		if ((t = strchr(t + 2, COLON)) != NULL)
		    device = TRUE;
	    } else
		device = TRUE;
	}
	d += len;
    } else if (*s == CH_TILDE) {	/* process home-directory reference */
	char *home = getenv("SYS$LOGIN");
#if !SYS_VMS
	if (home == 0)
	    home = unix2vms_path(tmp2, getenv("HOME"));
#endif
	node =
	    device = TRUE;
	s++;

	len = strlen(strcpy(d, home));

	if (d[len - 1] == R_BLOCK) {
	    bracket++;
	    if (strcmp(s, "/")) {	/* strip right-bracket to allow new levels */
		if (d[len - 2] == PERIOD)
		    len--;
		d[len - 1] = PERIOD;
	    } else {
		s++;
		len--;
	    }
	}
	d += len;
    }

    /* look for node-name in VMS-format */
    if (!node
	&& (t = strchr(s, '!')) != 0
	&& (t[1] == SLASHC || t[1] == EOS)) {
	leaf_dot = DotPrefix(s);
	while (s < t)
	    *d++ = CharToVms(*s++);
	*d++ = COLON;
	*d++ = COLON;
	s++;			/* skip over '!' */
    }

    /* look for device-name, indicated by a leading SLASHC */
    if (!device
	&& (*s == SLASHC)) {
	leaf_dot = DotPrefix(++s);
	if ((t = strchr(s, SLASHC)) == 0)
	    t = skip_string(s);
	else if (t[1] == EOS)
	    on_top = TRUE;
	while (s < t)
	    *d++ = CharToVms(*s++);
	if (d != dst)
	    *d++ = COLON;
    }

    /* permit leading "./" to simplify cases in which we concatenate */
    if (!strncmp(s, "./", 2))
	s += 2;

    /* translate repeated leading "../" */
    while (!strncmp(s, "../", 3)) {
	s += 3;
	if (!bracket++)
	    *d++ = L_BLOCK;
	*d++ = '-';
    }
    if (!strcmp(s, "..")) {
	s += 2;
	if (!bracket++)
	    *d++ = L_BLOCK;
	*d++ = '-';
    }

    if (strchr(s, SLASHC)) {
	if (!bracket++)
	    *d++ = L_BLOCK;
	if (*s == SLASHC) {
	    s++;
	} else if (!on_top) {
	    *d++ = PERIOD;
	}
	while ((c = *s++) != EOS) {
	    if (c == PERIOD) {
		c = '$';
		if (*s == SLASHC)	/* ignore "./" */
		    continue;
	    }
	    if (c == SLASHC) {
		leaf_dot = DotPrefix(s);
		if (strchr(s, SLASHC))
		    *d++ = PERIOD;
		else {
		    break;
		}
	    } else {
		*d++ = CharToVms(c);
	    }
	}
    }
    if (bracket) {
	if (on_top && d[-1] == L_BLOCK) {
	    (void) strcpy(d, RootDir);
	    d += strlen(d);
	}
	*d++ = R_BLOCK;
    }
    if (c != EOS && *s) {
	leaf_dot = DotPrefix(s);
	while ((c = *s) != EOS) {
	    if ((leaf_ver = is_version(s)) == TRUE) {
		leaf_dot = TRUE;	/* no longer pertinent */
		(void) strcpy(d, s);
		*d = SEMICOLON;	/* make this unambiguous */
		d += strlen(d);
		break;
	    } else {
		*d++ = CharToVms(c);
	    }
	    s++;
	}
	if (!leaf_dot)
	    *d++ = PERIOD;
	if (!leaf_ver)
	    *d++ = SEMICOLON;
    }
    *d = EOS;
    return mkupper(dst);
}
예제 #18
0
void Parser::scan_string() {
    skip_string();
}
예제 #19
0
파일: clirap.c 프로젝트: aosm/samba
int cli_RNetShareEnum(struct cli_state *cli, void (*fn)(const char *, uint32, const char *, void *), void *state)
{
	char *rparam = NULL;
	char *rdata = NULL;
	char *p;
	unsigned int rdrcnt,rprcnt;
	pstring param;
	int count = -1;

	/* now send a SMBtrans command with api RNetShareEnum */
	p = param;
	SSVAL(p,0,0); /* api number */
	p += 2;
	pstrcpy_base(p,"WrLeh",param);
	p = skip_string(param,sizeof(param),p);
	pstrcpy_base(p,"B13BWz",param);
	p = skip_string(param,sizeof(param),p);
	SSVAL(p,0,1);
	/*
	 * Win2k needs a *smaller* buffer than 0xFFFF here -
	 * it returns "out of server memory" with 0xFFFF !!! JRA.
	 */
	SSVAL(p,2,0xFFE0);
	p += 4;
	
	if (cli_api(cli, 
		    param, PTR_DIFF(p,param), 1024,  /* Param, length, maxlen */
		    NULL, 0, 0xFFE0,            /* data, length, maxlen - Win2k needs a small buffer here too ! */
		    &rparam, &rprcnt,                /* return params, length */
		    &rdata, &rdrcnt))                /* return data, length */
		{
			int res = rparam? SVAL(rparam,0) : -1;
			
			if (res == 0 || res == ERRmoredata) {
				int converter=SVAL(rparam,2);
				int i;
				
				count=SVAL(rparam,4);
				p = rdata;
				
				for (i=0;i<count;i++,p+=20) {
					char *sname = p;
					int type = SVAL(p,14);
					int comment_offset = IVAL(p,16) & 0xFFFF;
					const char *cmnt = comment_offset?(rdata+comment_offset-converter):"";
					pstring s1, s2;

					pull_ascii_pstring(s1, sname);
					pull_ascii_pstring(s2, cmnt);

					fn(s1, type, s2, state);
				}
			} else {
				DEBUG(4,("NetShareEnum res=%d\n", res));
			}      
		} else {
			DEBUG(4,("NetShareEnum failed\n"));
		}
  
	SAFE_FREE(rparam);
	SAFE_FREE(rdata);
	
	return count;
}
예제 #20
0
void dds_dump (DDS_DomainParticipant part)
{
	char		buf [256], cmd [64];
	const char	*sp;

	ARG_NOT_USED (part)

	LIST_INIT (topics);
	LIST_INIT (endpoints);

	tty_init ();
	DDS_Handle_attach (tty_stdin,
			   POLLIN | POLLPRI | POLLERR | POLLHUP | POLLNVAL,
			   tty_input,
			   NULL);

	printf ("Technicolor DDS Dump program.\r\n");
	printf ("Type 'help' for a list ofcommands.\r\n");
	while (!aborting) {
		printf (">");
		fflush (stdout);
		tty_gets (sizeof (buf), buf, 0, 0);
		sp = buf;
		skip_blanks (&sp);
		skip_string (&sp, cmd);
		if (!memcmp (cmd, "help", 1)) {
			printf ("Following commands are available:\r\n");
			printf ("\tlist                  List all discovered domain topics.\r\n");
			printf ("\tauto <name_spec>      Automatically monitor new matching topics.\r\n");
			printf ("\tmonitor <name_spec>   Start monitoring matching topic(s).\r\n");
			printf ("\tignore <name_spec>    Stop monitoring matching topic(s).\r\n");
			printf ("\ttrace                 Toggle tracing of discovery traffic.\r\n");
#ifndef DDS_DEBUG
			printf ("\tpause                 Pause monitoring.\r\n");
			printf ("\tresume                Resume monitoring.\r\n");
			printf ("\tquit                  Quit the program.\r\n");
#else
			DDS_Debug_help ();
#endif
		}
		else if (!memcmp (cmd, "list", 2))
			t_dump ();
		else if (!memcmp (cmd, "auto", 2))
			t_auto (sp);
		else if (!memcmp (cmd, "monitor", 2))
			t_monitor (sp, part);
		else if (!memcmp (cmd, "ignore", 2))
			t_ignore (sp, part);
		else if (!memcmp (cmd, "trace", 2))
			t_trace ();			
#ifndef DDS_DEBUG
		else if (!memcmp (cmd, "pause", 1))
			paused = 1;
		else if (!memcmp (cmd, "resume", 1))
			paused = 0;
		else if (!memcmp (cmd, "quit", 1))
			aborting = 1;
		else
			printf ("?%s\r\n", buf);
#else
		else
			DDS_Debug_command (buf);
#endif
	}
예제 #21
0
bool cli_send_mailslot(struct messaging_context *msg_ctx,
		       bool unique, const char *mailslot,
		       uint16 priority,
		       char *buf, int len,
		       const char *srcname, int src_type,
		       const char *dstname, int dest_type,
		       const struct sockaddr_storage *dest_ss)
{
	struct packet_struct p;
	struct dgram_packet *dgram = &p.packet.dgram;
	char *ptr, *p2;
	char tmp[4];
	pid_t nmbd_pid;
	char addr[INET6_ADDRSTRLEN];

	if ((nmbd_pid = pidfile_pid("nmbd")) == 0) {
		DEBUG(3, ("No nmbd found\n"));
		return False;
	}

	if (dest_ss->ss_family != AF_INET) {
		DEBUG(3, ("cli_send_mailslot: can't send to IPv6 address.\n"));
		return false;
	}

	memset((char *)&p, '\0', sizeof(p));

	/*
	 * Next, build the DGRAM ...
	 */

	/* DIRECT GROUP or UNIQUE datagram. */
	dgram->header.msg_type = unique ? 0x10 : 0x11;
	dgram->header.flags.node_type = M_NODE;
	dgram->header.flags.first = True;
	dgram->header.flags.more = False;
	dgram->header.dgm_id = ((unsigned)time(NULL)%(unsigned)0x7FFF) +
		((unsigned)sys_getpid()%(unsigned)100);
	/* source ip is filled by nmbd */
	dgram->header.dgm_length = 0; /* Let build_dgram() handle this. */
	dgram->header.packet_offset = 0;

	make_nmb_name(&dgram->source_name,srcname,src_type);
	make_nmb_name(&dgram->dest_name,dstname,dest_type);

	ptr = &dgram->data[0];

	/* Setup the smb part. */
	ptr -= 4; /* XXX Ugliness because of handling of tcp SMB length. */
	memcpy(tmp,ptr,4);

	if (smb_size + 17*2 + strlen(mailslot) + 1 + len > MAX_DGRAM_SIZE) {
		DEBUG(0, ("cli_send_mailslot: Cannot write beyond end of packet\n"));
		return False;
	}

	cli_set_message(ptr,17,strlen(mailslot) + 1 + len,True);
	memcpy(ptr,tmp,4);

	SCVAL(ptr,smb_com,SMBtrans);
	SSVAL(ptr,smb_vwv1,len);
	SSVAL(ptr,smb_vwv11,len);
	SSVAL(ptr,smb_vwv12,70 + strlen(mailslot));
	SSVAL(ptr,smb_vwv13,3);
	SSVAL(ptr,smb_vwv14,1);
	SSVAL(ptr,smb_vwv15,priority);
	SSVAL(ptr,smb_vwv16,2);
	p2 = smb_buf(ptr);
	fstrcpy(p2,mailslot);
	p2 = skip_string(ptr,MAX_DGRAM_SIZE,p2);
	if (!p2) {
		return False;
	}

	memcpy(p2,buf,len);
	p2 += len;

	dgram->datasize = PTR_DIFF(p2,ptr+4); /* +4 for tcp length. */

	p.packet_type = DGRAM_PACKET;
	p.ip = ((const struct sockaddr_in *)dest_ss)->sin_addr;
	p.timestamp = time(NULL);

	DEBUG(4,("send_mailslot: Sending to mailslot %s from %s ",
		 mailslot, nmb_namestr(&dgram->source_name)));
	print_sockaddr(addr, sizeof(addr), dest_ss);

	DEBUGADD(4,("to %s IP %s\n", nmb_namestr(&dgram->dest_name), addr));

	return NT_STATUS_IS_OK(messaging_send_buf(msg_ctx,
						  pid_to_procid(nmbd_pid),
						  MSG_SEND_PACKET,
						  (uint8 *)&p, sizeof(p)));
}
예제 #22
0
파일: itty.c 프로젝트: seanlynch/itty
/* The actual interpreter loop */
void interp(state_t *st) {
    while (1) {
        obj_t *x, *y, *z;
        char *p, c;
        int i;
        unsigned long u;
        /* fprintf(stderr, "Executing '%c'\n", *st->pc); */
        switch (c = *st->pc++) {
        case '\0':
            return;
        case '\r':
        case '\n':
        case '\t':
        case ' ': /* nop */
            break;
        case '!': /* call */
            POP(x);
            if (x->type != function) {
                error("Not a function.\n");
            } else {
                CALL(x);
                decref(x);
            }
            break;
        case '"': /* output string */
            p = skip_string(st->pc);
            c = *p; /* Save old character */
            *p = '\0'; /* Change it to NUL */
            fputs(st->pc, stdout); /* Print the string */
            *p = c; /* Replace original character */
            st->pc = p + 1; /* Set the PC to one past the closing quote*/
            break;
        case '#': /* over */
            POP(y); POP(x);
            PUS(x); PUS(y); PUSH(x);
            break;
        case '$': /* dup */
            POP(x);
            PUS(x); PUSH(x);
            break;
        case '%': /* mod */
            BINOP(mpz_mod);
            break;
        case '&': /* && */
            BINBOOL(NONZERO(x) && NONZERO(y));
            break;
        case '\'': /* Set multi */
            for (p = st->pc; *p && *p != '\''; p++);
            st->pc = p + 1;
            for (p--; *p != '\''; p--) {
                if (*p >= 'a' && *p <= 'z') {
                    /* local */
                    POP(x);
                    i = *p - 'a';
                    if ((y = st->frame->vars[i]) != NULL) decref(y);
                    st->frame->vars[i] = x;
                } else if (*p >= 'A' && *p <= 'Z') {
                    /* global */
                    POP(x);
                    i = *p - 'A';
                    if ((y = st->vars[i]) != NULL) decref(y);
                    st->vars[i] = x;
                } else if (*p != '\n' && *p != '\t' && *p != ' ') {
                    error("Not a variable: '%c'", *p);
                }
            }
            break;
        case '(': /* Comment; can't be nested */
            st->pc = skip_comment(st->pc);
            break;
        case '*': /* mul */
            BINOP(mpz_mul);
            break;
        case '+': /* add */
            BINOP(mpz_add);
            break;
        case ',': /* print character */
            POP(x);
            u = to_ulong(x);
            putchar(u);
            decref(x);
            break;
        case '-': /* sub */
            BINOP(mpz_sub);
            break;
        case '.': /* print */
            POP(x);
            print_obj(stdout, x);
            decref(x);
            break;
        case '/': /* div */
            BINOP(mpz_fdiv_q);
            break;
        case '0':
        case '1':
        case '2':
        case '3':
        case '4':
        case '5':
        case '6':
        case '7':
        case '8':
        case '9':
            p = st->pc;
            /* Skip to the first non-digit */
            while ((c = *p) >= '0' && c <= '9') p++;
            *p = '\0'; /* Temporarily put a NUL there */
            PUS(num_new_from_str(st->pc-1));
            *p = c; /* Replace original character */
            st->pc = p;
            break;
        case ':': /* Set variable */
            POP(x);
            c = *st->pc++;
            if (c >= 'A' && c <= 'Z') {
                /* global */
                i = c - 'A';
                if ((y = st->vars[i]) != NULL) decref(y);
                st->vars[i] = x;
            } else if (c >= 'a' && c <= 'z') {
                /* local */
                i = c - 'a';
                if ((y = st->frame->vars[i]) != NULL) decref(y);
                st->frame->vars[i] = x;
            } else {
                error("Not a variable: '%c'\n", *st->pc);
            }
            break;
        /* case ';': */
        /*     break; */
        case '<': /* less than */
            BINBOOL(mpz_cmp(*to_mpz(x), *to_mpz(y)) < 0);
            break;
        case '=': /* equal to */
            BINBOOL(mpz_cmp(*to_mpz(x), *to_mpz(y)) == 0);
            break;
        case '>': /* greater than */
            BINBOOL(mpz_cmp(*to_mpz(x), *to_mpz(y)) > 0);
            break;
        case '?': /* if */
            POP(z); POP(y); POP(x);
            if (x->type != number || y->type != function || z->type != function)
                error("Wrong argument type.");
            CALL(NONZERO(x) ? y : z);
            decref(z); decref(y); decref(x);
            break;
        case '@': /* rot */
            POP(z); POP(y); POP(x);
            PUS(y); PUS(z); PUS(x);
            break;
            /* global variables */
        case 'A':
        case 'B':
        case 'C':
        case 'D':
        case 'E':
        case 'F':
        case 'G':
        case 'H':
        case 'I':
        case 'J':
        case 'K':
        case 'L':
        case 'M':
        case 'N':
        case 'O':
        case 'P':
        case 'Q':
        case 'R':
        case 'S':
        case 'T':
        case 'U':
        case 'V':
        case 'W':
        case 'X':
        case 'Y':
        case 'Z':
            /* global variables */
            i = c - 'A';
            if ((x = st->vars[i]) == NULL) {
                error("Uninitialized variable '%c'\n", c);
            }
            if (x->type == function) {
                CALL(x);
            } else {
                PUSH(x);
            }
            break;
        case '[':
            PUS(fun_new(st->pc));
            i = 1;
            while (*st->pc) {
                switch (*st->pc++) {
                case '"':
                    st->pc = skip_string(st->pc) + 1;
                    break;
                case '(':
                    st->pc = skip_comment(st->pc) + 1;
                    break;
                case '[':
                    i++;
                    break;
                case ']':
                    if (--i <= 0) goto done;
                    break;
                }
            }
        done:
            break;
        case '\\': /* swap */
            POP(y); POP(x);
            PUS(y); PUS(x);
            break;
        case ']':
            POPRET();
            break;
        case '^': /* trace */
            print_trace(st);
            break;
        /* case '^': /\* pow *\/ */
        /*     POP(y); POP(x); */
        /*     z = num_new(); */
        /*     mpz_pow_ui(z->data.mpz, *to_mpz(x), to_ulong(y)); */
        /*     PUSH(z); */
        /*     decref(y); decref(x); */
        /*     break; *\/ */
        case '_': /* neg */
            POP(x);
            mpz_neg(*to_mpz(x), x->data.mpz);
            PUS(x);
            break;
        case '`': /* drop */
            POP(x);
            decref(x);
            break;
        case 'a':
        case 'b':
        case 'c':
        case 'd':
        case 'e':
        case 'f':
        case 'g':
        case 'h':
        case 'i':
        case 'j':
        case 'k':
        case 'l':
        case 'm':
        case 'n':
        case 'o':
        case 'p':
        case 'q':
        case 'r':
        case 's':
        case 't':
        case 'u':
        case 'v':
        case 'w':
        case 'x':
        case 'y':
        case 'z':
            /* local variables */
            i = c - 'a';
            if ((x = st->frame->vars[i]) == NULL) {
                error("Uninitialized variable '%c'\n", c);
            }
            if (x->type == function) {
                CALL(x);
            } else {
                PUSH(x);
            }
            break;
        /* case '{': */
        /*     break; */
        case '|': /* or */
            BINBOOL(NONZERO(x) || NONZERO(y));
            break;
        /* case '}': */
        /*     break; */
        case '~': /* not */
            POP(x);
            PUSH(ZERO(x) ? one : zero);
            decref(x);
            break;
        default:
            error("Undefined token '%c'\n", c);
        }
    }
}
예제 #23
0
void muj_phase1_value_string(muj_source source, muj_compressed_json target)
{
	skip_string(source, target);
}
예제 #24
0
static qboolean serverlist_load (void)
{
	int size;
	char *data;
	char *ptr;

	size = FS_LoadFile("serverlist.dat", (void**)&data);

	if (size > -1)
	{
		int endiantest;
		int actualsize;
		register int i;

		// Check header to make sure it's a valid file:
		if (memcmp(data, "PB2Serverlist1.00", sizeof("PB2Serverlist1.00")-1) != 0)
		{
			FS_FreeFile(data);
			return false;
		}

		ptr = data + sizeof("PB2Serverlist1.00")-1;
		memcpy(&endiantest, ptr, sizeof(int));

		if (endiantest != 123123123)
		{
			FS_FreeFile(data);
			return false;
		}

		// Read our data:
		ptr += sizeof(int);
		memcpy(&actualsize, ptr, sizeof(int));

		if (actualsize < INITIAL_SERVERLIST_SIZE)
		{
			FS_FreeFile(data);
			return false;
		}

		ptr += sizeof(int);
		create_serverlist(actualsize);
		memcpy(&m_serverlist.numservers, ptr, sizeof(int));
		ptr += sizeof(int);
		memcpy(&m_serverlist.nummapped, ptr, sizeof(int));
		ptr += sizeof(int);

		for (i=0; i<m_serverlist.numservers; i++)
		{
			memcpy(&m_serverlist.server[i].adr, ptr, sizeof(netadr_t));
			ptr += sizeof(netadr_t);
			m_serverlist.server[i].remap = *(short*)ptr;
			ptr += sizeof(short);
			m_serverlist.server[i].servername = text_copy(ptr);
			ptr = skip_string(ptr);
			m_serverlist.server[i].mapname = text_copy(ptr);
			ptr = skip_string(ptr);
			m_serverlist.server[i].ping = *(unsigned short*)ptr;
			ptr += sizeof(unsigned short);
			m_serverlist.server[i].players = *(unsigned char*)ptr;
			ptr += sizeof(unsigned char);
			m_serverlist.server[i].maxplayers = *(unsigned char*)ptr;
			ptr += sizeof(unsigned char);
		}

		for (i=0; i<m_serverlist.nummapped; i++)
		{
			m_serverlist.ips[i] = text_copy(ptr);
			ptr = skip_string(ptr);
			m_serverlist.info[i] = text_copy(ptr);
			ptr = skip_string(ptr);
		}

		FS_FreeFile(data);
		return true;
	}

	return false;
}
예제 #25
0
파일: t_vobj.c 프로젝트: deplinenoise/vlink
static void vobj_read(struct GlobalVars *gv,struct LinkFile *lf,uint8_t *data)
{
  struct ObjectUnit *u;
  int bpb,bpt,nsecs,nsyms,i;
  struct vobj_symbol *vsymbols = NULL;

  if (lf->type == ID_LIBARCH) {  /* check ar-member for correct format */
    vobj_check_ar_type(fff[lf->format],lf->pathname,data);
  }
  p = data + 5;  /* skip ID and endianess */
  bpb = (int)read_number();  /* bits per byte */
  if (bpb != 8) {
    /* bits per byte are not supported */
    error(113,lf->pathname,fff[lf->format]->tname,bpb);
  }
  bpt = (int)read_number();  /* bytes per taddr */
  if (bpt > sizeof(taddr)) {
    /* n bytes per target-address are not supported */
    error(114,lf->pathname,fff[lf->format]->tname,bpt);
  }
  skip_string();  /* skip cpu-string */

  u = create_objunit(gv,lf,lf->objname);
  nsecs = (int)read_number();  /* number of sections */
  nsyms = (int)read_number();  /* number of symbols */

  if (nsyms) {
    vsymbols = alloc(nsyms * sizeof(struct vobj_symbol));
    for (i=0; i<nsyms; i++)
      read_symbol(&vsymbols[i]);
  }

  for (i=1; i<=nsecs; i++)
    read_section(gv,u,(uint32_t)i,vsymbols,nsyms);

  /* add relocatable and absolute symbols, ignore unknown symbol-refs */
  for (i=0; i<nsyms; i++) {
    struct vobj_symbol *vs = &vsymbols[i];
    struct Section *s = NULL;
    uint8_t type,bind,info;

    if (vs->flags & WEAK)
      bind = SYMB_WEAK;
    else if (vs->flags & EXPORT)
      bind = SYMB_GLOBAL;
    else
      bind = SYMB_LOCAL;

    if (vs->flags & COMMON) {
      type = SYM_COMMON;
      s = common_section(gv,u);
    }
    else if (vs->type == EXPRESSION) {
      type = SYM_ABS;
      s = abs_section(u);
    }
    else if (vs->type == LABSYM) {
      type = SYM_RELOC;
      if (!(s = find_sect_id(u,vs->sec))) {
        /* a section with this index doesn't exist! */
        error(53,lf->pathname,vs->name,lf->objname,vs->sec);
      }
    }
    else if (vs->type == IMPORT) {
      type = 0;  /* ignore unknown symbols */
    }
    else {
      /* illegal symbol type */
      error(116,getobjname(u),fff[lf->format]->tname,
            vs->type,vs->name,lf->objname);
      type = 0;
    }

    switch (TYPE(vs)) {
      case TYPE_UNKNOWN: info = SYMI_NOTYPE; break;
      case TYPE_OBJECT: info = SYMI_OBJECT; break;
      case TYPE_FUNCTION: info = SYMI_FUNC; break;
      case TYPE_SECTION: type = 0; break;  /* ignore SECTION symbols */
      case TYPE_FILE: info = SYMI_FILE; break;
      default:
        error(54,lf->pathname,TYPE(vs),vs->name,lf->objname);
        type = 0;
        break;
    }

    if (type) {
      if (bind == SYMB_LOCAL)
        addlocsymbol(gv,s,vs->name,NULL,(lword)vs->val,type,0,info,vs->size);
      else
        addsymbol(gv,s,vs->name,NULL,(lword)vs->val,
                  type,0,info,bind,vs->size,TRUE);
    }
  }
  if (nsyms)
    free(vsymbols);

  add_objunit(gv,u,TRUE);  /* add object unit and fix relocations */
}
    if(!AM_LOCAL_MASTER_BROWSER(work)) {
        DEBUG(5,("browse_sync_remote: We can only do this if we are a local master browser \
for workgroup %s on subnet %s.\n", lp_workgroup(), FIRST_SUBNET->subnet_name ));
        return;
    }

    memset(outbuf,'\0',sizeof(outbuf));
    p = outbuf;
    SCVAL(p,0,ANN_MasterAnnouncement);
    p++;

    fstrcpy(myname, global_myname());
    strupper_m(myname);
    myname[15]='\0';
    push_pstring_base(p, myname, outbuf);

    p = skip_string(p,1);

    for (ptr=s; next_token(&ptr,s2,NULL,sizeof(s2)); ) {
        /* The entries are of the form a.b.c.d */
        addr = *interpret_addr2(s2);

        DEBUG(5,("announce_remote: Doing remote browse sync announce for server %s to IP %s.\n",
                 global_myname(), inet_ntoa(addr) ));

        send_mailslot(True, BROWSE_MAILSLOT, outbuf,PTR_DIFF(p,outbuf),
                      global_myname(), 0x0, "*", 0x0, addr, FIRST_SUBNET->myip, DGRAM_PORT);
    }
}
예제 #27
0
bool cli_NetServerEnum(struct cli_state *cli, char *workgroup, uint32_t stype,
		       void (*fn)(const char *, uint32_t, const char *, void *),
		       void *state)
{
	char *rparam = NULL;
	char *rdata = NULL;
	char *rdata_end = NULL;
	unsigned int rdrcnt,rprcnt;
	char *p;
	char param[1024];
	int uLevel = 1;
	size_t len;
	uint32_t func = RAP_NetServerEnum2;
	char *last_entry = NULL;
	int total_cnt = 0;
	int return_cnt = 0;
	int res;

	errno = 0; /* reset */

	/*
	 * This may take more than one transaction, so we should loop until
	 * we no longer get a more data to process or we have all of the
	 * items.
	 */
	do {
		/* send a SMBtrans command with api NetServerEnum */
	        p = param;
		SIVAL(p,0,func); /* api number */
	        p += 2;

		if (func == RAP_NetServerEnum3) {
			strlcpy(p,"WrLehDzz", sizeof(param)-PTR_DIFF(p,param));
		} else {
			strlcpy(p,"WrLehDz", sizeof(param)-PTR_DIFF(p,param));
		}

		p = skip_string(param, sizeof(param), p);
		strlcpy(p,"B16BBDz", sizeof(param)-PTR_DIFF(p,param));

		p = skip_string(param, sizeof(param), p);
		SSVAL(p,0,uLevel);
		SSVAL(p,2,CLI_BUFFER_SIZE);
		p += 4;
		SIVAL(p,0,stype);
		p += 4;

		/* If we have more data, tell the server where
		 * to continue from.
		 */
		len = push_ascii(p,
				workgroup,
				sizeof(param) - PTR_DIFF(p,param) - 1,
				STR_TERMINATE|STR_UPPER);

		if (len == 0) {
			SAFE_FREE(last_entry);
			return false;
		}
		p += len;

		if (func == RAP_NetServerEnum3) {
			len = push_ascii(p,
					last_entry ? last_entry : "",
					sizeof(param) - PTR_DIFF(p,param) - 1,
					STR_TERMINATE);

			if (len == 0) {
				SAFE_FREE(last_entry);
				return false;
			}
			p += len;
		}

		/* Next time through we need to use the continue api */
		func = RAP_NetServerEnum3;

		if (!cli_api(cli,
			param, PTR_DIFF(p,param), 8, /* params, length, max */
			NULL, 0, CLI_BUFFER_SIZE, /* data, length, max */
		            &rparam, &rprcnt, /* return params, return size */
		            &rdata, &rdrcnt)) { /* return data, return size */

			/* break out of the loop on error */
		        res = -1;
		        break;
		}

		rdata_end = rdata + rdrcnt;
		res = rparam ? SVAL(rparam,0) : -1;

		if (res == 0 || res == ERRmoredata ||
                    (res != -1 && cli_errno(cli) == 0)) {
			char *sname = NULL;
			int i, count;
			int converter=SVAL(rparam,2);

			/* Get the number of items returned in this buffer */
			count = SVAL(rparam, 4);

			/* The next field contains the number of items left,
			 * including those returned in this buffer. So the
			 * first time through this should contain all of the
			 * entries.
			 */
			if (total_cnt == 0) {
			        total_cnt = SVAL(rparam, 6);
			}

			/* Keep track of how many we have read */
			return_cnt += count;
			p = rdata;

			/* The last name in the previous NetServerEnum reply is
			 * sent back to server in the NetServerEnum3 request
			 * (last_entry). The next reply should repeat this entry
			 * as the first element. We have no proof that this is
			 * always true, but from traces that seems to be the
			 * behavior from Window Servers. So first lets do a lot
			 * of checking, just being paranoid. If the string
			 * matches then we already saw this entry so skip it.
			 *
			 * NOTE: sv1_name field must be null terminated and has
			 * a max size of 16 (NetBIOS Name).
			 */
			if (last_entry && count && p &&
				(strncmp(last_entry, p, 16) == 0)) {
			    count -= 1; /* Skip this entry */
			    return_cnt = -1; /* Not part of total, so don't count. */
			    p = rdata + 26; /* Skip the whole record */
			}

			for (i = 0; i < count; i++, p += 26) {
				int comment_offset;
				const char *cmnt;
				const char *p1;
				char *s1, *s2;
				TALLOC_CTX *frame = talloc_stackframe();
				uint32_t entry_stype;

				if (p + 26 > rdata_end) {
					TALLOC_FREE(frame);
					break;
				}

				sname = p;
				comment_offset = (IVAL(p,22) & 0xFFFF)-converter;
				cmnt = comment_offset?(rdata+comment_offset):"";

				if (comment_offset < 0 || comment_offset >= (int)rdrcnt) {
					TALLOC_FREE(frame);
					continue;
				}

				/* Work out the comment length. */
				for (p1 = cmnt, len = 0; *p1 &&
						p1 < rdata_end; len++)
					p1++;
				if (!*p1) {
					len++;
				}

				entry_stype = IVAL(p,18) & ~SV_TYPE_LOCAL_LIST_ONLY;

				pull_string_talloc(frame,rdata,0,
					&s1,sname,16,STR_ASCII);
				pull_string_talloc(frame,rdata,0,
					&s2,cmnt,len,STR_ASCII);

				if (!s1 || !s2) {
					TALLOC_FREE(frame);
					continue;
				}

				fn(s1, entry_stype, s2, state);
				TALLOC_FREE(frame);
			}

			/* We are done with the old last entry, so now we can free it */
			if (last_entry) {
			        SAFE_FREE(last_entry); /* This will set it to null */
			}

			/* We always make a copy of  the last entry if we have one */
			if (sname) {
			        last_entry = smb_xstrdup(sname);
			}

			/* If we have more data, but no last entry then error out */
			if (!last_entry && (res == ERRmoredata)) {
			        errno = EINVAL;
			        res = 0;
			}

		}

		SAFE_FREE(rparam);
		SAFE_FREE(rdata);
	} while ((res == ERRmoredata) && (total_cnt > return_cnt));

	SAFE_FREE(rparam);
	SAFE_FREE(rdata);
	SAFE_FREE(last_entry);

	if (res == -1) {
		errno = cli_errno(cli);
	} else {
		if (!return_cnt) {
			/* this is a very special case, when the domain master for the
			   work group isn't part of the work group itself, there is something
			   wild going on */
			errno = ENOENT;
		}
	    }

	return(return_cnt > 0);
}
예제 #28
0
bool TorrentBase::skip_info_utf8() {
	return m_check_info_utf8 ? skip_utf8() : skip_string();
}
예제 #29
0
bool cli_NetWkstaUserLogon(struct cli_state *cli,char *user, char *workstation)
{
	char *rparam = NULL;
	char *rdata = NULL;
	char *p;
	unsigned int rdrcnt,rprcnt;
	char param[1024];

	memset(param, 0, sizeof(param));

	/* send a SMBtrans command with api NetWkstaUserLogon */
	p = param;
	SSVAL(p,0,132); /* api number */
	p += 2;
	strlcpy(p,"OOWb54WrLh",sizeof(param)-PTR_DIFF(p,param));
	p = skip_string(param,sizeof(param),p);
	strlcpy(p,"WB21BWDWWDDDDDDDzzzD",sizeof(param)-PTR_DIFF(p,param));
	p = skip_string(param,sizeof(param),p);
	SSVAL(p,0,1);
	p += 2;
	strlcpy(p,user,sizeof(param)-PTR_DIFF(p,param));
	if (!strupper_m(p)) {
		return false;
	}
	p += 21;
	p++;
	p += 15;
	p++;
	strlcpy(p, workstation,sizeof(param)-PTR_DIFF(p,param));
	if (!strupper_m(p)) {
		return false;
	}
	p += 16;
	SSVAL(p, 0, CLI_BUFFER_SIZE);
	p += 2;
	SSVAL(p, 0, CLI_BUFFER_SIZE);
	p += 2;

	if (cli_api(cli,
                    param, PTR_DIFF(p,param),1024,  /* param, length, max */
                    NULL, 0, CLI_BUFFER_SIZE,           /* data, length, max */
                    &rparam, &rprcnt,               /* return params, return size */
                    &rdata, &rdrcnt                 /* return data, return size */
                   )) {
		cli->rap_error = rparam? SVAL(rparam,0) : -1;
		p = rdata;

		if (cli->rap_error == 0) {
			DEBUG(4,("NetWkstaUserLogon success\n"));
			/*
			 * The cli->privileges = SVAL(p, 24); field was set here
			 * but it was not use anywhere else.
			 */
			/* The cli->eff_name field used to be set here
	                   but it wasn't used anywhere else. */
		} else {
			DEBUG(1,("NetwkstaUserLogon gave error %d\n", cli->rap_error));
		}
	}

	SAFE_FREE(rparam);
	SAFE_FREE(rdata);
	return (cli->rap_error == 0);
}
예제 #30
0
파일: cliprint.c 프로젝트: ekohl/samba
int cli_print_queue(struct cli_state *cli,
		    void (*fn)(struct print_job_info *))
{
	char *rparam = NULL;
	char *rdata = NULL;
	char *p;
	unsigned int rdrcnt, rprcnt;
	char param[1024];
	int result_code=0;
	int i = -1;

	memset(param,'\0',sizeof(param));

	p = param;
	SSVAL(p,0,76);         /* API function number 76 (DosPrintJobEnum) */
	p += 2;
	strlcpy_base(p,"zWrLeh", param, sizeof(param));   /* parameter description? */
	p = skip_string(param,sizeof(param),p);
	strlcpy_base(p,"WWzWWDDzz", param, sizeof(param));  /* returned data format */
	p = skip_string(param,sizeof(param),p);
	strlcpy_base(p,cli->share, param, sizeof(param));    /* name of queue */
	p = skip_string(param,sizeof(param),p);
	SSVAL(p,0,2);   /* API function level 2, PRJINFO_2 data structure */
	SSVAL(p,2,1000); /* size of bytes of returned data buffer */
	p += 4;
	strlcpy_base(p,"", param,sizeof(param));   /* subformat */
	p = skip_string(param,sizeof(param),p);

	DEBUG(4,("doing cli_print_queue for %s\n", cli->share));

	if (cli_api(cli,
		    param, PTR_DIFF(p,param), 1024,  /* Param, length, maxlen */
		    NULL, 0, CLI_BUFFER_SIZE,            /* data, length, maxlen */
		    &rparam, &rprcnt,                /* return params, length */
		    &rdata, &rdrcnt)) {               /* return data, length */
		int converter;
		result_code = SVAL(rparam,0);
		converter = SVAL(rparam,2);       /* conversion factor */

		if (result_code == 0) {
			struct print_job_info job;

			p = rdata;

			for (i = 0; i < SVAL(rparam,4); ++i) {
				job.id = SVAL(p,0);
				job.priority = SVAL(p,2);
				fstrcpy(job.user,
					fix_char_ptr(SVAL(p,4), converter,
						     rdata, rdrcnt));
				job.t = make_unix_date3(
					p + 12, cli_state_server_time_zone(cli));
				job.size = IVAL(p,16);
				fstrcpy(job.name,fix_char_ptr(SVAL(p,24),
							      converter,
							      rdata, rdrcnt));
				fn(&job);
				p += 28;
			}
		}
	}

	/* If any parameters or data were returned, free the storage. */
	SAFE_FREE(rparam);
	SAFE_FREE(rdata);

	return i;
}