Exemple #1
0
void authtoken_init()
{
	char buf1[512], buf2[512];
	char t1[128/8], t2[128/8];
	struct stat stat_buf;

	FILE *fp=fopen(RANDTOKENFILE, "r");

	time(&expire_time);

	if (fp)
	{
		if (fgets(buf1, sizeof(buf1), fp) &&
		    fgets(buf2, sizeof(buf2), fp))
		{
			char *p;

			if ((p=strchr(buf1, '\n')) != NULL)
				*p=0;
			if ((p=strchr(buf2, '\n')) != NULL)
				*p=0;

			/* Determine if the saved tokens are kosher */

			if (strlen(buf1) == 32 &&
			    strlen(buf2) == 32 &&
			    goodtoken(buf1, t1) == 0 &&
			    goodtoken(buf2, t2) == 0 &&
			    fstat(fileno(fp), &stat_buf) == 0 &&

			    /* Haven't expired (+tolerate clock adjustments) */
			    stat_buf.st_mtime < expire_time + 60 &&
			    stat_buf.st_mtime >= expire_time - TIMEOUT*2)
			{
				expire_time=stat_buf.st_mtime + TIMEOUT*2;
				memcpy(prev_token, t1, sizeof(t1));
				memcpy(cur_token, t2, sizeof(t2));
				fclose(fp);
				fprintf(stderr, "NOTICE: restored saved authentication tokens\n");
				return;
			}
		}
		fclose(fp);
	}
	newtoken(prev_token);
	newtoken(cur_token);
	expire_time += TIMEOUT*2;
	savetokens();
}
Exemple #2
0
/* CONTEXT: Determine whether a GI is valid in the present structural context.
            Returns RCHIT if valid, RCEND if element has ended, RCREQ if a
            different element is required, and RCMISS if it is totally invalid.
            On entry, pos points to the model token to be tested against the GI.
            TO DO: Save allowed GIs for an error message on an RCMISS.
                   Support a "query" mode (what is allowed now?) by working
                   with a copy of pos.
*/
int context(struct etd *gi,               /* ETD of new GI. */
				struct thdr mod[],            /* Model of current open element. */
				struct mpos pos[],            /* Position in open element's model. */
				UNCH *statuspt,               /* Token status: RCHIT RCMISS RCEND RCREQ RCNREQ*/
				int mexts)                    /* >0=stack level of minus grp; -1=plus; 0=none.*/
{
     UNCH toccsv, gtypesv;    /* Save token's TOCC and GTYPE in case grp ends.*/

     if (mexts == -1) {
	  if (STATUS == RCEND)
	       return RCPEX;
	  copypos(savedpos, pos);
     }
     Tstart = T;              /* Save starting token for AND group testing. */
     while (STATUS!=RCMISS && STATUS!=RCEND) {
          TRACEGI("CONTEXT", gi, mod, pos, Tstart);
          while (TTYPE==TTOR || TTYPE==TTSEQ || TTYPE==TTAND) {
               pos[P+1].g = M++; pos[++P].t = 1; HITCLEAR(H);
               Tstart = T;    /* Save starting token for AND group testing. */
               TRACEGI("OPENGRP", gi, mod, pos, Tstart);
          }
          STATUS = (UNCH)tokenreq(gi, mod, pos);
          TRACEGI("STATUS", gi, mod, pos, Tstart);
          if (gi==TOKEN.tu.thetd) {     /* Hit in model. */
               STATUS = (UNCH)RCHIT;
               gtypesv = GTYPE; toccsv = TOCC;
               newtoken(mod, pos, statuspt);
               return(mexts<=0 ? RCHIT : (gtypesv==TTOR || BITON(toccsv, TOPT))
                                       ?  RCMEX : RCHITMEX);
          }
          if (STATUS==RCREQ) {
				 if (mexts == -1) break;
				 STATUS = RCHIT;
				 nextetd = TOKEN.tu.thetd;
				 newtoken(mod, pos, statuspt);
				 return(RCREQ);
          }
          /* else if (STATUS==RCNREQ) */
			 if (mexts>0) return(RCMEX);
			 newtoken(mod, pos, statuspt);
     }
     if (mexts == -1) {
		  copypos(pos, savedpos);
		  return STATUS = RCPEX;
     }
     return((int)STATUS);
}
Exemple #3
0
token *
lex()
	{
	static char *word = NULL;
	token *result;
	char *p;

	result = newtoken();

	if (!word || *word == 0) {
		word = getword();
		if (!word) {
			result->type = 0;
			if (D_valsi)
				printf("valsi: end of text\n");
			return result;
			}
		}

	if (iscmene(word)) {
		result->type = CMENE_518;
		result->text = newstring(strlen(word) + 1);
		memcheck(result->text, "text");
		strcpy(result->text, word);
		word = NULL;
		}
	else if (isbrivla(word)) {
		result->type = BRIVLA_509;
		result->text = newstring(strlen(word) + 1);
		memcheck(result->text, "text");
		strcpy(result->text, word);
		word = NULL;
		}
	else {
		for (p = word + 1; *p; p++)
			if (isC(*p)) break;
		result->text = newstring(p - word + 1);
		memcheck(result->text, "text");
		strncpy(result->text, word, p - word);
		result->text[p-word] = 0;
		word = p;
		}
	if (D_valsi) {
		printf("valsi: ");
		print(result);
		}
	return result;
	}
