コード例 #1
0
ファイル: op-adduser.c プロジェクト: jeremyroman/pyceo
static int check_adduser(Ceo__AddUser *in, Ceo__AddUserResponse *out, char *client) {
    int office = check_group(client, "office");
    int syscom = check_group(client, "syscom");

    notice("adding uid=%s cn=%s by %s", in->username, in->realname, client);

    if (!office && !syscom)
        return response_message(out, EPERM, "%s not authorized to create users", client);

    if (!in->username)
        return response_message(out, EINVAL, "missing required argument: username");
    if (!in->realname)
        return response_message(out, EINVAL, "missing required argument: realname");

    switch (in->type) {
    case CEO__ADD_USER__TYPE__MEMBER:
    case CEO__ADD_USER__TYPE__CLUB_REP:
        if (!in->password)
            return response_message(out, EINVAL, "missing required argument: password");
        break;

    case CEO__ADD_USER__TYPE__CLUB:
        if (in->password)
            return response_message(out, EINVAL, "club accounts cannot have passwords");
        if (in->program)
            return response_message(out, EINVAL, "club accounts cannot have programs");
        break;

    default:
        return response_message(out, EINVAL, "invalid user type: %d", in->type);
    }

    if (getpwnam(in->username) != NULL)
        return response_message(out, EEXIST, "user %s already exists", in->username);

    if (getgrnam(in->username) != NULL)
        return response_message(out, EEXIST, "group %s already exists", in->username);

    if (ceo_user_exists(in->username))
        return response_message(out, EEXIST, "user %s already exists in LDAP", in->username);

    if (ceo_group_exists(in->username))
        return response_message(out, EEXIST, "group %s already exists in LDAP", in->username);

    return 0;
}
コード例 #2
0
PUBLIC int MPI_Group_translate_ranks (MPI_Group group1, int n, int *ranks1, MPI_Group group2, int *ranks2)
{
  int i, j;

  check_group (group1, NULL);
  check_group (group2, NULL);

  for (i = 0; i < n; i++)
  {
    void *desired = group1->members[ranks1[i]];
    ranks2[i] = MPI_UNDEFINED;
    for (j = 0; j < group2->size; j++)
      if (desired == group2->members[j])
      {
        ranks2[i] = j;
        break;
      }
  }
}
コード例 #3
0
ファイル: group_size.c プロジェクト: aCaldwell/pftool
PUBLIC int MPI_Group_size (MPI_Group group, int *size)
{
  check_group (group, NULL);
  *size = group->size;
  return MPI_SUCCESS;
}
コード例 #4
0
void desert_water_frontiers(int originx, int originy, int w, int h)
{
    /* copied from connect_transport */
    // sets the correct TYPE depending on neighbours, => gives the correct tile to display
    int mask;
/*
    static const short desert_table[16] = {
        CST_DESERT_0, CST_DESERT_1D, CST_DESERT_1R, CST_DESERT_2RD,
        CST_DESERT_1L, CST_DESERT_2LD, CST_DESERT_2LR, CST_DESERT_3LRD,
        CST_DESERT_1U, CST_DESERT_2UD, CST_DESERT_2RU, CST_DESERT_3RUD,
        CST_DESERT_2LU, CST_DESERT_3LUD, CST_DESERT_3LRU, CST_DESERT
    };

#if FLAG_LEFT != 1 || FLAG_UP != 2 || FLAG_RIGHT != 4 || FLAG_DOWN != 8
#error  desert_frontier(): you loose
#error  the algorithm depends on proper flag settings -- (ThMO)
#endif
*/
    /* Adjust originx,originy,w,h to proper range */
    if (originx <= 0)
    {
        w -= 1 - originx;
        originx = 1;
    }
    if (originy <= 0)
    {
        h -= 1 - originy;
        originy = 1;
    }
    if (originx + w >= world.len())
    {   w = world.len() - originx;}
    if (originy + h >= world.len())
    {   h = world.len() - originy;}

    for (int x = originx; x < originx + w; x++)
    {
        for (int y = originy; y < originy + h; y++)
        {
            if ( world(x, y)->getLowerstVisibleGroup() == GROUP_DESERT)
            {
                mask = 0;
                if ( check_lvgroup(x, y - 1) == GROUP_DESERT )
                {   mask |= 8;}
                if ( check_lvgroup(x - 1, y) == GROUP_DESERT )
                {   mask |= 4;}
                if ( check_lvgroup(x + 1, y) == GROUP_DESERT )
                {   mask |= 2;}
                if ( check_lvgroup(x, y + 1) == GROUP_DESERT )
                {   ++mask;}
                world(x, y)->type = mask;
            }
            else if ( world(x, y)->getLowerstVisibleGroup() == GROUP_WATER)
            {
                mask = 0;
                if (  check_water(x, y - 1)
                  || (check_group(x, y - 1) == GROUP_PORT)  )
                {   mask |= 8;}
                if (  check_water(x - 1, y)
                  || (check_group(x - 1, y) == GROUP_PORT)  )
                {   mask |= 4;}
                if (  check_water(x + 1, y)  )
                {   mask |= 2;}
                if (  check_water(x, y + 1)  )
                {   ++mask;}
                world(x, y)->type = mask;
            }
        }
    }
}
コード例 #5
0
void connect_transport(int originx, int originy, int w, int h)
{
    // sets the correct TYPE depending on neighbours, => gives the correct tile to display
    static const short power_table[16] = {
        0, 1, 0, 2,
        0, 3, 0, 4,
        1, 1, 5, 6,
        7, 8, 9, 10
    };

    static const short table[16] = {
        0, 0, 1, 2,
        0, 0, 3, 4,
        1, 5, 1, 6,
        7, 8, 9, 10
    };

    Construction *cstr = 0;
    /* Adjust originx,originy,w,h to proper range */
    if (originx <= 0)
    {
        originx = 1;
        w -= 1 - originx;
    }
    if (originy <= 0)
    {
        originy = 1;
        h -= 1 - originy;
    }
    if (originx + w >= world.len())
    {   w = world.len() - originx;}
    if (originy + h >= world.len())
    {   h = world.len() - originy;}
    for (int y = originy; y < originy+h; ++y)
    {
        for (int x = originx; x < originx+w; ++x)
        {
            // First, set up a mask according to directions
            cstr = world(x, y)->construction;
            int mask = 0;
            switch (world(x, y)->getGroup())
            {
            case GROUP_POWER_LINE:
            {
                bool far = false;
                int mwh = -1;
                world(x,y)->reportingConstruction->deneighborize();
                /* up -- (ThMO) */
                mwh = world(x, y-1)->reportingConstruction?
                world(x, y-1)->reportingConstruction->tellstuff(Construction::STUFF_MWH, -2):-1;
                if ((far = ((y > 1) && (world(x, y-1)->is_water() || world(x, y-1)->is_transport()))))
                {
                    mwh = world(x, y-2)->reportingConstruction?
                    world(x, y-2)->reportingConstruction->tellstuff(Construction::STUFF_MWH, -2):-1;
                }
                if(mwh != -1)
                {
                    if (far) //suspended cables
                    {
                        //opposite edge
                        if (!world(x, y-2)->reportingConstruction->countPowercables(1))
                        {
                            world(x, y-1)->flags |= FLAG_POWER_CABLES_0;
                            cstr->link_to(world(x,y-2)->reportingConstruction);
                            mask |=8;
                        }
                    }
                    else
                    {
                        cstr->link_to(world(x,y-1)->reportingConstruction);
                        mask |=8;
                    }
                }
                else
                {   world(x, y-1)->flags &= ~FLAG_POWER_CABLES_0;}

                /* left -- (ThMO) */
                mwh = world(x-1, y)->reportingConstruction?
                world(x-1, y)->reportingConstruction->tellstuff(Construction::STUFF_MWH, -2):-1;
                if((far = ((x > 1) && (world(x-1, y)->is_water() || world(x-1, y)->is_transport()))))
                {
                    mwh = world(x-2, y)->reportingConstruction?
                    world(x-2, y)->reportingConstruction->tellstuff(Construction::STUFF_MWH, -2):-1;
                }
                if(mwh != -1)
                {
                    if (far) //suspended cables
                    {
                        //opposite edge
                        if ( !world(x-2, y)->reportingConstruction->countPowercables(2) )
                        {
                            cstr->link_to(world(x-2,y)->reportingConstruction);
                            world(x-1, y)->flags |= FLAG_POWER_CABLES_90;
                            mask |=4;
                        }
                    }
                    else
                    {
                        cstr->link_to(world(x-1,y)->reportingConstruction);
                        mask |=4;
                    }
                }
                else
                {   world(x-1, y)->flags &= ~FLAG_POWER_CABLES_90;}

                /* right -- (ThMO) */
                mwh = world(x+1, y)->reportingConstruction?
                world(x+1, y)->reportingConstruction->tellstuff(Construction::STUFF_MWH, -2):-1;
                if ((far = ((x < world.len() - 2) && (world(x+1, y)->is_water() || world(x+1, y)->is_transport()))))
                {
                    mwh = world(x+2, y)->reportingConstruction?
                    world(x+2, y)->reportingConstruction->tellstuff(Construction::STUFF_MWH, -2):-1;
                }
                if(mwh != -1)
                {
                    if (far) //suspended cables
                    {
                        //opposite edge
                        if ( !world(x+2, y)->reportingConstruction->countPowercables(4) )
                        {
                            cstr->link_to(world(x+2,y)->reportingConstruction);
                            world(x+1, y)->flags |= FLAG_POWER_CABLES_90;
                            mask |=2;
                        }
                    }
                    else
                    {
                        cstr->link_to(world(x+1,y)->reportingConstruction);
                        mask |=2;
                    }
                }
                else
                {   world(x+1, y)->flags &= ~FLAG_POWER_CABLES_90;}

                /* down -- (ThMO) */
                mwh = world(x, y+1)->reportingConstruction?
                world(x, y+1)->reportingConstruction->tellstuff(Construction::STUFF_MWH, -2):-1;
                if ((far = (y < world.len() - 2) && (world(x, y+1)->is_water() || world(x, y+1)->is_transport())))
                {
                    mwh = world(x, y+2)->reportingConstruction?
                    world(x, y+2)->reportingConstruction->tellstuff(Construction::STUFF_MWH, -2):-1;}
                if(mwh != -1)
                {
                    if (far) //suspended cables
                    {
                        //opposite edge
                        if ( !world(x, y+2)->reportingConstruction->countPowercables(8) )
                        {
                            cstr->link_to(world(x,y+2)->reportingConstruction);
                            world(x, y+1)->flags |= FLAG_POWER_CABLES_0;
                            mask |=1;
                        }
                    }
                    else
                    {
                        cstr->link_to(world(x,y+1)->reportingConstruction);
                        mask |=1;
                    }
                }
                else
                {   world(x, y+1)->flags &= ~FLAG_POWER_CABLES_0;}

                cstr->type = power_table[mask];
                break;
            }
            case GROUP_TRACK:
                if (check_group(x, y - 1) == GROUP_TRACK
                ||  check_group(x, y - 1) == GROUP_ROAD
                || (check_group(x, y - 1) == GROUP_RAIL && //rail crossing
                    check_group(x, y - 2) == GROUP_TRACK))
                {   mask |= 2;}
                if (check_group(x - 1, y) == GROUP_TRACK
                ||  check_group(x - 1, y) == GROUP_ROAD
                || (check_group(x - 1, y) == GROUP_RAIL && //rail crossing
                    check_group(x - 2, y) == GROUP_TRACK))
                {   mask |= 1;}

                switch (check_topgroup(x + 1, y))
                {
                    case GROUP_RAIL:
                        if(check_group(x + 2, y) != GROUP_TRACK)
                        {   break;}
                    case GROUP_ROAD:
                    case GROUP_TRACK:
                    case GROUP_TRACK_BRIDGE:
                    case GROUP_COMMUNE:
                    case GROUP_COALMINE:
                    case GROUP_OREMINE:
                    case GROUP_INDUSTRY_L:
                    case GROUP_INDUSTRY_H:
                    case GROUP_RECYCLE:
                    case GROUP_TIP:
                    case GROUP_PORT:
                    case GROUP_COAL_POWER:
                        mask |= 4;
                        break;
                }

                switch (check_topgroup(x, y + 1))
                {
                    case GROUP_RAIL:
                        if(check_group(x, y + 2) != GROUP_TRACK)
                        {   break;}
                    case GROUP_ROAD:
                    case GROUP_TRACK:
                    case GROUP_TRACK_BRIDGE:
                    case GROUP_COMMUNE:
                    case GROUP_COALMINE:
                    case GROUP_OREMINE:
                    case GROUP_INDUSTRY_L:
                    case GROUP_INDUSTRY_H:
                    case GROUP_RECYCLE:
                    case GROUP_TIP:
                    case GROUP_PORT:
                    case GROUP_COAL_POWER:
                        mask |= 8;
                        break;
                }
                // A track section between 2 bridge sections
                // in this special case we use a pillar bridge section with green
                if ((check_group(x, y-1) == GROUP_TRACK_BRIDGE && (
                        check_group(x, y+1) == GROUP_TRACK_BRIDGE || check_group(x, y+2) == GROUP_TRACK_BRIDGE))
                        || (check_group(x, y+1) == GROUP_TRACK_BRIDGE && (
                        check_group(x, y-1) == GROUP_TRACK_BRIDGE || check_group(x, y-2) == GROUP_TRACK_BRIDGE)))
                {   cstr->type = 11;}
                else if ((check_group(x-1, y) == GROUP_TRACK_BRIDGE && (
                        check_group(x+1, y) == GROUP_TRACK_BRIDGE || check_group(x+2, y) == GROUP_TRACK_BRIDGE))
                        || (check_group(x+1, y) == GROUP_TRACK_BRIDGE && (
                        check_group(x-1, y) == GROUP_TRACK_BRIDGE || check_group(x-2, y) == GROUP_TRACK_BRIDGE)))
                {   cstr->type = 12;}
                // Set according bridge entrance if any
                else if (check_group(x, y-1) == GROUP_TRACK_BRIDGE)
                {   cstr->type = 13;}
                else if (check_group(x-1, y) == GROUP_TRACK_BRIDGE)
                {   cstr->type = 14;}
                else if (check_group(x, y+1) == GROUP_TRACK_BRIDGE)
                {   cstr->type = 15;}
                else if (check_group(x+1, y) == GROUP_TRACK_BRIDGE)
                {   cstr->type = 16;}
                else if (check_group(x+1, y) == GROUP_RAIL &&
                         check_group(x-1, y) == GROUP_RAIL &&
                         check_group(x, y+1) == GROUP_TRACK &&
                         check_group(x, y-1) == GROUP_TRACK)
                {
                    railConstructionGroup.placeItem(x,y);
                    cstr = world(x,y)->construction;
                    cstr->type = 21;
                    y = originy;
                }
                else if (check_group(x, y+1) == GROUP_RAIL &&
                         check_group(x, y-1) == GROUP_RAIL &&
                         check_group(x+1, y) == GROUP_TRACK &&
                         check_group(x-1, y) == GROUP_TRACK)
                {
                    railConstructionGroup.placeItem(x,y);
                    cstr = world(x,y)->construction;
                    cstr->type = 22;
                    x = originx;
                }
                else
                {   cstr->type = table[mask];}
                //only brige entrances (and bridges) are transparent
                if (cstr->type >= 11 && cstr->type <= 12)
                {   cstr->flags |= FLAG_TRANSPARENT;}
                else
                {   cstr->flags &= (~FLAG_TRANSPARENT);}
                break;

            case GROUP_TRACK_BRIDGE:
                // Bridge neighbour priority
                if (check_group(x, y-1) == GROUP_TRACK_BRIDGE || check_group(x, y+1) == GROUP_TRACK_BRIDGE
                   || check_group(x, y-1) == GROUP_TRACK || check_group(x, y+1) == GROUP_TRACK)
                {
                    mask |= 2;
                    cstr->type = 0;
                }
                else if (check_group(x-1, y) == GROUP_TRACK_BRIDGE || check_group(x+1, y) == GROUP_TRACK_BRIDGE
                    || check_group(x-1, y) == GROUP_TRACK || check_group(x+1, y) == GROUP_TRACK)
                {
                    mask |= 1;
                    cstr->type = 1;
                }
                else //a lonely bridge tile
                {   cstr->type = 1;}
                cstr->flags |= FLAG_TRANSPARENT;
                break;

            case GROUP_ROAD:
                if (check_group(x, y - 1) == GROUP_ROAD
                ||  check_group(x, y - 1) == GROUP_TRACK
                || (check_group(x, y - 1) == GROUP_RAIL && //rail crossing
                    check_group(x, y - 2) == GROUP_ROAD))
                {   mask |= 2;}
                if (check_group(x - 1, y) == GROUP_ROAD
                ||  check_group(x - 1, y) == GROUP_TRACK
                || (check_group(x - 1, y) == GROUP_RAIL && //rail crossing
                    check_group(x - 2, y) == GROUP_ROAD))
                {   mask |= 1;}

                switch (check_topgroup(x + 1, y))
                {
                    case GROUP_RAIL:
                        if(check_group(x + 2, y) != GROUP_ROAD)
                        {   break;}
                    case GROUP_TRACK:
                    case GROUP_ROAD:
                    case GROUP_COMMUNE:
                    case GROUP_COALMINE:
                    case GROUP_OREMINE:
                    case GROUP_INDUSTRY_L:
                    case GROUP_INDUSTRY_H:
                    case GROUP_RECYCLE:
                    case GROUP_TIP:
                    case GROUP_PORT:
                    case GROUP_COAL_POWER:
                        mask |= 4;
                        break;
                }
                switch (check_topgroup(x, y + 1))
                {
                    case GROUP_RAIL:
                        if(check_group(x, y + 2) != GROUP_ROAD)
                        {   break;}
                    case GROUP_TRACK:
                    case GROUP_ROAD:
                    case GROUP_COMMUNE:
                    case GROUP_COALMINE:
                    case GROUP_OREMINE:
                    case GROUP_INDUSTRY_L:
                    case GROUP_INDUSTRY_H:
                    case GROUP_RECYCLE:
                    case GROUP_TIP:
                    case GROUP_PORT:
                    case GROUP_COAL_POWER:
                        mask |= 8;
                        break;
                }
                // A road section between 2 bridge sections
                // in this special case we use a pillar bridge section with green
                if ((check_group(x, y-1) == GROUP_ROAD_BRIDGE && (
                        check_group(x, y+1) == GROUP_ROAD_BRIDGE || check_group(x, y+2) == GROUP_ROAD_BRIDGE))
                        || (check_group(x, y+1) == GROUP_ROAD_BRIDGE && (
                        check_group(x, y-1) == GROUP_ROAD_BRIDGE || check_group(x, y-2) == GROUP_ROAD_BRIDGE)))
                {   cstr->type = 11;}
                else if ((check_group(x-1, y) == GROUP_ROAD_BRIDGE && (
                        check_group(x+1, y) == GROUP_ROAD_BRIDGE || check_group(x+2, y) == GROUP_ROAD_BRIDGE))
                        || (check_group(x+1, y) == GROUP_ROAD_BRIDGE && (
                        check_group(x-1, y) == GROUP_ROAD_BRIDGE || check_group(x-2, y) == GROUP_ROAD_BRIDGE)))
                {   cstr->type = 12;}
                // Build bridge entrance2
                else if (check_group(x, y-1) == GROUP_ROAD_BRIDGE)
                {   cstr->type = 13;}
                else if (check_group(x-1, y) == GROUP_ROAD_BRIDGE)
                {   cstr->type = 14;}
                else if (check_group(x, y+1) == GROUP_ROAD_BRIDGE)
                {   cstr->type = 15;}
                else if (check_group(x+1, y) == GROUP_ROAD_BRIDGE)
                {   cstr->type = 16;}
                // Build bridge entrance1
                else if (check_group(x, y-2) == GROUP_ROAD_BRIDGE && check_group(x, y-1) == GROUP_ROAD)
                {   cstr->type = 17;}
                else if (check_group(x-2, y) == GROUP_ROAD_BRIDGE && check_group(x-1, y) == GROUP_ROAD)
                {   cstr->type = 18;}
                else if (check_group(x, y+2) == GROUP_ROAD_BRIDGE && check_group(x, y+1) == GROUP_ROAD)
                {   cstr->type = 19;}
                else if (check_group(x+2, y) == GROUP_ROAD_BRIDGE && check_group(x+1, y) == GROUP_ROAD)
                {   cstr->type = 20;}
                else if (check_group(x+1, y) == GROUP_RAIL &&
                         check_group(x-1, y) == GROUP_RAIL &&
                         check_group(x, y+1) == GROUP_ROAD &&
                         check_group(x, y-1) == GROUP_ROAD)
                {
                    railConstructionGroup.placeItem(x,y);
                    cstr = world(x,y)->construction;
                    cstr->type = 23;
                    y = originy;
                }
                else if (check_group(x, y+1) == GROUP_RAIL &&
                         check_group(x, y-1) == GROUP_RAIL &&
                         check_group(x+1, y) == GROUP_ROAD &&
                         check_group(x-1, y) == GROUP_ROAD)
                {
                    railConstructionGroup.placeItem(x,y);
                    cstr = world(x,y)->construction;
                    cstr->type = 24;
                    x = originx;
                }
                else
                {   cstr->type = table[mask];}
                if(cstr->type >= 11 && cstr->type <= 16)
                {   cstr->flags |= FLAG_TRANSPARENT;}
                else
                {   cstr->flags &= (~FLAG_TRANSPARENT);}
                break;

            case GROUP_ROAD_BRIDGE:
                // Bridge neighbour priority
                if (check_group(x, y-1) == GROUP_ROAD_BRIDGE || check_group(x, y+1) == GROUP_ROAD_BRIDGE)
                {   cstr->type = 0;}
                else if (check_group(x-1, y) == GROUP_ROAD_BRIDGE || check_group(x+1, y) == GROUP_ROAD_BRIDGE)
                {   cstr->type = 1;}
                else if (check_group(x, y-1) == GROUP_ROAD || check_group(x, y+1) == GROUP_ROAD)
                {   world(x, y)->construction->type = 0;}//2
                else if (check_group(x-1, y) == GROUP_ROAD || check_group(x+1, y) == GROUP_ROAD)
                {   world(x, y)->construction->type = 1;}//3
                else
                {  cstr->type = 1;}
                cstr->flags |= FLAG_TRANSPARENT;
                break;

            case GROUP_RAIL:
                if (check_group(x, y - 1) == GROUP_RAIL)
                {   mask |= 2;}
                if (check_group(x - 1, y) == GROUP_RAIL)
                {   mask |= 1;}

                switch (check_topgroup(x + 1, y)) {
                    case GROUP_RAIL:
                    case GROUP_COMMUNE:
                    case GROUP_COALMINE:
                    case GROUP_OREMINE:
                    case GROUP_INDUSTRY_L:
                    case GROUP_INDUSTRY_H:
                    case GROUP_RECYCLE:
                    case GROUP_TIP:
                    case GROUP_PORT:
                    case GROUP_COAL_POWER:
                        mask |= 4;
                        break;
                }
                switch (check_topgroup(x, y + 1)) {
                    case GROUP_RAIL:
                    case GROUP_COMMUNE:
                    case GROUP_COALMINE:
                    case GROUP_OREMINE:
                    case GROUP_INDUSTRY_L:
                    case GROUP_INDUSTRY_H:
                    case GROUP_RECYCLE:
                    case GROUP_TIP:
                    case GROUP_PORT:
                    case GROUP_COAL_POWER:
                        mask |= 8;
                        break;
                }
                // A rail section between 2 bridge sections
                // in this special case we use a pillar bridge section with green
                if ((check_group(x, y-1) == GROUP_RAIL_BRIDGE && (
                        check_group(x, y+1) == GROUP_RAIL_BRIDGE || check_group(x, y+2) == GROUP_RAIL_BRIDGE))
                        || (check_group(x, y+1) == GROUP_RAIL_BRIDGE && (
                        check_group(x, y-1) == GROUP_RAIL_BRIDGE || check_group(x, y-2) == GROUP_RAIL_BRIDGE)))
                {   cstr->type = 11;}
                else if ((check_group(x-1, y) == GROUP_RAIL_BRIDGE && (
                        check_group(x+1, y) == GROUP_RAIL_BRIDGE || check_group(x+2, y) == GROUP_RAIL_BRIDGE))
                        || (check_group(x+1, y) == GROUP_RAIL_BRIDGE && (
                        check_group(x-1, y) == GROUP_RAIL_BRIDGE || check_group(x-2, y) == GROUP_RAIL_BRIDGE)))
                {   cstr->type = 12;}
                // Build bridge entrance2
                else if (check_group(x, y-1) == GROUP_RAIL_BRIDGE)
                {   cstr->type = 13;}
                else if (check_group(x-1, y) == GROUP_RAIL_BRIDGE)
                {   cstr->type = 14;}
                else if (check_group(x, y+1) == GROUP_RAIL_BRIDGE)
                {   cstr->type = 15;}
                else if (check_group(x+1, y) == GROUP_RAIL_BRIDGE)
                {   cstr->type = 16;}
                // Build bridge entrance1
                else if (check_group(x, y-2) == GROUP_RAIL_BRIDGE && check_group(x, y-1) == GROUP_RAIL)
                {   cstr->type = 17;}
                else if (check_group(x-2, y) == GROUP_RAIL_BRIDGE && check_group(x-1, y) == GROUP_RAIL)
                {   cstr->type = 18;}
                else if (check_group(x, y+2) == GROUP_RAIL_BRIDGE && check_group(x, y+1) == GROUP_RAIL)
                {   cstr->type = 19;}
                else if (check_group(x+2, y) == GROUP_RAIL_BRIDGE && check_group(x+1, y) == GROUP_RAIL)
                {   cstr->type = 20;}
                //railroad crossings
                else if (check_group(x+1, y) == GROUP_TRACK &&
                         check_group(x-1, y) == GROUP_TRACK)
                {   cstr->type = 22; }
                else if (check_group(x, y+1) == GROUP_TRACK &&
                         check_group(x, y-1) == GROUP_TRACK)
                {   cstr->type = 21; }
                else if (check_group(x+1, y) == GROUP_ROAD &&
                         check_group(x-1, y) == GROUP_ROAD)
                {   cstr->type = 24; }
                else if (check_group(x, y+1) == GROUP_ROAD &&
                         check_group(x, y-1) == GROUP_ROAD)
                {   cstr->type = 23; }

                else
                {   cstr->type = table[mask];}
                if(cstr->type >= 11 && cstr->type <= 16)
                {   cstr->flags |= FLAG_TRANSPARENT;}
                else
                {   cstr->flags &= (~FLAG_TRANSPARENT);}
                break;

            case GROUP_RAIL_BRIDGE:
                // Bridge neighbour priority
                if (check_group(x, y-1) == GROUP_RAIL_BRIDGE || check_group(x, y+1) == GROUP_RAIL_BRIDGE
                   || check_group(x, y-1) == GROUP_RAIL || check_group(x, y+1) == GROUP_RAIL)
                {   cstr->type = 0;}
                else if (check_group(x-1, y) == GROUP_RAIL_BRIDGE || check_group(x+1, y) == GROUP_RAIL_BRIDGE
                    || check_group(x-1, y) == GROUP_RAIL || check_group(x+1, y) == GROUP_RAIL)
                {   cstr->type = 1;}
                else
                {   cstr->type = 1;}
                cstr->flags |= FLAG_TRANSPARENT;
                break;
/*          // now handled by desert_water_frontiers
            case GROUP_WATER:

                if ( ((y > 0) && (world(x, y-1)->getGroup() == GROUP_PORT))
                    || check_water(x, y - 1))
                {   mask |= 8;}

                if ( ((x > 0) && (world(x - 1, y)->getGroup() == GROUP_PORT))
                    || check_water(x - 1, y))
                {   mask |= 4;}

                if (check_water(x + 1, y))
                {   mask |= 2;}

                if (check_water(x, y + 1))
                {   mask |= 1;}

                world(x, y)->type = mask;
                break;
*/
            }                   /* end switch */
        }                       /* end for y*/
    }                           /* end for x*/
}
コード例 #6
0
ファイル: seusers.c プロジェクト: SELinuxProject/selinux
int getseuserbyname(const char *name, char **r_seuser, char **r_level)
{
	FILE *cfg = NULL;
	size_t size = 0;
	char *buffer = NULL;
	int rc;
	unsigned long lineno = 0;
	int mls_enabled = is_selinux_mls_enabled();

	char *username = NULL;
	char *seuser = NULL;
	char *level = NULL;
	char *groupseuser = NULL;
	char *grouplevel = NULL;
	char *defaultseuser = NULL;
	char *defaultlevel = NULL;

	gid_t gid = get_default_gid(name);

	cfg = fopen(selinux_usersconf_path(), "re");
	if (!cfg)
		goto nomatch;

	__fsetlocking(cfg, FSETLOCKING_BYCALLER);
	while (getline(&buffer, &size, cfg) > 0) {
		++lineno;
		rc = process_seusers(buffer, &username, &seuser, &level,
				     mls_enabled);
		if (rc == -1)
			continue;	/* comment, skip */
		if (rc == -2) {
			fprintf(stderr, "%s:  error on line %lu, skipping...\n",
				selinux_usersconf_path(), lineno);
			continue;
		}

		if (!strcmp(username, name))
			break;

		if (username[0] == '%' && 
		    !groupseuser && 
		    check_group(&username[1], name, gid)) {
				groupseuser = seuser;
				grouplevel = level;
		} else {
			if (!defaultseuser && 
			    !strcmp(username, "__default__")) {
				defaultseuser = seuser;
				defaultlevel = level;
			} else {
				free(seuser);
				free(level);
			}
		}
		free(username);
		username = NULL;
		seuser = NULL;
	}

	free(buffer);
	fclose(cfg);

	if (seuser) {
		free(username);
		free(defaultseuser);
		free(defaultlevel);
		free(groupseuser);
		free(grouplevel);
		*r_seuser = seuser;
		*r_level = level;
		return 0;
	}

	if (groupseuser) {
		free(defaultseuser);
		free(defaultlevel);
		*r_seuser = groupseuser;
		*r_level = grouplevel;
		return 0;
	}

	if (defaultseuser) {
		*r_seuser = defaultseuser;
		*r_level = defaultlevel;
		return 0;
	}

      nomatch:
	if (require_seusers)
		return -1;

	/* Fall back to the Linux username and no level. */
	*r_seuser = strdup(name);
	if (!(*r_seuser))
		return -1;
	*r_level = NULL;
	return 0;
}