Example #1
0
/**
 ** GM: TAKE <unit> <int> <itemtype>
 ** requires: permission-key "gmtake"
 **/
static void gm_take(const void *tnext, struct unit *u, struct order *ord)
{
  unit *to = findunit(getid());
  int num = getint();
  const item_type *itype = finditemtype(getstrtoken(), u->faction->locale);

  if (to == NULL || rplane(to->region) != rplane(u->region)) {
    /* unknown or in another plane */
    ADDMSG(&u->faction->msgs, msg_feedback(u, ord, "feedback_unit_not_found",
        ""));
  } else if (itype == NULL || i_get(to->items, itype) == 0) {
    /* unknown or not enough */
    mistake(u, ord, "invalid item or item not found.");
  } else {
    /* checking permissions */
    attrib *permissions = a_find(u->faction->attribs, &at_permissions);
    if (!permissions || !has_permission(permissions, atoi36("gmtake"))) {
      mistake(u, ord, "permission denied.");
    } else {
      int i = i_get(to->items, itype);
      if (i < num)
        num = i;
      if (num) {
        i_change(&to->items, itype, -num);
        i_change(&u->items, itype, num);
      }
    }
  }
}
Example #2
0
/**
 ** GM: TERRAFORM <x> <y> <terrain>
 ** requires: permission-key "gmterf"
 **/
static void gm_terraform(const void *tnext, struct unit *u, struct order *ord)
{
  const struct plane *p = rplane(u->region);
  int x = rel_to_abs(p, u->faction, getint(), 0);
  int y = rel_to_abs(p, u->faction, getint(), 1);
  const char *c = getstrtoken();
  variant token;
  void **tokens = get_translations(u->faction->locale, UT_TERRAINS);
  region *r;
  pnormalize(&x, &y, p);
  r = findregion(x, y);

  if (r == NULL || p != rplane(r)) {
    mistake(u, ord, "region is in another plane.");
    return;
  } else {
    /* checking permissions */
    attrib *permissions = a_find(u->faction->attribs, &at_permissions);
    if (!permissions || !has_permission(permissions, atoi36("gmterf")))
      return;
  }

  if (findtoken(*tokens, c, &token) != E_TOK_NOMATCH) {
    const terrain_type *terrain = (const terrain_type *)token.v;
    terraform_region(r, terrain);
  }
}
Example #3
0
/**
 ** GM: SKILL <unit> <skill> <tage>
 ** requires: permission-key "gmskil"
 **/
static void gm_skill(const void *tnext, struct unit *u, struct order *ord)
{
  unit *to = findunit(getid());
  skill_t skill = findskill(getstrtoken(), u->faction->locale);
  int num = getint();

  if (to == NULL || rplane(to->region) != rplane(u->region)) {
    /* unknown or in another plane */
    ADDMSG(&u->faction->msgs, msg_feedback(u, ord, "feedback_unit_not_found",
        ""));
  } else if (skill == NOSKILL || skill == SK_MAGIC || skill == SK_ALCHEMY) {
    /* unknown or not enough */
    mistake(u, ord, "unknown skill, or skill cannot be raised.");
  } else if (num < 0 || num > 30) {
    /* sanity check failed */
    mistake(u, ord, "invalid value.");
  } else {
    /* checking permissions */
    attrib *permissions = a_find(u->faction->attribs, &at_permissions);
    if (!permissions || !has_permission(permissions, atoi36("gmskil"))) {
      mistake(u, ord, "permission denied.");
    } else {
      set_level(to, skill, num);
    }
  }
}
Example #4
0
/**
 ** GM: KILL FACTION <id> <string>
 ** requires: permission-key "gmmsgr"
 **/
