Ejemplo n.º 1
0
static void readinput(void) {
    char *input;
    if ((input = calloc(1, LINE_MAX)) == NULL)
        err(EXIT_FAILURE, "failed to allocate space for input");

    int r = wgetnstr(winp, input, LINE_MAX);
    updatewinp();

    if (r == ERR) readout();
    else if (r == KEY_RESIZE) redrawall();
    else if (input == NULL) return;
    else if (strlen(input) == 0) redrawall();
    else if (strcmp(input, ESCSYMB) == 0) running = false;
    else sendmesg(input);
}
Ejemplo n.º 2
0
int main(int argc, char **argv)
{
    char input[MAXLINE], *mapname, def[MAXLINE], conf[MAXLINE], errstr[MAXLINE];
    double testpoint[2], pointarray[MAXVERTS][2];
    int i, j, k;
    FILE *fp;
    char *t;
    double dist, mindist;
    int sawpoint = 0;
    
    if (argc != 2)
        servererr("Wrong number of arguments, client may not support ISMAP.");
    mapname=getenv("PATH_INFO");

    if((!mapname) || (!mapname[0]))
        servererr("No map name given. Please read the <A HREF=\"http://hoohoo.ncsa.uiuc.edu/docs/tutorials/imagemapping.html\">instructions</A>.<P>");


    mapname++;
    if(!(t = strchr(argv[1],',')))
        servererr("Your client doesn't support image mapping properly.");
    *t++ = '\0';
    testpoint[X] = (double) atoi(argv[1]);
    testpoint[Y] = (double) atoi(t);

    /*
     * if the mapname contains a '/', it represents a unix path -
     * we get the translated path, and skip reading the configuration file.
     */
    if (strchr(mapname,'/')) {
      strcpy(conf,getenv("PATH_TRANSLATED"));
      goto openconf;
    }
    
    if ((fp = fopen(CONF_FILE, "r")) == NULL){
      /* Assume new style request if CONF_FILE doesn't exist
       */
       goto openconf;
    }

    while(!(mygetline(input,MAXLINE,fp))) {
        char confname[MAXLINE];
        if((input[0] == '#') || (!input[0]))
            continue;
        for(i=0;isname(input[i]) && (input[i] != ':');i++)
            confname[i] = input[i];
        confname[i] = '\0';
        if(!strcmp(confname,mapname))
            goto found;
    }
    /*
     * if mapname was not found in the configuration file, it still
     * might represent a file in the server root directory -
     * we get the translated path, and check to see if a file of that
     * name exists, jumping to the opening of the map file if it does.
     */
    if(feof(fp)) {
      struct stat sbuf;
      strcpy(conf,getenv("PATH_TRANSLATED"));
      if (!stat(conf,&sbuf) && ((sbuf.st_mode & S_IFMT) == S_IFREG))
	goto openconf;
      else
	servererr("Map not found in configuration file.");
    }
    
  found:
    fclose(fp);
    while(isspace(input[i]) || input[i] == ':') ++i;

    for(j=0;input[i] && isname(input[i]);++i,++j)
        conf[j] = input[i];
    conf[j] = '\0';

  openconf:
    if(!(fp=fopen(conf,"r"))){
	sprintf(errstr, "Couldn't open configuration file: %s", conf);
        servererr(errstr);
    }

    while(!(mygetline(input,MAXLINE,fp))) {
        char type[MAXLINE];
        char url[MAXLINE];
        char num[10];

        if((input[0] == '#') || (!input[0]))
            continue;

        type[0] = '\0';url[0] = '\0';

        for(i=0;isname(input[i]) && (input[i]);i++)
            type[i] = input[i];
        type[i] = '\0';

        while(isspace(input[i])) ++i;
        for(j=0;input[i] && isname(input[i]);++i,++j)
            url[j] = input[i];
        url[j] = '\0';

        if(!strcmp(type,"default") && !sawpoint) {
            strcpy(def,url);
            continue;
        }

        k=0;
        while (input[i]) {
            while (isspace(input[i]) || input[i] == ',')
                i++;
            j = 0;
            while (isdigit(input[i]))
                num[j++] = input[i++];
            num[j] = '\0';
            if (num[0] != '\0')
                pointarray[k][X] = (double) atoi(num);
            else
                break;
            while (isspace(input[i]) || input[i] == ',')
                i++;
            j = 0;
            while (isdigit(input[i]))
                num[j++] = input[i++];
            num[j] = '\0';
            if (num[0] != '\0')
                pointarray[k++][Y] = (double) atoi(num);
            else {
                fclose(fp);
                servererr("Missing y value.");
            }
        }
        pointarray[k][X] = -1;
        if(!strcmp(type,"poly"))
            if(pointinpoly(testpoint,pointarray))
                sendmesg(url);
        if(!strcmp(type,"circle"))
            if(pointincircle(testpoint,pointarray))
                sendmesg(url);
        if(!strcmp(type,"rect"))
            if(pointinrect(testpoint,pointarray))
                sendmesg(url);
        if(!strcmp(type,"point")) {
	    /* Don't need to take square root. */
	    dist = ((testpoint[X] - pointarray[0][X])
		    * (testpoint[X] - pointarray[0][X]))
		   + ((testpoint[Y] - pointarray[0][Y])
		      * (testpoint[Y] - pointarray[0][Y]));
	    /* If this is the first point, or the nearest, set the default. */
	    if ((! sawpoint) || (dist < mindist)) {
		mindist = dist;
	        strcpy(def,url);
	    }
	    sawpoint++;
	}
    }
    if(def[0])
        sendmesg(def);
    servererr("No default specified.");
}
Ejemplo n.º 3
0
/* NCSA Imagemap files use: method URL coord1 coord2
 * CERN Imagemap files use: method (coord1) (coord2) URL
 * This version of imagemap will probably work with either in the same file,
 * as long as a full line is in one format or the other.
 */
