Example #1
0
static int sel_comp(str* res, select_t* s, sip_msg_t* msg)
{
	int i, local = 0, issuer = 0;
	int nid = NID_commonName;

	for(i = 1; i <= s->n - 1; i++) {
		switch(s->params[i].v.i) {
		case CERT_LOCAL:   local = 1;                        break;
		case CERT_PEER:    local = 0;                        break;
		case CERT_SUBJECT: issuer = 0;                       break;
		case CERT_ISSUER:  issuer = 1;                       break;
		case COMP_CN:      nid = NID_commonName;             break;
		case COMP_O:       nid = NID_organizationName;       break;
		case COMP_OU:      nid = NID_organizationalUnitName; break;
		case COMP_C:       nid = NID_countryName;            break;
		case COMP_ST:      nid = NID_stateOrProvinceName;    break;
		case COMP_L:       nid = NID_localityName;           break;
		default:
			BUG("Bug in sel_comp: %d\n", s->params[s->n - 1].v.i);
			return -1;
		}
	}

	return get_comp(res, local, issuer, nid, msg);
}
Example #2
0
void inst_book(char *student_id) {
  int c;
  char buff[100];
  struct tm tim;
  time_t now= time(0);
  
  tim= *(localtime(&now));
  strftime (buff, 100, "%d/%m/%Y %H:%M:%S", &tim);
  initscr();
  mvprintw(0,40,buff);
  
  c= get_comp(student_id,tim.tm_hour,tim.tm_min,1);
  if(c==0)
    mvprintw(9,10,"Sorry! All computers booked at the moment");
  else {
    tim.tm_hour ++;
    strftime (buff, 100, "%d/%m/%Y %H:%M:%S", &tim);
    mvprintw(9,10,"Successfully booked comp_id = %d under user_id \"%s\"\n\t\tuptill %s",c,student_id,buff);
  }
  refresh();
  if(!get_confirm())
    return;
  if(c!=0)
    update_file(c,student_id,tim.tm_hour-1,tim.tm_min,1);
}
Example #3
0
static int pv_comp(sip_msg_t* msg, pv_param_t* param, pv_value_t* res)
{
    int ind_local, local = 0, issuer = 0, nid = NID_commonName;

    /* copy callback value as we modify it */
    ind_local = param->pvn.u.isname.name.n;
    DBG("ind_local = %x", ind_local);

    if (ind_local & PV_CERT_PEER) {
        local = 0;
        ind_local = ind_local ^ PV_CERT_PEER;
    } else if (ind_local & PV_CERT_LOCAL) {
        local = 1;
        ind_local = ind_local ^ PV_CERT_LOCAL;
    } else {
        BUG("could not determine certificate\n");
        return pv_get_null(msg, param, res);
    }

    if (ind_local & PV_CERT_SUBJECT) {
        issuer = 0;
        ind_local = ind_local ^ PV_CERT_SUBJECT;
    } else if (ind_local & PV_CERT_ISSUER) {
        issuer = 1;
        ind_local = ind_local ^ PV_CERT_ISSUER;
    } else {
        BUG("could not determine subject or issuer\n");
        return pv_get_null(msg, param, res);
    }

    switch(ind_local) {
    case PV_COMP_CN:
        nid = NID_commonName;
        break;
    case PV_COMP_O:
        nid = NID_organizationName;
        break;
    case PV_COMP_OU:
        nid = NID_organizationalUnitName;
        break;
    case PV_COMP_C:
        nid = NID_countryName;
        break;
    case PV_COMP_ST:
        nid = NID_stateOrProvinceName;
        break;
    case PV_COMP_L:
        nid = NID_localityName;
        break;
    default:
        nid = NID_undef;
    }

    if (get_comp(&res->rs, local, issuer, nid, msg) < 0) {
        return pv_get_null(msg, param, res);
    }

    res->flags = PV_VAL_STR;
    return 0;
}
Example #4
0
void insert_comp (Comp eqn)
{//inserts an comp in rep and parse trees
    LOG_DEBUG1( "O: inserting comp Ob" )
    Ob cmp = get_comp(eqn);Assert3(!isDepricated(cmp), "insert_comp: bad comp");
    Ob lhs = get_lhs(eqn); Assert3(!isDepricated(lhs), "insert_comp: bad lhs");
    Ob rhs = get_rhs(eqn); Assert3(!isDepricated(rhs), "insert_comp: bad rhs");

    //update bool properties
    cmp(BOOL_PROPERTIES) |= STRUCTURAL & lhs(BOOL_PROPERTIES)
                                       & rhs(BOOL_PROPERTIES);
}
Example #5
0
const typet &control_runtime_array_size_type(const symbol_tablet &st)
{
  const char * const name=CEGIS_CONTROL_A_SIZE_MEMBER_NAME;
  const struct_typet::componentt &c=get_comp(st, name);
  return c.type();
}
Example #6
0
const typet &control_array_size_type(const symbol_tablet &st)
{
  const struct_typet::componentt &c=get_comp(st, CEGIS_CONTROL_A_MEMBER_NAME);
  return to_array_type(c.type()).size().type();
}
Example #7
0
uint8_t SkMasks::getAlpha(uint32_t pixel) const {
    return get_comp(pixel, fAlpha.mask, fAlpha.shift, fAlpha.size);
}
Example #8
0
uint8_t SkMasks::getBlue(uint32_t pixel) const {
    return get_comp(pixel, fBlue.mask, fBlue.shift, fBlue.size);
}
Example #9
0
uint8_t SkMasks::getGreen(uint32_t pixel) const {
    return get_comp(pixel, fGreen.mask, fGreen.shift, fGreen.size);
}
Example #10
0
/*
 *
 * Get a color component
 *
 */