static void gm_killfaction(const void *tnext, struct unit *u, struct order *ord)
{
  int n = getid();
  faction *f = findfaction(n);
  const char *msg = getstrtoken();
  plane *p = rplane(u->region);
  attrib *permissions = a_find(u->faction->attribs, &at_permissions);
  if (!permissions || !has_permission(permissions, atoi36("gmkill"))) {
    mistake(u, ord, "permission denied.");
    return;
  }
  if (f != NULL) {
    region *r;
    for (r = regions; r; r = r->next)
      if (rplane(r) == p) {
        unit *target;
        for (target = r->units; target; target = target->next) {
          if (target->faction == f) {
            scale_number(target, 0);
            ADDMSG(&target->faction->msgs, msg_message("killedbygm",
                "region unit string", r, target, msg));
            return;
          }
        }
      }
  }
  mistake(u, ord, "cannot remove a unit from this faction.");
}
Example #5
0
/**
 ** GM: TELL <unit> <string>
 ** requires: permission-key "gmmsgr"
 **/
static void gm_messageunit(const void *tnext, struct unit *u, struct order *ord)
{
  const struct plane *p = rplane(u->region);
  unit *target = findunit(getid());
  const char *msg = getstrtoken();
  region *r;

  if (target == NULL) {
    ADDMSG(&u->faction->msgs, msg_feedback(u, ord, "feedback_unit_not_found",
        ""));
    return;
  }

  r = target->region;

  if (r == NULL || p != rplane(r)) {
    mistake(u, ord, "region is in another plane.");
  } else {
    /* checking permissions */
    attrib *permissions = a_find(u->faction->attribs, &at_permissions);
    if (!permissions || !has_permission(permissions, atoi36("gmmsgu"))) {
      mistake(u, ord, "permission denied.");
    } else {
      add_message(&target->faction->msgs,
        msg_message("regionmessage", "region sender string", r, u, msg));
    }
  }
}
Example #6
0
static void
gm_messagefaction(const void *tnext, struct unit *gm, struct order *ord)
{
  int n = getid();
  faction *f = findfaction(n);
  const char *msg = getstrtoken();
  plane *p = rplane(gm->region);
  attrib *permissions = a_find(gm->faction->attribs, &at_permissions);
  if (!permissions || !has_permission(permissions, atoi36("gmmsgr"))) {
    mistake(gm, ord, "permission denied.");
    return;
  }
  if (f != NULL) {
    region *r;
    for (r = regions; r; r = r->next)
      if (rplane(r) == p) {
        unit *u;
        for (u = r->units; u; u = u->next)
          if (u->faction == f) {
            add_message(&f->msgs, msg_message("msg_event", "string", msg));
            return;
          }
      }
  }
  mistake(gm, ord, "cannot send messages to this faction.");
}
Example #7
0
/**
 ** GM: TELL PLANE <string>
 ** requires: permission-key "gmmsgr"
 **/
static void gm_messageplane(const void *tnext, struct unit *gm, struct order *ord)
{
  const struct plane *p = rplane(gm->region);
  const char *zmsg = getstrtoken();
  if (p == NULL) {
    mistake(gm, ord, "In diese Ebene kann keine Nachricht gesandt werden.");
  } else {
    /* checking permissions */
    attrib *permissions = a_find(gm->faction->attribs, &at_permissions);
    if (!permissions || !has_permission(permissions, atoi36("gmmsgr"))) {
      mistake(gm, ord, "permission denied.");
    } else {
      message *msg = msg_message("msg_event", "string", zmsg);
      faction *f;
      region *r;
      for (f = factions; f; f = f->next) {
        freset(f, FFL_SELECT);
      }
      for (r = regions; r; r = r->next) {
        unit *u;
        if (rplane(r) != p)
          continue;
        for (u = r->units; u; u = u->next)
          if (!fval(u->faction, FFL_SELECT)) {
            f = u->faction;
            fset(f, FFL_SELECT);
            add_message(&f->msgs, msg);
          }
      }
      msg_release(msg);
    }
  }
}
Example #8
0
/**
 ** GM: TELEPORT <unit> <x> <y>
 ** requires: permission-key "gmtele"
 **/