Exemple #4
0
static struct token*
clone_token(struct token *stok)
{
  struct token*tp = newtoken();
  *tp = *stok;
  if (curr_lang)
    {
      tp->lang = curr_lang;
      texttag_register(curr_lang->fulltag);
    }
  else
    {
      tp->lang = global_lang;
    }
  return tp;
}
Exemple #5
0
time_t authtoken_check()
{
	time_t now;

	time(&now);

	if (now < expire_time && now >= expire_time - TIMEOUT*4)
		return (expire_time - now);

	memcpy(prev_token, cur_token, sizeof(cur_token));
	newtoken(cur_token);
	savetokens();
	now += TIMEOUT*2;
	expire_time=now;
	return (TIMEOUT*2);
}
Exemple #6
0
/* Create a new NFS request of type specified */
static
NFS_BaseRequest *
create_request(enum NfsRequestType rt, VNode vn, pid_t pid) {
	dprintf(2, "create request: %d %p %d\n", rt, vn, pid);
	NFS_BaseRequest *rq;

	switch (rt) {
		case RT_LOOKUP:
			rq = (NFS_BaseRequest *) malloc(sizeof(NFS_LookupRequest));
			break;
		case RT_READ:
			rq = (NFS_BaseRequest *) malloc(sizeof(NFS_ReadRequest));
			break;
		case RT_WRITE:
			rq = (NFS_BaseRequest *) malloc(sizeof(NFS_WriteRequest));
			break;
		case RT_STAT:
			rq = (NFS_BaseRequest *) malloc(sizeof(NFS_StatRequest));
			break;
		case RT_DIR:
			rq = (NFS_BaseRequest *) malloc(sizeof(NFS_DirRequest));
			break;
		case RT_REMOVE:
			rq = (NFS_BaseRequest *) malloc(sizeof(NFS_RemoveRequest));
			break;
		default:
			dprintf(0, "!!! nfsfs_create_request: invalid request type %d\n", rt);
			return NULL;
	}

	if (rq == NULL) {
		dprintf(0, "!!! nfsfs_create_request: Malloc failed! (type %d)\n", rt);
		return NULL;
	}

	rq->rt = rt;
	rq->token = newtoken();
	rq->vnode = vn;
	rq->pid = pid;

	// add to list
	list_push(NfsRequests, rq);

	return rq;
}
Exemple #7
0
struct prsstack *gettok()										/*;gettok*/
{
	/* Gettok: Scan and return the next token in the adafile, adding the */
	/* token to namelist. */

	static int nextcanbeprime = 0;	/* The next token can be a prime */
	static int canbeprime;			/* The current token can be a prime */
	struct prsstack *tok;			/* Token to be returned */