uint8_t SkMasks::getRed(uint32_t pixel) const {
    return get_comp(pixel, fRed.mask, fRed.shift, fRed.size);
}
int main(int argc, char **argv)
{
    int ifd;
    uint32_t checksum;
    uint32_t addr;
    uint32_t ep;
    struct stat sbuf;
    unsigned char *ptr;
    char *name = "";

    cmdname = *argv;

    addr = ep = 0;

    while (--argc > 0 && **++argv == '-')
    {
        while (*++*argv)
        {
            switch (**argv)
            {
            case 'l':
                lflag = 1;
                break;
            case 'A':
                if ((--argc <= 0) || (opt_arch = get_arch(*++argv)) < 0)
                    usage();
                goto NXTARG;
            case 'C':
                if ((--argc <= 0) || (opt_comp = get_comp(*++argv)) < 0)
                    usage();
                goto NXTARG;
            case 'O':
                if ((--argc <= 0) || (opt_os = get_os(*++argv)) < 0)
                    usage();
                goto NXTARG;
            case 'T':
                if ((--argc <= 0) || (opt_type = get_type(*++argv)) < 0)
                    usage();
                goto NXTARG;

            case 'a':
                if (--argc <= 0)
                    usage();
                addr = strtoul(*++argv, (char **)&ptr, 16);
                if (*ptr)
                {
                    fprintf(stderr,
                            "%s: invalid load address %s\n",
                            cmdname, *argv);
                    exit(EXIT_FAILURE);
                }
                goto NXTARG;
            case 'd':
                if (--argc <= 0)
                    usage();
                datafile = *++argv;
                dflag = 1;
                goto NXTARG;
            case 'e':
                if (--argc <= 0)
                    usage();
                ep = strtoul(*++argv, (char **)&ptr, 16);
                if (*ptr)
                {
                    fprintf(stderr,
                            "%s: invalid entry point %s\n",
                            cmdname, *argv);
                    exit(EXIT_FAILURE);
                }
                eflag = 1;
                goto NXTARG;
            case 'n':
                if (--argc <= 0)
                    usage();
                name = *++argv;
                goto NXTARG;
            case 'v':
                vflag++;
                break;
            case 'x':
                xflag++;
                break;
            default:
                usage();
            }
        }
NXTARG:
        ;
    }

    if ((argc != 1) || ((lflag ^ dflag) == 0))
        usage();

    if (!eflag)
    {
        ep = addr;
        /* If XIP, entry point must be after the U-Boot header */
        if (xflag)
            ep += sizeof(image_header_t);
    }

    /*
     * If XIP, ensure the entry point is equal to the load address plus
     * the size of the U-Boot header.
     */
    if (xflag)
    {
        if (ep != addr + sizeof(image_header_t))
        {
            fprintf(stderr,
                    "%s: For XIP, the entry point must be the load addr + %lu\n",
                    cmdname, (unsigned long)sizeof(image_header_t));
            exit(EXIT_FAILURE);
        }
    }

    imagefile = *argv;

    if (lflag)
    {
        ifd = open(imagefile, O_RDONLY | O_BINARY);
    }
    else
    {
        ifd =
            open(imagefile, O_RDWR | O_CREAT | O_TRUNC | O_BINARY, 0666);
    }

    if (ifd < 0)
    {
        fprintf(stderr, "%s: Can't open %s: %s\n",
                cmdname, imagefile, strerror(errno));
        exit(EXIT_FAILURE);
    }

    if (lflag)
    {
        int len;
        char *data;
        /*
         * list header information of existing image
         */
        if (fstat(ifd, &sbuf) < 0)
        {
            fprintf(stderr, "%s: Can't stat %s: %s\n",
                    cmdname, imagefile, strerror(errno));
            exit(EXIT_FAILURE);
        }

        if ((unsigned)sbuf.st_size < sizeof(image_header_t))
        {
            fprintf(stderr,
                    "%s: Bad size: \"%s\" is no valid image\n",
                    cmdname, imagefile);
            exit(EXIT_FAILURE);
        }

        ptr = (unsigned char *)mmap(0, sbuf.st_size,
                                    PROT_READ, MAP_SHARED, ifd, 0);
        if ((caddr_t) ptr == (caddr_t) - 1)
        {
            fprintf(stderr, "%s: Can't read %s: %s\n",
                    cmdname, imagefile, strerror(errno));
            exit(EXIT_FAILURE);
        }

        /*
         * create copy of header so that we can blank out the
         * checksum field for checking - this can't be done
         * on the PROT_READ mapped data.
         */
        memcpy(hdr, ptr, sizeof(image_header_t));

        if (ntohl(hdr->ih_magic) != IH_MAGIC)
        {
            fprintf(stderr,
                    "%s: Bad Magic Number: \"%s\" is no valid image\n",
                    cmdname, imagefile);
            exit(EXIT_FAILURE);
        }

        data = (char *)hdr;
        len = sizeof(image_header_t);

        checksum = ntohl(hdr->ih_hcrc);
        hdr->ih_hcrc = htonl(0);        /* clear for re-calculation */

        if (crc32(0, data, len) != checksum)
        {
            fprintf(stderr,
                    "*** Warning: \"%s\" has bad header checksum!\n",
                    imagefile);
        }

        data = (char *)(ptr + sizeof(image_header_t));
        len = sbuf.st_size - sizeof(image_header_t);

        if (crc32(0, data, len) != ntohl(hdr->ih_dcrc))
        {
            fprintf(stderr,
                    "*** Warning: \"%s\" has corrupted data!\n",
                    imagefile);
        }

        /* for multi-file images we need the data part, too */
        print_header((image_header_t *) ptr);

        (void)munmap((void *)ptr, sbuf.st_size);
        (void)close(ifd);

        exit(EXIT_SUCCESS);
    }

    /*
     * Must be -w then:
     *
     * write dummy header, to be fixed later
     */
    memset(hdr, 0, sizeof(image_header_t));

    if (write(ifd, hdr, sizeof(image_header_t)) != sizeof(image_header_t))
    {
        fprintf(stderr, "%s: Write error on %s: %s\n",
                cmdname, imagefile, strerror(errno));
        exit(EXIT_FAILURE);
    }

    if (opt_type == IH_TYPE_MULTI || opt_type == IH_TYPE_SCRIPT)
    {
        char *file = datafile;
        unsigned long size;

        for (;;)
        {
            char *sep = NULL;

            if (file)
            {
                if ((sep = strchr(file, ':')) != NULL)
                {
                    *sep = '\0';
                }

                if (stat(file, &sbuf) < 0)
                {
                    fprintf(stderr, "%s: Can't stat %s: %s\n",
                            cmdname, file, strerror(errno));
                    exit(EXIT_FAILURE);
                }
                size = htonl(sbuf.st_size);
            }
            else
            {
                size = 0;
            }

            if (write(ifd, (char *)&size, sizeof(size)) != sizeof(size))
            {
                fprintf(stderr, "%s: Write error on %s: %s\n",
                        cmdname, imagefile, strerror(errno));
                exit(EXIT_FAILURE);
            }

            if (!file)
            {
                break;
            }

            if (sep)
            {
                *sep = ':';
                file = sep + 1;
            }
            else
            {
                file = NULL;
            }
        }

        file = datafile;

        for (;;)
        {
            char *sep = strchr(file, ':');
            if (sep)
            {
                *sep = '\0';
                copy_file(ifd, file, 1);
                *sep++ = ':';
                file = sep;
            }
            else
            {
                copy_file(ifd, file, 0);
                break;
            }
        }
    }
    else
    {
        copy_file(ifd, datafile, 0);
    }

    /* We're a bit of paranoid */
#if defined(_POSIX_SYNCHRONIZED_IO) && !defined(__sun__) && !defined(__FreeBSD__)
    (void)fdatasync(ifd);
#else
    (void)fsync(ifd);
#endif

    if (fstat(ifd, &sbuf) < 0)
    {
        fprintf(stderr, "%s: Can't stat %s: %s\n",
                cmdname, imagefile, strerror(errno));
        exit(EXIT_FAILURE);
    }

    ptr = (unsigned char *)mmap(0, sbuf.st_size,
                                PROT_READ | PROT_WRITE, MAP_SHARED, ifd,
                                0);
    if (ptr == (unsigned char *)MAP_FAILED)
    {
        fprintf(stderr, "%s: Can't map %s: %s\n",
                cmdname, imagefile, strerror(errno));
        exit(EXIT_FAILURE);
    }

    hdr = (image_header_t *) ptr;

    checksum = crc32(0,
                     (const char *)(ptr + sizeof(image_header_t)),
                     sbuf.st_size - sizeof(image_header_t));

    /* Build new header */
    hdr->ih_magic = htonl(IH_MAGIC);
    hdr->ih_time = htonl(sbuf.st_mtime);
    hdr->ih_size = htonl(sbuf.st_size - sizeof(image_header_t));
    hdr->ih_load = htonl(addr);
    hdr->ih_ep = htonl(ep);
    hdr->ih_dcrc = htonl(checksum);
    hdr->ih_os = opt_os;
    hdr->ih_arch = opt_arch;
    hdr->ih_type = opt_type;
    hdr->ih_comp = opt_comp;

    strncpy((char *)hdr->ih_name, name, IH_NMLEN);

    checksum = crc32(0, (const char *)hdr, sizeof(image_header_t));

    hdr->ih_hcrc = htonl(checksum);

    print_header(hdr);

    (void)munmap((void *)ptr, sbuf.st_size);

    /* We're a bit of paranoid */
#if defined(_POSIX_SYNCHRONIZED_IO) && !defined(__sun__) && !defined(__FreeBSD__)
    (void)fdatasync(ifd);
#else
    (void)fsync(ifd);
#endif

    if (close(ifd))
    {
        fprintf(stderr, "%s: Write error on %s: %s\n",
                cmdname, imagefile, strerror(errno));
        exit(EXIT_FAILURE);
    }

    exit(EXIT_SUCCESS);
}