static void gm_teleport(const void *tnext, struct unit *u, struct order *ord)
{
  const struct plane *p = rplane(u->region);
  unit *to = findunit(getid());
  int x = rel_to_abs(p, u->faction, getint(), 0);
  int y = rel_to_abs(p, u->faction, getint(), 1);
  region *r = findregion(x, y);

  if (r == NULL || p != rplane(r)) {
    mistake(u, ord, "region is in another plane.");
  } else if (to == NULL) {
    ADDMSG(&u->faction->msgs, msg_feedback(u, ord, "feedback_unit_not_found",
        ""));
  } else if (rplane(to->region) != rplane(r) && !ucontact(to, u)) {
    ADDMSG(&u->faction->msgs, msg_feedback(u, ord, "feedback_no_contact",
        "target", to));
  } else {
    /* checking permissions */
    attrib *permissions = a_find(u->faction->attribs, &at_permissions);
    if (!permissions || !has_permission(permissions, atoi36("gmtele"))) {
      mistake(u, ord, "permission denied.");
    } else
      move_unit(to, r, NULL);
  }
}
Example #9
0
/**
 ** GM: GATE <id> <x> <y>
 ** requires: permission-key "gmgate"
 **/
static void gm_gate(const void *tnext, struct unit * u, struct order *ord)
{
  const struct plane *pl = rplane(u->region);
  int id = getid();
  int x = rel_to_abs(pl, u->faction, getint(), 0);
  int y = rel_to_abs(pl, u->faction, getint(), 1);
  building *b = findbuilding(id);
  region *r;

  pnormalize(&x, &y, pl);
  r = findregion(x, y);
  if (b == NULL || r == NULL || pl != rplane(b->region) || pl != rplane(r)) {
    mistake(u, ord, "the unit cannot transform this building.");
    return;
  } else {
    /* checking permissions */
    attrib *permissions = a_find(u->faction->attribs, &at_permissions);
    if (permissions && has_permission(permissions, atoi36("gmgate"))) {
      remove_triggers(&b->attribs, "timer", &tt_gate);
      remove_triggers(&b->attribs, "create", &tt_unguard);
      if (r != b->region) {
        add_trigger(&b->attribs, "timer", trigger_gate(b, r));
        add_trigger(&b->attribs, "create", trigger_unguard(b));
        fset(b, BLD_UNGUARDED);
      }
    }
  }
}
Example #10
0
bool User::can_change_right(AdminRights r, const UserPtr& who) const {
    if (!who || who->removed() || removed()) {
        return false;
    }
    if (who != self() && has_permission(SUPER_RIGHTS_CHANGER)) {
        return false;
    }
    return who->has_permission(SUPER_RIGHTS_CHANGER);
}
Example #11
0
static int sys_write(int fd, char * ptr, int len) {
	if (FD_CHECK(fd)) {
		PTR_VALIDATE(ptr);
		fs_node_t * node = FD_ENTRY(fd);
		if (!has_permission(node, 02)) {
			debug_print(WARNING, "access denied (write, fd=%d)", fd);
			return -EACCES;
		}
		uint32_t out = write_fs(node, node->offset, len, (uint8_t *)ptr);
		node->offset += out;
		return out;
	}
	return -1;
}
Example #12
0
static int sys_open(const char * file, int flags, int mode) {
	PTR_VALIDATE(file);
	debug_print(NOTICE, "open(%s) flags=0x%x; mode=0x%x", file, flags, mode);
	fs_node_t * node = kopen((char *)file, flags);

	if (node && !has_permission(node, 04)) {
		debug_print(WARNING, "access denied (read, sys_open, file=%s)", file);
		return -EACCES;
	}
	if (node && ((flags & O_RDWR) || (flags & O_APPEND) || (flags & O_WRONLY))) {
		if (!has_permission(node, 02)) {
			debug_print(WARNING, "access denied (write, sys_open, file=%s)", file);
			return -EACCES;
		}
	}

	if (!node && (flags & O_CREAT)) {
		/* TODO check directory permissions */
		debug_print(NOTICE, "- file does not exist and create was requested.");
		/* Um, make one */
		int result = create_file_fs((char *)file, mode);
		if (!result) {
			node = kopen((char *)file, flags);
		} else {
			return result;
		}
	}
	if (!node) {
		debug_print(NOTICE, "File does not exist; someone should be setting errno?");
		return -1;
	}
	node->offset = 0;
	int fd = process_append_fd((process_t *)current_process, node);
	debug_print(INFO, "[open] pid=%d %s -> %d", getpid(), file, fd);
	return fd;
}
Example #13
0
/**
 ** GM: TELL REGION <x> <y> <string>
 ** requires: permission-key "gmmsgr"
 **/