	while (1) {
		while (1) {
			while (*line == ' ' || *line == '\t') {
				colno += (*line == '\t') ? (8 - ((colno - 1) % 8)) : 1;
				line++;
			}
			if (!*line || *line == '-' && line[1] == '-')
				break;
			canbeprime = nextcanbeprime;
			nextcanbeprime = 0;

			if (isalpha(*line)) {		/* Scan identifiers */
				char id[MAXLINE + 1];
				int idind = 0, chread = 0;
				int tokind, toksym;

				scanidorint(id, &idind, &chread, isletterordigit, 0);
				if (id[idind - 1] == '_')
					idind--;
				id[idind] = '\0';
				convtoupper(id);
				tokind = namemap(id, idind);
				toksym = MIN(tokind, ID_SYM);
				tok = newtoken(toksym, tokind, lineno, colno);
				nextcanbeprime = toksym == ID_SYM || toksym == RANGE_SYM
				  || toksym == ALL_SYM;
				colno += chread;
				line += chread;
				return(tok);
			}

			else if (isdigit(*line) || *line == '.' && isdigit(line[1])) {
			/* Scan numeric literals */
				char num[MAXLINE + 3];
				int ind = 0, chread = 0, result;
				char ch;
				/* ind is the index into the num string */
				/* chread is the index into the line input string */

				result = scandec(num, &ind, &chread, isdecimal);
				ch = line[chread];
				if (result == 1 && (ch == '#' || ch == ':')) {
				/* Scan for the rest of a based literal */
					num[ind++] = '#';
					chread++;
					if (!scandec(num, &ind, &chread, ishex)) {
						lexerr(lineno, colno + chread - 1, colno + chread - 1,
						  "Incomplete based number");
						num[ind++] = '0';
					}
					num[ind++] = '#';
					if (line[chread] != ch) {
						if (line[chread] == '#' + ':' - ch) {
							lexerr(lineno, colno + chread, colno + chread,
							  "Expect #'s or :'s in based number to match");
							chread++;
						}
						else {
							char msg[50];

							sprintf(msg, "Expect '%c' after last digit", ch);
							lexerr(lineno, colno + chread - 1,
							  colno + chread - 1, msg);
						}
					}
					else
						chread++;
					checkbased(num, &ind);
				}
				scanexp(num, &ind, &chread);
				if (isalpha(line[chread]))
					lexerr(lineno, colno, colno + chread - 1,
					  "Number should be separated from adjacent identifier");
				num[ind] = '\0';
				tok = newtoken(NUMBER_SYM, namemap(num, ind), lineno, colno);
				colno += chread;
				line += chread;
				return(tok);
			}

			else if (*line == '\'') {
				int err = 0;

				if (line[1] != '\0' && line[2] == '\'' &&
				    (!canbeprime || line[1] != '(')) {
				/* Scan a character literal */
					char str[4];
					int len = 3;

					strcpy(str, "' '");
					if (!isprint(line[1]) && line[1] != ' ') {
						char msg[80];

						sprintf(msg,
  "Invalid character %s in character literal replaced by space",
						  nonprintingmsg[line[1]]);
						lexerr(lineno, colno + 1, colno + 1, msg);
						len = (line[1] == '\t') ? (10 - (colno % 8)) : 2;
					}
					else
						str[1] = line[1];
					tok = newtoken(CHAR_SYM, namemap(str, 3), lineno, colno);
					colno += len;
					line += 3;
					return(tok);
				}
				else if (!canbeprime) {
				/* Possibly a single quote delimited string */
					int ind;

					if (line[1] == '\'')
						ind = 1;
					else {
						ind = 3;
						while (line[ind]) {
							if (line[ind] == '\'') {
								if (line[ind + 1] && line[ind + 2] == '\'') {
									ind = -1;
									break;
								}
								else {
									if (line[ind + 1] != '\'')
										break;
									ind++;
								}
							}
							ind++;
						}
					}
					if (ind > -1 && line[ind]) {
						err = 1;
						lexerr(lineno, colno, colno + ind,
						  "Expect double quotes to delimit a character string");
						do
							if (line[ind] == '\'')
								line[ind] = '"';
						while (ind--);
					}
				}
				if (!err) {     /* A prime */
					int ind = namemap("'", 1);

					tok = newtoken(ind, ind, lineno, colno);
					colno++;
					line++;
					return(tok);
				}
			}
			else if (*line == '"' || *line == '%') {
			/* Scan a string literal */
				int col = colno;
				int oldindex = 0, newindex = -1;
				char bracket = *line;
				char nxtchr ;
				char tmpstr[MAXLINE + 1];
				int   save_col;	   /* these are maintained to restore line */
				char *save_line;   /* in case of missing string bracket */
				int   save_newindex;

				if ( (strchr(line+1, bracket)) == 0 ) {
					char bracket_str[2];
					*bracket_str = bracket; 
					*(bracket_str + 1) = '\0';
					tok = newtoken(ERROR_SYM, namemap(bracket_str, 1),
					    lineno, colno);
					line++;
					colno++;
					return(tok);
				}
				while (1) {
					save_line = line + oldindex + 1;
					save_col = col + 1;
					save_newindex = newindex + 1;
					do {
						col++;
						oldindex++;
						newindex++;
						nxtchr = line[oldindex] ;
						tmpstr[newindex] = nxtchr ;
					}
					/* test separately for bracket for use of % as delimiter */
					while (nxtchr != bracket  && IS_STRING_CHAR(nxtchr));

					if (line[oldindex] == bracket) {
						if (line[oldindex + 1] == bracket) {
							tmpstr[newindex] = bracket ;
							oldindex++;
							col++;
						}
						else {
							tmpstr[newindex] = '\0';
							tok = newtoken(STRING_SYM, namemap(tmpstr,
							  newindex), lineno, colno+1);
							colno = col + 1;
							line += oldindex + 1;
							return(tok);
						}
					}
					else if (line[oldindex] == '"') {
						oldindex++;
						lexerr(lineno, col, col,
						  "% delimited string contains \", being ignored");
					}
					else if (line[oldindex] == '\0') {
						lexerr(lineno, colno, colno, "Missing string bracket");
						/* restore values of line and colno to values prior to
						 * last set of string characters 
			 			 */
						line = save_line;
						colno = save_col;
						/*  insert a closing string bracket */
						tmpstr[save_newindex] = bracket;
						tmpstr[save_newindex + 1] = '\0';
						tok = newtoken(STRING_SYM, namemap(tmpstr,
						  save_newindex + 1), lineno, colno);
						return(tok);
					}
/*
		    else if (isprint(line[oldindex]) || line[oldindex] == ' ')
			tmpstr[newindex] = line[oldindex];
*/
					else {
						char msg[80];

						sprintf(msg, "Invalid character %s in string deleted",
						  nonprintingmsg[line[oldindex++]]);
						lexerr(lineno, col, col, msg);
						col += (line[oldindex] == '\t') ? 7 - ((col-1)%8) : -1;
					}
				}
			}

			else if (ISDELIMITER(*line))	/* Scan a delimiter */
			{
				int len = 1, ind;
				char str[3];

				switch (*line) {
				case '=' :
					if (line[1] == '>')
						len = 2;
					break;
				case '*' :
					if (line[1] == '*')
						len = 2;
					break;
				case ':' :
				case '/' :
					if (line[1] == '=')
						len = 2;
					break;
				case '>' :
					if (line[1] == '=' || line[1] == '>')
						len = 2;
					break;
				case '<' :
					if (line[1] == '=' || line[1] == '<' || line[1] == '>')
						len = 2;
					break;
				case '.' :
					if (line[1] == '.')
						len = 2;
					break;
				case '!' :
					*line = '|';
					break;
				case '[' :	/* Change to a "(" */
					lexerr(lineno, colno, colno,
					  "Bad character \"[\", replaced by \"(\".") ;
					line[0] = '(' ;
					break ;
				case ']' :	/* Change to a ")" */
					/* Note that this case falls through to the next one */
					lexerr(lineno, colno, colno,
					  "Bad character \"]\", replaced by \")\".") ;
					line[0] = ')' ;
				case ')' :
					nextcanbeprime = 1;
					break;
				}
				strncpy(str, line, len);
				str[len] = '\0';
				ind = namemap(str, len);
				tok = newtoken(ind, ind, lineno, colno);
				colno += len;
				line += len;
				return(tok);
			}

			else if (*line == '_') {	/* An error- an underline _ */
				lexerr(lineno, colno, colno, "Break character misplaced");
				colno++;
				line++;
			}

			else {	/* An error- an unknown character */
				char msg[80];
				char ch[2];

				*ch = *line;
				ch[1] = '\0';
				sprintf(msg, "Bad character in file ignored: %s",
				    (isprint(*line)) ? ch : nonprintingmsg[*line]);
				lexerr(lineno, colno, colno, msg);
				if (isprint(*line))
					colno++;
				line++;
			}
		}
		if (getline() == EOF)
			return(newtoken(EOFT_SYM, EOFT_SYM, lineno, colno));
	}
}