int send_imagemap(per_request* reqInfo, struct stat* fi, char allow_options)
{
    char *input, *def, *szPoint, *url, *type;
    double testpoint[2], pointarray[MAXVERTS][2];
    int i, j, k;
    int error_num = 0;
    FILE *fp;
    char *t;
    double dist, mindist = -1;
    int sawpoint = 0;
    int sawparen = 0;
    int Found = 0;

    
    input = newString(HUGE_STRING_LEN,STR_TMP);
    def = newString(MAX_STRING_LEN,STR_TMP);
    szPoint = newString(MAX_STRING_LEN,STR_TMP);
    type = newString(MAX_STRING_LEN,STR_TMP);
    url = newString(MAX_STRING_LEN,STR_TMP);

    def[0] = '\0';
    strcpy(szPoint, reqInfo->args);

    if(!(t = strchr(szPoint,','))) {
        error_num = IMAP_ERR_INCORRECT_ARGS;
	goto imagemap_error;
    }

    *t++ = '\0';
    testpoint[X] = (double) atoi(szPoint);
    testpoint[Y] = (double) atoi(t);

    if(!(fp=FOpen(reqInfo->filename,"r"))){
	log_reason(reqInfo, "File permissions deny server access",
		   reqInfo->filename);
        freeString(input);
        freeString(def);
        freeString(szPoint);
        freeString(url);
        freeString(type);
	die(reqInfo, SC_FORBIDDEN, reqInfo->url);
    }

    while (!Found && fgets(input,HUGE_STRING_LEN,fp)) {
        char num[10];

        /* Skip lines with # as comments and blank lines */
        if((input[0] == '#') || (!input[0]))
            continue;

        type[0] = '\0';url[0] = '\0';

        /* Copy the shape keyword into type */
        for(i=0;!isspace(input[i]) && (input[i]);i++)
            type[i] = input[i];
        type[i] = '\0';

        /* Forward to next word */
        while(isspace(input[i])) ++i;

        /* If no coordinates, must be url for default, or NCSA format  */
	if (input[i] != '(') {
          for(j=0;input[i] && !isspace(input[i]);++i,++j)
            url[j] = input[i];
          url[j] = '\0';
        }

	/* Handle default keyword */
        if(!strcmp(type,"default") && !sawpoint) {
            strcpy(def,url);
            continue;
        }

        /* Looking for Coordinates */
        k=0;
        while (input[i]) {
	    /* Move over spaces and commas */
            while (isspace(input[i]) || input[i] == ',')
                i++;
	    
	    /* Under CERN, coordinates are in parenthesis */
            if (input[i] == '(') {
                sawparen = 1;
                while (isspace(input[++i]));
            }

            /* Copy digits into num array */
            j = 0;
            while (isdigit(input[i]))
                num[j++] = input[i++];

            num[j] = '\0';
            if (!j) break;
            pointarray[k][X] = (double) atoi(num);

            /* Skip to next digit */
            while (isspace(input[i]) || input[i] == ',')
                i++;
            /* Copy other number into num */
            j = 0;
            while (isdigit(input[i]))
                num[j++] = input[i++];
            num[j] = '\0';

            if (!j && !sawparen && k > 0) {
              pointarray[k++][Y] = -127;
              break;
            }
  
            if (j)
                pointarray[k++][Y] = (double) atoi(num);
            else {
		error_num = IMAP_ERR_INCORRECT_COORDS;
	        FClose(fp);
		goto imagemap_error;
            }
            
            /* End of parenthesis for coordinates under CERN */
            if (input[i] == ')') {
	      i++;
	      sawparen = 0;
	    } else if (sawparen) {
	      error_num = IMAP_ERR_CERN_MISSING_RIGHT_PAREN;
              FClose(fp);
              goto imagemap_error;	
	    }
        }
        if (url[0] == '\0' && input[i]) {
          while (isspace(input[i])) i++;
          for (j = 0; input[i] && !isspace(input[i]); ++i, ++j)
             url[j] = input[i];
          url[j] = '\0';
        }
        pointarray[k][X] = -1;
        if(!strncmp(type, "poly", 4))
            if(pointinpoly(testpoint,pointarray))
	       Found = 1;
        if(!strncmp(type, "circ", 4))
            if(pointincircle(testpoint,pointarray))
	      Found = 1;
        if(!strncmp(type, "rect", 4))
            if(pointinrect(testpoint,pointarray))
	      Found = 1;
        if(!strcmp(type,"point")) {
	    /* Don't need to take square root. */
	    dist = ((testpoint[X] - pointarray[0][X])
		    * (testpoint[X] - pointarray[0][X]))
		   + ((testpoint[Y] - pointarray[0][Y])
		      * (testpoint[Y] - pointarray[0][Y]));
	    /* If this is the first point, or the nearest, set the default. */
	    if ((! sawpoint) || (dist < mindist)) {
		mindist = dist;
	        strcpy(def,url);
	    }
	    sawpoint++;
	}
    }
    if(Found) {
      sendmesg(reqInfo, url, fp);
      goto imagemap_ok;
    } else {
      if(def[0]) {
        sendmesg(reqInfo, def, fp);
	goto imagemap_ok;
      }
    }
/* No reason to log each of these as an "error" */
/*    log_reason(reqInfo, "No default defined in imagemap.",
	       reqInfo->filename); */
    FClose(fp);
    freeString(input);
    freeString(def);
    freeString(szPoint);
    freeString(url);
    freeString(type);
    die(reqInfo, SC_NO_CONTENT, reqInfo->url);
    return 0;
 
 imagemap_ok:
    FClose(fp);
    freeString(input);
    freeString(def);
    freeString(szPoint);
    freeString(url);
    freeString(type);
    return 1;
 
 imagemap_error:
   freeString(input);
   freeString(def);
   freeString(szPoint);
   freeString(url);
   freeString(type);
   log_reason(reqInfo,imagemap_errors[error_num-1],reqInfo->filename);
   die(reqInfo,SC_BAD_IMAGEMAP,imagemap_errors[error_num-1]);
   return -1;
}
Ejemplo n.º 4
0
void MakeXMLNet(char * buffer)
{
    int i=0,j=0;
    char type[20];// = (char *)malloc(sizeof(char));
    char typecon[10];// = (char *)malloc(sizeof(char));
    char prot[10];// = (char *)malloc(sizeof(char));
    char timespamp[30];// = (char *)malloc(sizeof(char));
    char id[20] ;// = (char *)malloc(sizeof(char));
    char pid[8] ;// = (char *)malloc(sizeof(char));
    char ppid[8];// = (char *)malloc(sizeof(char));
    char scontext[500] ;//= (char *)malloc(sizeof(char));
    char name[1024] ;//= (char *)malloc(sizeof(char));
    char retour[15] ;//= (char *)ma
    char size[100];
    char temp[20];
    char   buffer_final[5096];
    TCPInfo tcp;
    UDPInfo udp;

    if(strstr(buffer,"endoftrace") == NULL)
        return;
    ZeroMemory(buffer_final, sizeof(buffer_final));
    ZeroMemory(typecon, sizeof(typecon));
    ZeroMemory(type, sizeof(type));
    ZeroMemory(prot, sizeof(prot));
    ZeroMemory(timespamp, sizeof(timespamp));
    ZeroMemory(id  , sizeof(id));
    ZeroMemory(ppid, sizeof(ppid));
    ZeroMemory(pid, sizeof(pid));
    ZeroMemory(name, sizeof(name));
    ZeroMemory(temp, sizeof(temp));
    ZeroMemory(scontext, sizeof(scontext));
    ZeroMemory(retour, sizeof(retour));
    ZeroMemory(size, sizeof(size));

//audit(129412850090651712,1) pid=3384 name=iexplore.exe ppid=3308 { send } size=16 prot=tcp return=0 endoftrace
    while(i < (int)strlen(buffer))
    {
        while(buffer[i] != '(') i++;
        i++;
        j=0;
        while(buffer[i] != ',') // get timestamp
        {
            timespamp[j] = buffer[i];
            i++;
            j++;
        }
        timespamp[j]='\0';
        i++;
        j=0;
        while(buffer[i] != ')')// get id
        {
            id[j]=buffer[i];
            i++;
            j++;
        }
        id[j]='\0';
        while(buffer[i] != '=') i++;
        j=0;
        i++;
         while(buffer[i] != ' ') // get pid
        {
            pid[j]=buffer[i];
            i++;
            j++;
        }
        pid[j]='\0';
        while(buffer[i] != '=') i++;
        j=0;
        i++;
         while(buffer[i] != ' ') // get name
        {
            name[j]=buffer[i];
            i++;
            j++;
        }
        name[j]='\0';
        while(buffer[i] != '=') i++;
        j=0;
        i++;
        while(buffer[i] != ' ') // get pid
        {
            ppid[j]=buffer[i];
            i++;
            j++;
        }
        ppid[j]='\0';
        while(buffer[i] != '{') i++;
        j=0;
        i++;
        i++;
        while(buffer[i] != ' ') // get rights
        {
            typecon[j]=buffer[i];
            i++;
            j++;
        }
        typecon[j]='\0';
        while(buffer[i] != '=') i++;
        j=0;
        i++;
        while(buffer[i] != ' ') // get rights
        {
            size[j]=buffer[i];
            i++;
            j++;
        }
        size[j]='\0';
        while(buffer[i] != '=') i++;
        j=0;
        i++;
        while(buffer[i] != ' ') // get rights
        {
            prot[j]=buffer[i];
            i++;
            j++;
        }
        prot[j]='\0';
        while(buffer[i] != '=') i++;
        j=0;
        i++;
        while(buffer[i] != ' ') // get rights
        {
            retour[j]=buffer[i];
            i++;
            j++;
        }
        retour[j]='\0';
        break;
    }
    i=0;
    while(i < 16 )
    {
        if(name[i] == '.')
            break;
        temp[i] = name[i];
        i++;
    }
    sprintf(scontext, "system_u:system_r:%s_t", temp);

    if(strcmp(prot , "tcp") == 0)
    {

        tcp = GetIpTcp(atoi(pid));
        sprintf(buffer_final, "<trace id=\"%s\" timestamp=\"%s\" >\n\t<class type=\"network\" return=\"%s\" />\n\t<process pid=\"%s\" ppid=\"%s\" scontext=\"%s\" name=\"%s\" />\n\t<ip ipsource=\"%s\" portsource=\"%i\" ipdest=\"%s\" portdest=\"%i\" state=\"%s\" typeconnect=\"%s\" size=\"%s\" prot=\"%s\" />\n\t<data>\n\t</data>\n</trace>\n", \
                id, timespamp, retour, pid, ppid, scontext, name, tcp.localip, tcp.localport, tcp.distip, tcp.distport, tcp.state, typecon,size, prot);//
    }

    if(strcmp(prot, "udp") == 0)
    {
        udp = GetUdpInfo(atoi(pid));
        sprintf(buffer_final, "<trace id=\"%s\" timestamp=\"%s\" >\n\t<class type=\"network\" return=\"%s\" />\n\t<process pid=\"%s\" ppid=\"%s\" scontext=\"%s\" name=\"%s\" />\n\t<ip ipsource=\"%s\" portsource=\"%i\" ipdest=\"0\" portdest=\"0\" state=\"NONE\" typeconnect=\"%s\" size=\"%s\" prot=\"%s\" />\n\t<data>\n\t</data>\n</trace>\n", \
                id, timespamp, retour, pid, ppid, scontext, name, udp.localip, udp.localport,  typecon,size, prot);//
    }
 printf("%s\n", buffer_final);
//    printf("%s\n", buffer_final);
  sendmesg(buffer_final);
}
Ejemplo n.º 5
0
void MakeXML(char * buffer)
{
    int i=0,j=0;
    char type[20];// = (char *)malloc(sizeof(char));
    char droit[200];// = (char *)malloc(sizeof(char));
    char timespamp[30];// = (char *)malloc(sizeof(char));
    char id[20] ;// = (char *)malloc(sizeof(char));
    char pid[8] ;// = (char *)malloc(sizeof(char));
    char ppid[8];// = (char *)malloc(sizeof(char));
    char scontext[500] ;//= (char *)malloc(sizeof(char));
    char name[1024] ;//= (char *)malloc(sizeof(char));
    char tcontext[1024] ;// = (char *)malloc(sizeof(char));
    char objname[1024] ;//= (char *)malloc(sizeof(char));
    char retour[10] ;//= (char *)ma
    char size[100];


    char   buffer_final[5096];

    if(strstr(buffer,"endoftrace") == NULL)
        return;
    ZeroMemory(buffer_final, sizeof(buffer_final));
    ZeroMemory(droit, sizeof(droit));
    ZeroMemory(type, sizeof(type));
    ZeroMemory(timespamp, sizeof(timespamp));
    ZeroMemory(id  , sizeof(id));
    ZeroMemory(ppid, sizeof(ppid));
    ZeroMemory(pid, sizeof(pid));
    ZeroMemory(name, sizeof(name));
    ZeroMemory(objname, sizeof(objname));
    ZeroMemory(scontext, sizeof(scontext));
    ZeroMemory(tcontext, sizeof(tcontext));
    ZeroMemory(retour, sizeof(retour));
    ZeroMemory(size, sizeof(size));

    while(i < (int)strlen(buffer))
    {
        while(buffer[i] != '(') i++;
        i++;
        j=0;
        while(buffer[i] != ',') // get timestamp
        {
            timespamp[j] = buffer[i];
            i++;
            j++;
        }
        timespamp[j]='\0';
        i++;
        j=0;
        while(buffer[i] != ')')// get id
        {
            id[j]=buffer[i];
            i++;
            j++;
        }
        id[j]='\0';
        while(buffer[i] != '{') i++;
        j=0;
        i++;
        while(buffer[i] != '}') // get rights
        {
            droit[j]=buffer[i];
            i++;
            j++;
        }
        droit[j]='\0';
        while(buffer[i] != '=') i++;
        j=0;
        i++;
        while(buffer[i] != ' ') // get pid
        {
            pid[j]=buffer[i];
            i++;
            j++;
        }
        pid[j]='\0';
        while(buffer[i] != '"') i++;
        i++;
        j=0;
        while(buffer[i] != '"') // get name
        {
            name[j]=buffer[i];
            i++;
            j++;
        }
        name[j]='\0';
        while(buffer[i] != '=') i++;
        j=0;
        i++;
        while(buffer[i] != ' ') // get pid
        {
            ppid[j]=buffer[i];
            i++;
            j++;
        }
        ppid[j]='\0';
        while(buffer[i] != '"') i++;
        i++;
        j=0;
        while(buffer[i] != '"') // get objname
        {
            objname[j]=buffer[i];
            i++;
            j++;
        }
        objname[j]='\0';
        while(buffer[i] != '=') i++;
        j=0;
        i++;
        while(buffer[i] != ' ') // get scontext
        {
            scontext[j]=buffer[i];
            i++;
            j++;
        }
        scontext[j]='\0';
        while(buffer[i] != '=') i++;
        j=0;
        i++;
        while(buffer[i] != ' ') // get tcontext
        {
            tcontext[j]=buffer[i];
            i++;
            j++;
        }
        tcontext[j]='\0';
        while(buffer[i] != '=') i++;
        j=0;
        i++;
        while(buffer[i] != ' ') // get type
        {
            type[j]=buffer[i];
            i++;
            j++;
        }
        type[j]='\0';
        while(buffer[i] != '=') i++;
        j=0;
        i++;
        while(buffer[i] != ' ') // get retour
        {
            retour[j]=buffer[i];
            i++;
            j++;
        }
        retour[j]='\0';
        while(buffer[i] != '=') i++;
        j=0;
        i++;
        //break;
        while(buffer[i] != ' ') // get retour
        {
            size[j]=buffer[i];
            i++;
            j++;
        }
        size[j]='\0';
        break;
    }

    sprintf(buffer_final, "<trace id=\"%s\" timestamp=\"%s\" >\n\t<class type=\"%s\" return=\"%s\" />\n\t<process pid=\"%s\" ppid=\"%s\" scontext=\"%s\" name=\"%s\" />\n\t<object name=\"%s\" tcontext=\"%s\" rights=\"%s\" size=\"%s\" />\n\t<data>\n\t</data>\n</trace>\n", id, timespamp, type, retour, pid, ppid, scontext,name,objname, tcontext, droit, size);
printf("%s\n", buffer_final);
  sendmesg(buffer_final);
}