static void gm_messageregion(const void *tnext, struct unit *u, struct order *ord)
{
  const struct plane *p = rplane(u->region);
  int x = rel_to_abs(p, u->faction, getint(), 0);
  int y = rel_to_abs(p, u->faction, getint(), 1);
  const char *msg = getstrtoken();
  region *r = findregion(x, y);

  if (r == NULL || p != rplane(r)) {
    mistake(u, ord, "region is in another plane.");
  } else {
    /* checking permissions */
    attrib *permissions = a_find(u->faction->attribs, &at_permissions);
    if (!permissions || !has_permission(permissions, atoi36("gmmsgr"))) {
      mistake(u, ord, "permission denied.");
    } else {
      add_message(&r->msgs, msg_message("msg_event", "string", msg));
    }
  }
}
Example #14
0
int pager_syslog(pid_t pid, void *addr, size_t len) {
	char *message = (char*) malloc(len + 1);

	struct pagetable* page_table = get_page_table(pid);
	int i = 0, m = 0;
	for (i = 0; i < len; i++) {
		// if pid doest not have permission to access addr+i
		// return -1
		if (!has_permission(page_table, (intptr_t) addr + i))
			return -1;
		int page_no =
				get_page_no(
						(void*) (((intptr_t) addr + i)
								& (~(page_table->page_size - 1))));
		int frame = page_table->page_frames[page_no];
		message[m++] = pmem[frame * page_table->page_size + i];
	}
	printf("pager_syslog pid %d %s\n", (int) pid, message);
	return 0;
}
Example #15
0
/**
 ** GM: KILL UNIT <id> <string>
 ** requires: permission-key "gmkill"
 **/
static void gm_killunit(const void *tnext, struct unit *u, struct order *ord)
{
  const struct plane *p = rplane(u->region);
  unit *target = findunit(getid());
  const char *msg = getstrtoken();
  region *r = target->region;

  if (r == NULL || p != rplane(r)) {
    mistake(u, ord, "region is in another plane.");
  } else {
    /* checking permissions */
    attrib *permissions = a_find(u->faction->attribs, &at_permissions);
    if (!permissions || !has_permission(permissions, atoi36("gmkill"))) {
      mistake(u, ord, "permission denied.");
    } else {
      scale_number(target, 0);
      ADDMSG(&target->faction->msgs, msg_message("killedbygm",
          "region unit string", r, target, msg));
    }
  }
}
Example #16
0
static int sys_open(const char * file, int flags, int mode) {
	PTR_VALIDATE(file);
	debug_print(NOTICE, "open(%s) flags=0x%x; mode=0x%x", file, flags, mode);
	fs_node_t * node = kopen((char *)file, flags);

	int access_bits = 0;

	if (node && (flags & O_CREAT) && (flags & O_EXCL)) {
		close_fs(node);
		return -EEXIST;
	}

	if (!(flags & O_WRONLY) || (flags & O_RDWR)) {
		if (node && !has_permission(node, 04)) {
			debug_print(WARNING, "access denied (read, sys_open, file=%s)", file);
			close_fs(node);
			return -EACCES;
		} else {
			access_bits |= 01;
		}
	}

	if ((flags & O_RDWR) || (flags & O_WRONLY)) {
		if (node && !has_permission(node, 02)) {
			close_fs(node);
			return -EACCES;
		}
		if (node && (node->flags & FS_DIRECTORY)) {
			return -EISDIR;
		}
		if ((flags & O_RDWR) || (flags & O_WRONLY)) {
			/* truncate doesn't grant write permissions */
			access_bits |= 02;
		}
	}

	if (!node && (flags & O_CREAT)) {
		/* TODO check directory permissions */
		debug_print(NOTICE, "- file does not exist and create was requested.");
		/* Um, make one */
		int result = create_file_fs((char *)file, mode);
		if (!result) {
			node = kopen((char *)file, flags);
		} else {
			return result;
		}
	}

	if (node && (flags & O_DIRECTORY)) {
		if (!(node->flags & FS_DIRECTORY)) {
			return -ENOTDIR;
		}
	}

	if (node && (flags & O_TRUNC)) {
		if (!(access_bits & 02)) {
			close_fs(node);
			return -EINVAL;
		}
		truncate_fs(node);
	}

	if (!node) {
		return -ENOENT;
	}
	if (node && (flags & O_CREAT) && (node->flags & FS_DIRECTORY)) {
		close_fs(node);
		return -EISDIR;
	}
	int fd = process_append_fd((process_t *)current_process, node);
	FD_MODE(fd) = access_bits;
	if (flags & O_APPEND) {
		FD_OFFSET(fd) = node->length;
	} else {
		FD_OFFSET(fd) = 0;
	}
	debug_print(INFO, "[open] pid=%d %s -> %d", getpid(), file, fd);
	return fd;
}
Example #17
0
bool can_read( char_data* ch, help_data* help )
{
  return has_permission( ch, help->level );
}
Example #18
0
void BuyChipLayer::handle_get_permission(cmd_data_pointer data)
{
    if (GetRoom()->get_group_id() == 0)
    {
        need_credit_ = false;
    }else
    {
        std::shared_ptr<net_data_recv_package> rec = dynamic_pointer_cast<net_data_recv_package>(data);
        if (!check_request(rec)) return;
        auto processor = PM->GetUserPermission_down(rec);
        need_credit_ = true;
        if (processor.has_permission())
        {
            permission_.CopyFrom(processor.permission());
        }else{
            need_credit_ = false;
        }
    }

    auto user = static_pointer_cast<user_texas>(GetRoom()->get_user( GDM->get_user_id()));
    if(user) {
        int buyin_min = GetRoom()->get_buyin_min();
        int buyin_max = GetRoom()->get_buyin_max();
        
        ;//permission_.needcredit();
        if (need_credit_)
        {
            uint32_t credit = permission_.credit();
            
            if (credit < buyin_max)
            {
                buyin_max = credit;
            }
        }
        
        int min_chip = buyin_min - user->get_properties()->chips();
        int max_chip = buyin_max - user->get_properties()->chips();
        
        if (need_credit_ && permission_.credit() < min_chip)
        {
            TipView::showAlertView(tools::local_string("no_credit","信用值不足"));
            this->removeFromParent();
            return;
        }
        
        if (max_chip <= 0)
        {
            TipView::showAlertView(tools::local_string("max_chip", "您的计分牌已经达到极限,不能添加"));
            this->removeFromParent();
            return;
        }
        
        min_chip = std::max(0, min_chip);
        
        text_min_number_->setString(tools::to_string(min_chip));
        text_max_number_->setString(tools::to_string(max_chip));
        text_buy_number_->setString(tools::to_string(min_chip));
    }
    slider_slider_chip(slider_chip_, Slider::EventType::ON_PERCENTAGE_CHANGED);
    this->setVisible(true);
}
Example #19
0
 bool satisfied(const permission_level& permission, uint16_t depth = 0) {
    return has_permission( permission.actor ) ||
           satisfied(permission_to_authority(permission), depth);
 }
Example #20
0
bool User::can_remove(const UserPtr& victim) const {
    return has_permission(USER_REMOVER) && victim &&
           !victim->has_permission(USER_REMOVER) &&
           self() != victim;
}
Example #21
0
bool User::has_permission(Rights perm) const {
    return has_permission(perm, rights());
}
Example #22
0
bool User::has_permission(AdminRights perm) const {
    return has_permission(perm, admin_rights());
}
Example #23
0
void do_write( char_data* ch, char* argument )
{
  char           buf  [ MAX_INPUT_LENGTH ];
  area_data*    area;
  int         number  = 0;
  int          flags;

  if( !get_flags( ch, argument, &flags, "f", "write" ) )
    return;

  if( !strcasecmp( argument, "all" ) ) {
    if( !has_permission( ch, PERM_WRITE_ALL, TRUE ) ) 
      return;
    write_all( is_set( &flags, 0 ) );
    send( ch, "All files written.\r\n" );
    sprintf( buf, "All files written (%s).", ch->descr->name );
    info( "", LEVEL_BUILDER, buf, IFLAG_WRITES, 1, ch );
    return;
    }

  if( fmatches( argument, "areas" ) ) {
    if( !has_permission( ch, PERM_WRITE_AREAS, TRUE ) )
      return;
    for( area = area_list; area != NULL; area = area->next ) 
      number += save_area( area, is_set( &flags, 0 ) );
    if( number > 0 ) {
      send( ch, "All areas written. ( %d file )\r\n", number );
      sprintf( buf, "All areas written (%s).", ch->real_name() );
      info( "", LEVEL_BUILDER, buf, IFLAG_WRITES, 1, ch );
      }
    else {
      send( ch, "No area needed saving.\r\n" );
      }
    return;
    }

  if( fmatches( argument, "rtables" ) ) {
    if( !has_permission( ch, PERM_RTABLES, TRUE ) ) 
      return;
    save_rtables( );
    send( ch, "Rtables written.\r\n" );
    sprintf( buf, "Rtables written (%s).", ch->real_name() );
    info( "", LEVEL_BUILDER, buf, IFLAG_WRITES, 1, ch );
    return;
    }

  if( fmatches( argument, "mobs" ) ) {
    if( !has_permission( ch, PERM_MOBS, TRUE ) )
      return;
    save_mobs( );
    send( ch, "Ok.\r\n" );
    sprintf( buf, "Mob file written (%s).", ch->real_name() );
    info( "", LEVEL_BUILDER, buf, IFLAG_WRITES, 1, ch );
    return;
    }

  if( fmatches( argument, "objects" ) ) {
    if( !has_permission( ch, PERM_OBJECTS, TRUE ) )
      return;
    save_objects( );
    send( ch, "Ok.\r\n" );
    sprintf( buf, "Object file written (%s).", ch->real_name() );
    info( "", LEVEL_BUILDER, buf, IFLAG_WRITES, 1, ch );
    return;
    }

  if( !strcasecmp( argument, "notes" ) ) {
    save_notes( -1 );
    send( ch, "All noteboards written.\r\n" );
    return;
    }

  if( !strcasecmp( argument, "shops" ) ) {
    if( !has_permission( ch, PERM_ROOMS, TRUE ) )
      return;
    save_shops( );
    send( "Ok.\r\n", ch );
    sprintf( buf, "Shop file written (%s).", ch->real_name() );
    info( "", LEVEL_IMMORTAL, buf , IFLAG_WRITES, 1, ch );
    return;
    }

  if( !strcasecmp( argument, "tables" ) ) {
    if( !has_permission( ch, PERM_MISC_TABLES )
      && !has_permission( ch, PERM_SOCIALS, TRUE ) ) 
      return;
    save_tables( );
    send( "Ok.\r\n", ch );
    sprintf( buf, "Table file written (%s).", ch->real_name() );
    info( "", LEVEL_IMMORTAL, buf, IFLAG_WRITES, 1, ch );
    return;
    }

  if( !strcasecmp( argument, "clans" ) ) {
    if( !has_permission( ch, PERM_CLANS, TRUE ) )
      return;
    save_clans( );
    send( ch, "Ok.\r\n" );
    sprintf( buf, "Clan files written (%s).", ch->real_name() );
    info( "", LEVEL_IMMORTAL, buf, IFLAG_WRITES, 1, ch );
    return;
    }

  if( !strcasecmp( argument, "lists" ) ) {
    if( !has_permission( ch, PERM_LISTS, TRUE ) ) 
      return;
    save_lists( );
    send( "Ok.\r\n", ch );
    sprintf( buf, "Table file written (%s).", ch->real_name() );
    info( "", LEVEL_IMMORTAL, buf , IFLAG_WRITES, 1, ch );
    return;
    }

  if( !strcasecmp( argument, "trainers" ) ) {
    if( !IS_IMMORTAL( ch ) ) {
      send( "You don't have permission.", ch );
      return;
      }
    save_trainers( );
    send( "Ok.\r\n", ch );
    sprintf( buf, "Trainer file written (%s).", ch->real_name() );
    info( "", LEVEL_BUILDER, buf, IFLAG_WRITES, 1, ch );
    return;
    }

  if( !strcasecmp( argument, "help" ) ) {
    if( !has_permission( ch, PERM_HELP_FILES, TRUE ) )
      return;
    if( !save_help( ch ) ) 
      send( ch, "Help was not modified so was not saved.\r\n" );
    return;
    }

  if( !strcasecmp( argument, "quests" ) ) {
    if( get_trust( ch ) < LEVEL_QUEST ) {
      send( ch, "You don't have permission." );
      return;
      }
    save_quests( );
    send( ch, "Ok.\r\n" );
    sprintf( buf, "Quest file written (%s).", ch->real_name() );
    info( "", LEVEL_BUILDER, buf, IFLAG_WRITES, 1, ch );
    return;
    }

  if( !strcasecmp( argument, "w3" ) ) {
    w3_help( );
    send( ch, "Webpage Updated.\r\n" );
    return;
    }

  if( *argument != '\0' ) {
    send( ch, "What do you want to write?\r\n" );
    return;
    }

  if( can_edit( ch, ch->in_room ) ) {
    if( !ch->in_room->area->modified ) {
      send( "Area has not been modified so was not saved.\r\n", ch );
      }
    else {
      save_area( ch->in_room->area );
      send( ch, "Area written.\r\n" );
      }
    }
}
Example #24
0
int __fd_open(const char *pathname, int flags, mode_t mode) {
  exe_disk_file_t *df;
  exe_file_t *f;
  int fd;

  for (fd = 0; fd < MAX_FDS; ++fd)
    if (!(__exe_env.fds[fd].flags & eOpen))
      break;
  if (fd == MAX_FDS) {
    errno = EMFILE;
    return -1;
  }
  
  f = &__exe_env.fds[fd];

  /* Should be the case if file was available, but just in case. */
  memset(f, 0, sizeof *f);

  df = __get_sym_file(pathname); 
  if (df) {    
    /* XXX Should check access against mode / stat / possible
       deletion. */
    f->dfile = df;
    
    if ((flags & O_CREAT) && (flags & O_EXCL)) {
      errno = EEXIST;
      return -1;
    }
    
    if ((flags & O_TRUNC) && (flags & O_RDONLY)) {
      /* The result of using O_TRUNC with O_RDONLY is undefined, so we
	 return error */
      klee_warning("Undefined call to open(): O_TRUNC | O_RDONLY\n");
      errno = EACCES;
      return -1;
    }

    if ((flags & O_EXCL) && !(flags & O_CREAT)) {
      /* The result of using O_EXCL without O_CREAT is undefined, so
	 we return error */
      klee_warning("Undefined call to open(): O_EXCL w/o O_RDONLY\n");
      errno = EACCES;
      return -1;
    }

    if (!has_permission(flags, df->stat)) {
	errno = EACCES;
	return -1;
    }
    else
      f->dfile->stat->st_mode = ((f->dfile->stat->st_mode & ~0777) |
				 (mode & ~__exe_env.umask));
  } else {    
    int os_fd = syscall(__NR_open, __concretize_string(pathname), flags, mode);
    if (os_fd == -1)
      return -1;
    f->fd = os_fd;
  }
  
  f->flags = eOpen;
  if ((flags & O_ACCMODE) == O_RDONLY) {
    f->flags |= eReadable;
  } else if ((flags & O_ACCMODE) == O_WRONLY) {
    f->flags |= eWriteable;
  } else { /* XXX What actually happens here if != O_RDWR. */
    f->flags |= eReadable | eWriteable;
  }
  
  return fd;
}