Exemplo n.º 1
0
int NFocus::SendCommand(char *rf_cmd)
{

  int nbytes_written=0, nbytes_read=0, check_ret=0, err_code=0;
  char rf_cmd_cks[32],nfocus_error[MAXRBUF];


  if (isDebug())
  {
   fprintf(stderr, "strlen(rf_cmd) %ld\n", strlen(rf_cmd)) ;
   fprintf(stderr, "WRITE: ") ;
   for(int i=0; i < strlen(rf_cmd); i++)
   {

     fprintf(stderr, "0x%2x ", (unsigned char) rf_cmd[i]) ;
   }
   fprintf(stderr, "\n") ;
  }


  tcflush(PortFD, TCIOFLUSH);

   if  ( (err_code = tty_write(PortFD, rf_cmd, strlen(rf_cmd)+1, &nbytes_written) != TTY_OK))
   {
        tty_error_msg(err_code, nfocus_error, MAXRBUF);
        if (isDebug())
            IDLog("TTY error detected: %s\n", nfocus_error);
        return -1;
   }

   return 0;

}
Exemplo n.º 2
0
bool NFocus::Connect()
{
    int connectrc=0;
    char errorMsg[MAXRBUF];


    if (isDebug())
        IDLog("connecting to %s\n",PortT[0].text);

    if ( (connectrc = tty_connect(PortT[0].text, 9600, 8, 0, 1, &PortFD)) != TTY_OK)
    {
        tty_error_msg(connectrc, errorMsg, MAXRBUF);

        if (isDebug())
            IDLog("Failed to connect o port %s. Error: %s", PortT[0].text, errorMsg);

        IDMessage(getDeviceName(), "Failed to connect to port %s. Error: %s", PortT[0].text, errorMsg);

        return false;

    }


    IDMessage(getDeviceName(), "Nfocus is online. Getting focus parameters...");

    return true;
}
Exemplo n.º 3
0
/**
 * @brief Compare two NFSv4 owners in the hash table
 *
 * @param[in] buff1 One key
 * @param[in] buff2 Another owner
 *
 * @retval 0 on equality.
 * @retval 1 on inequality.
 */
int compare_nfs4_owner_key(struct gsh_buffdesc *buff1,
			   struct gsh_buffdesc *buff2)
{
	state_owner_t *pkey1 = buff1->addr;
	state_owner_t *pkey2 = buff2->addr;

	if (isFullDebug(COMPONENT_STATE) && isDebug(COMPONENT_HASHTABLE)) {
		char str1[HASHTABLE_DISPLAY_STRLEN];
		char str2[HASHTABLE_DISPLAY_STRLEN];

		DisplayOwner(pkey1, str1);
		DisplayOwner(pkey2, str2);

		if (isDebug(COMPONENT_HASHTABLE))
			LogFullDebug(COMPONENT_STATE, "{%s} vs {%s}", str1,
				     str2);
	}

	if (pkey1 == NULL || pkey2 == NULL)
		return 1;

	if (pkey1->so_type != pkey2->so_type)
		return 1;

	return compare_nfs4_owner(pkey1, pkey2);
}
Exemplo n.º 4
0
/**
 * @brief Compare two NFSv4 owners in the hash table
 *
 * @param[in] buff1 One key
 * @param[in] buff2 Another owner
 *
 * @retval 0 on equality.
 * @retval 1 on inequality.
 */
int compare_nfs4_owner_key(struct gsh_buffdesc *buff1,
			   struct gsh_buffdesc *buff2)
{
	state_owner_t *pkey1 = buff1->addr;
	state_owner_t *pkey2 = buff2->addr;

	if (isFullDebug(COMPONENT_STATE) && isDebug(COMPONENT_HASHTABLE)) {
		char str1[LOG_BUFF_LEN / 2] = "\0";
		char str2[LOG_BUFF_LEN / 2] = "\0";
		struct display_buffer dspbuf1 = {sizeof(str1), str1, str1};
		struct display_buffer dspbuf2 = {sizeof(str2), str2, str2};

		display_owner(&dspbuf1, pkey1);
		display_owner(&dspbuf2, pkey2);

		if (isDebug(COMPONENT_HASHTABLE))
			LogFullDebug(COMPONENT_STATE, "{%s} vs {%s}", str1,
				     str2);
	}

	if (pkey1 == NULL || pkey2 == NULL)
		return 1;

	if (pkey1->so_type != pkey2->so_type)
		return 1;

	return compare_nfs4_owner(pkey1, pkey2);
}
Exemplo n.º 5
0
int
vsystem(const char *fmt, ...)
{
    va_list args;
    int pstat;
    pid_t pid;
    int omask;
    sig_t intsave, quitsave;
    char *cmd;
    int i;
    struct stat sb;

    cmd = (char *)alloca(FILENAME_MAX);
    cmd[0] = '\0';
    va_start(args, fmt);
    vsnprintf(cmd, FILENAME_MAX, fmt, args);
    va_end(args);

    omask = sigblock(sigmask(SIGCHLD));
    if (Fake) {
	msgDebug("vsystem:  Faked execution of `%s'\n", cmd);
	return 0;
    }
    if (isDebug())
	msgDebug("Executing command `%s'\n", cmd);
    pid = fork();
    if (pid == -1) {
	(void)sigsetmask(omask);
	i = 127;
    }
    else if (!pid) {	/* Junior */
	(void)sigsetmask(omask);
	if (DebugFD != -1) {
	    dup2(DebugFD, 0);
	    dup2(DebugFD, 1);
	    dup2(DebugFD, 2);
	}
	else {
	    close(1); open("/dev/null", O_WRONLY);
	    dup2(1, 2);
	}
	if (stat("/stand/sh", &sb) == 0)
	    execl("/stand/sh", "/stand/sh", "-c", cmd, (char *)NULL);
	else
	    execl("/bin/sh", "/bin/sh", "-c", cmd, (char *)NULL);
	exit(1);
    }
    else {
	intsave = signal(SIGINT, SIG_IGN);
	quitsave = signal(SIGQUIT, SIG_IGN);
	pid = waitpid(pid, &pstat, 0);
	(void)sigsetmask(omask);
	(void)signal(SIGINT, intsave);
	(void)signal(SIGQUIT, quitsave);
	i = (pid == -1) ? -1 : WEXITSTATUS(pstat);
	if (isDebug())
	    msgDebug("Command `%s' returns status of %d\n", cmd, i);
    }
    return i;
}
Exemplo n.º 6
0
int compare_nfs4_owner_key(hash_buffer_t * buff1, hash_buffer_t * buff2)
{
  if(isFullDebug(COMPONENT_STATE) && isDebug(COMPONENT_HASHTABLE))
    {
      char str1[HASHTABLE_DISPLAY_STRLEN];
      char str2[HASHTABLE_DISPLAY_STRLEN];

      display_nfs4_owner_key(buff1, str1);
      display_nfs4_owner_key(buff2, str2);
      if(isDebug(COMPONENT_HASHTABLE))
        LogFullDebug(COMPONENT_STATE,
                     "{%s} vs {%s}", str1, str2);
    }

  state_nfs4_owner_name_t *pname1 = (state_nfs4_owner_name_t *) buff1->pdata;
  state_nfs4_owner_name_t *pname2 = (state_nfs4_owner_name_t *) buff2->pdata;

  if(pname1 == NULL || pname2 == NULL)
    return 1;

  if(pname1->son_islock != pname2->son_islock)
    return 1;

  if(pname1->son_clientid != pname2->son_clientid)
    return 1;

  if(pname1->son_owner_len != pname2->son_owner_len)
    return 1;

  return memcmp(pname1->son_owner_val, pname2->son_owner_val, pname1->son_owner_len);
}                               /* compare_nfs4_owner */
void TorqueController::executeTorqueControl(hrp::dvector &dq)
{
  int numJoints = m_robot->numJoints();
  hrp::dvector tauMax(numJoints);
  dq.resize(numJoints);

  if (isDebug()) {
    std::cerr << "[" << m_profile.instance_name << "]" << std::endl;
  }
  
  // determine tauMax
  for(int i = 0; i < numJoints; i++) {
    double tauMaxFromModel = m_robot->joint(i)->climit * m_robot->joint(i)->gearRatio * m_robot->joint(i)->torqueConst;
    if ( m_tauMaxIn.data.length() ==  m_robot->numJoints() ) {
      tauMax[i] = std::min(tauMaxFromModel, m_tauMaxIn.data[i]);
    } else {
      tauMax[i] = tauMaxFromModel;
    }
  }

  // execute torque control
  // tauCurrent.length is assumed to be equal to numJoints (check in onExecute)
  if (isDebug()) {
    std::cerr << "tauCurrentIn: ";
    for (int i = 0; i < numJoints; i++) {
      std::cerr << " " << m_tauCurrentIn.data[i];
    }
    std::cerr << std::endl;
    std::cerr << "tauMax: ";
    for (int i = 0; i < numJoints; i++) {
      std::cerr << " " << tauMax[i];
    }
    std::cerr << std::endl;
  }

  Guard guard(m_mutex);
  for (int i = 0; i < numJoints; i++) {
    dq[i] = m_motorTorqueControllers[i].execute(m_tauCurrentIn.data[i], tauMax[i]); // twoDofController: tau = -K(q - qRef)
    // output debug message
    if (isDebug() && m_motorTorqueControllers[i].getMotorControllerState() != MotorTorqueController::INACTIVE) {
      m_motorTorqueControllers[i].printMotorControllerVariables();
    }

  }
    
  if (isDebug()) {
    std::cerr << "dq: ";
    for (int i = 0; i < dq.size(); i++) {
      std::cerr << dq[i] << " ";
    }
    std::cerr << std::endl;
  }

  return;
}
Exemplo n.º 8
0
int NFocus::ReadResponse(char *buf, int nbytes, int timeout)
{

  char nfocus_error[MAXRBUF];
  int bytesRead = 0;
  int totalBytesRead = 0;
  int err_code;

  if (isDebug())
      IDLog("##########################################\n")
;
  while (totalBytesRead < nbytes)
  {
      if ( (err_code = tty_read(PortFD, buf+totalBytesRead, nbytes-totalBytesRead, timeout, &bytesRead)) != TTY_OK)
      {
              tty_error_msg(err_code, nfocus_error, MAXRBUF);
              if (isDebug())
              {
                  IDLog("TTY error detected: %s\n", nfocus_error);
                  IDMessage(getDeviceName(), "TTY error detected: %s\n", nfocus_error);
              }
              return -1;
      }

      if (isDebug())
        IDLog("Bytes Read: %d\n", bytesRead);

      if (bytesRead < 0 )
      {
          if (isDebug())
            IDLog("Bytesread < 1\n");
          return -1;
      }

        totalBytesRead += bytesRead;
    }

    tcflush(PortFD, TCIOFLUSH);

   if (isDebug())
   {
       fprintf(stderr, "READ : (%s,%d), %d\n", buf, 9, totalBytesRead) ;
        fprintf(stderr, "READ : ") ;
        for(int i=0; i < 9; i++)
        {

         fprintf(stderr, "0x%2x ", (unsigned char)buf[i]) ;
        }
        fprintf(stderr, "\n") ;
   }

  return 9;
}
Exemplo n.º 9
0
inline bool decodeStandardEncryption(std::string& dec, const std::string& encryptedPackage, const EncryptionInfo& info, const std::string& pass, std::string secretKey)
{
	const EncryptionHeader& header = info.seHeader;
	const EncryptionVerifier& verifier = info.seVerifier;

	if (secretKey.empty()) {
		if (!verifyStandardEncryption(secretKey, header, verifier, pass)) {
			return false;
		}
	}
	if (isDebug()) {
		printf("secretKey = "); dump(secretKey, false);
	}

	const char *p = encryptedPackage.data();
	size_t decSize = cybozu::Get32bitAsLE(p);
	p += 8;
	const size_t dataSize = encryptedPackage.size();
	if (decSize > dataSize) {
		throw cybozu::Exception("ms:decodeStandardEncryption:bad decSize") << decSize << dataSize;
	}
	const size_t blockSize = 4096;
	dec.reserve(dataSize);
	const size_t n = (dataSize + blockSize - 1) / blockSize;
	const std::string iv;
	for (size_t i = 0; i < n; i++) {
		const size_t len = (i < n - 1) ? blockSize : (dataSize % blockSize);
		dec.append(cipher(header.cipherName, p + i * blockSize, len, secretKey, iv, cybozu::crypto::Cipher::Decoding));
	}
	dec.resize(decSize);
	return true;
}
Exemplo n.º 10
0
uint32_t _9p_owner_value_hash_func(hash_parameter_t * p_hparam,
                                   hash_buffer_t * buffclef)
{
  unsigned int sum = 0;
  unsigned int i;
  unsigned long res;
  state_owner_t *pkey = (state_owner_t *)buffclef->pdata;

  struct sockaddr_in * paddr = (struct sockaddr_in *)&pkey->so_owner.so_9p_owner.client_addr ;

  /* Compute the sum of all the characters */
  for(i = 0; i < pkey->so_owner_len; i++)
    sum += (unsigned char)pkey->so_owner_val[i];

  res = (unsigned long) (pkey->so_owner.so_9p_owner.proc_id)  +
        (unsigned long) paddr->sin_addr.s_addr +
        (unsigned long) sum +
        (unsigned long) pkey->so_owner_len;

  if(isDebug(COMPONENT_HASHTABLE))
    LogFullDebug(COMPONENT_STATE,
                 "value = %lu", res % p_hparam->index_size);

  return (unsigned long)(res % p_hparam->index_size);

}                               
Exemplo n.º 11
0
ClientTerrain::ClientTerrain(const std::string &imageFile, size_t frames,
                             ms_t frameTime)
    : _frames(frames),
      _frame(0),
      _frameTime(frameTime),
      _frameTimer(frameTime) {
  if (_frames == 1)
    _images.push_back(std::string("Images/Terrain/") + imageFile + ".png");
  else
    for (size_t i = 0; i != frames; ++i) {
      std::ostringstream oss;
      oss << "Images/Terrain/" << imageFile;
      // if (_frames > 100 && i < 100)
      //    oss << "0";
      if (_frames > 10 && i < 10) oss << "0";
      oss << i << ".png";
      _images.push_back(oss.str());
    }

  if (!isDebug())
    for (Texture &frame : _images) {
      frame.setBlend(SDL_BLENDMODE_ADD);
      frame.setAlpha(0x3f);
    }
}
Exemplo n.º 12
0
int nfs3_Pathconf(nfs_arg_t * parg,
                  exportlist_t * pexport,
                  fsal_op_context_t * pcontext,
                  cache_inode_client_t * pclient,
                  hash_table_t * ht, struct svc_req *preq, nfs_res_t * pres)
{
  static char __attribute__ ((__unused__)) funcName[] = "nfs3_Pathconf";

  cache_inode_status_t cache_status;
  cache_entry_t *pentry = NULL;
  cache_inode_fsal_data_t fsal_data;
  fsal_attrib_list_t attr;
  fsal_staticfsinfo_t * pstaticinfo = pcontext->export_context->fe_static_fs_info;

  if(isDebug(COMPONENT_NFSPROTO))
    {
      char str[LEN_FH_STR];
      sprint_fhandle3(str, &(parg->arg_pathconf3.object));
      LogDebug(COMPONENT_NFSPROTO,
               "REQUEST PROCESSING: Calling nfs3_Pathconf handle: %s", str);
    }

  /* to avoid setting it on each error case */
  pres->res_pathconf3.PATHCONF3res_u.resfail.obj_attributes.attributes_follow = FALSE;

  /* Convert file handle into a fsal_handle */
  if(nfs3_FhandleToFSAL(&(parg->arg_pathconf3.object), &fsal_data.handle, pcontext) == 0)
    return NFS_REQ_DROP;

  /* Set cookie to zero */
  fsal_data.cookie = DIR_START;

  /* Get the entry in the cache_inode */
  if((pentry = cache_inode_get( &fsal_data,
                                pexport->cache_inode_policy,
                                &attr, 
                                ht, 
                                pclient, 
                                pcontext, 
                                &cache_status)) == NULL)
    {
      /* Stale NFS FH ? */
      pres->res_pathconf3.status = NFS3ERR_STALE;
      return NFS_REQ_OK;
    }

  /* Build post op file attributes */
  nfs_SetPostOpAttr(pcontext, pexport,
                    pentry,
                    &attr, &(pres->res_pathconf3.PATHCONF3res_u.resok.obj_attributes));

  pres->res_pathconf3.PATHCONF3res_u.resok.linkmax = pstaticinfo->maxlink;
  pres->res_pathconf3.PATHCONF3res_u.resok.name_max = pstaticinfo->maxnamelen;
  pres->res_pathconf3.PATHCONF3res_u.resok.no_trunc = pstaticinfo->no_trunc;
  pres->res_pathconf3.PATHCONF3res_u.resok.chown_restricted = pstaticinfo->chown_restricted;
  pres->res_pathconf3.PATHCONF3res_u.resok.case_insensitive = pstaticinfo->case_insensitive;
  pres->res_pathconf3.PATHCONF3res_u.resok.case_preserving = pstaticinfo->case_preserving;

  return NFS_REQ_OK;
}                               /* nfs3_Pathconf */
Exemplo n.º 13
0
void AttributeFilter::ready(PointContext ctx)
{
    m_gdal_debug = std::shared_ptr<pdal::gdal::Debug>(
        new pdal::gdal::Debug(isDebug(), log()));

    for (auto& dim_par : m_dimensions)
    {
        Dimension::Id::Enum t = ctx.findDim(dim_par.first);
        dim_par.second.dim = t;

        if (dim_par.second.isogr)
        {

            OGRDSPtr ds = OGRDSPtr(OGROpen(dim_par.second.datasource.c_str(), 0, 0), OGRDataSourceDeleter());
            if (!ds)
            {
                std::ostringstream oss;
                oss << "Unable to open data source '" << dim_par.second.datasource <<"'";
                throw pdal_error(oss.str());
            }
            dim_par.second.ds = ds;
        }

    }
}
Exemplo n.º 14
0
/**
 * @brief Compare two NFSv4 owners
 *
 * @param[in] owner1 One owner
 * @param[in] owner2 Another owner
 *
 * @retval 0 on equality.
 * @retval 1 on inequality.
 */
int compare_nfs4_owner(state_owner_t *owner1, state_owner_t *owner2)
{
	if (isFullDebug(COMPONENT_STATE) && isDebug(COMPONENT_HASHTABLE)) {
		char str1[LOG_BUFF_LEN / 2];
		char str2[LOG_BUFF_LEN / 2];
		struct display_buffer dspbuf1 = {sizeof(str1), str1, str1};
		struct display_buffer dspbuf2 = {sizeof(str2), str2, str2};

		display_nfs4_owner(&dspbuf1, owner1);
		display_nfs4_owner(&dspbuf2, owner2);
		LogFullDebug(COMPONENT_STATE, "{%s} vs {%s}", str1, str2);
	}

	if (owner1 == NULL || owner2 == NULL)
		return 1;

	if (owner1 == owner2)
		return 0;

	if (owner1->so_type != owner2->so_type)
		return 1;

	if (owner1->so_owner.so_nfs4_owner.so_clientid !=
	    owner2->so_owner.so_nfs4_owner.so_clientid)
		return 1;

	if (owner1->so_owner_len != owner2->so_owner_len)
		return 1;

	return memcmp(owner1->so_owner_val, owner2->so_owner_val,
		      owner1->so_owner_len);
}
Exemplo n.º 15
0
/**
 *
 * nsm_client_Get_Pointer
 *
 * This routine gets a pointer to an NSM client from the nsm_client's hashtable.
 *
 * @param pstate       [IN] pointer to the stateid to be checked.
 * @param ppstate_data [OUT] pointer's state found 
 *
 * @return 1 if ok, 0 otherwise.
 *
 */
int nsm_client_Get_Pointer(state_nsm_client_t * pkey,
                           state_nsm_client_t * *pclient)
{
  hash_buffer_t buffkey;
  hash_buffer_t buffval;

  buffkey.pdata = (caddr_t) pkey;
  buffkey.len = sizeof(*pkey);

  if(isFullDebug(COMPONENT_STATE) && isDebug(COMPONENT_HASHTABLE))
    {
      char str[HASHTABLE_DISPLAY_STRLEN];

      display_nsm_client_key(&buffkey, str);
      LogFullDebug(COMPONENT_STATE,
                   "KEY {%s}", str);
    }

  if(HashTable_GetRef(ht_nsm_client, &buffkey, &buffval, Hash_inc_nsm_client_ref) != HASHTABLE_SUCCESS)
    {
      LogFullDebug(COMPONENT_STATE,
                   "NOTFOUND");
      *pclient = NULL;
      return 0;
    }

  *pclient = (state_nsm_client_t *) buffval.pdata;

  LogFullDebug(COMPONENT_STATE,
               "FOUND");

  return 1;
}                               /* nsm_client_Get_Pointer */
Exemplo n.º 16
0
/**
 * @brief Calculate RBT hash for an NSM key
 *
 * @todo Replace with a good hash function.
 *
 * @param[in]  hparam Hash params
 * @param[out] key    Key to hash
 *
 * @return The RBT hash.
 */
uint64_t nsm_client_rbt_hash_func(hash_parameter_t *hparam,
				  struct gsh_buffdesc *key)
{
	unsigned long res;
	state_nsm_client_t *pkey = key->addr;

	if (nfs_param.core_param.nsm_use_caller_name) {
		unsigned int sum = 0;
		unsigned int i;

		/* Compute the sum of all the characters */
		for (i = 0; i < pkey->ssc_nlm_caller_name_len; i++)
			sum += (unsigned char)pkey->ssc_nlm_caller_name[i];

		res =
		    (unsigned long)sum +
		    (unsigned long)pkey->ssc_nlm_caller_name_len;
	} else {
		res = (unsigned long) pkey->ssc_client;
	}

	if (isDebug(COMPONENT_HASHTABLE))
		LogFullDebug(COMPONENT_STATE, "rbt = %lu", res);

	return res;
}				/* nsm_client_rbt_hash_func */
Exemplo n.º 17
0
/**
 * @brief Compare NSM clients
 *
 * @param[in] client1 A client
 * @param[in] client2 Another client
 *
 * @retval 0 on equality.
 * @retval 1 on inequality.
 */
int compare_nsm_client(state_nsm_client_t *client1,
		       state_nsm_client_t *client2)
{
	if (isFullDebug(COMPONENT_STATE) && isDebug(COMPONENT_HASHTABLE)) {
		char str1[LOG_BUFF_LEN / 2];
		char str2[LOG_BUFF_LEN / 2];
		struct display_buffer dspbuf1 = {sizeof(str1), str1, str1};
		struct display_buffer dspbuf2 = {sizeof(str2), str2, str2};

		display_nsm_client(&dspbuf1, client1);
		display_nsm_client(&dspbuf2, client2);
		LogFullDebug(COMPONENT_STATE, "{%s} vs {%s}", str1, str2);
	}

	if (client1 == NULL || client2 == NULL)
		return 1;

	if (client1 == client2)
		return 0;

	if (!nfs_param.core_param.nsm_use_caller_name) {
		if (client1->ssc_client != client2->ssc_client)
			return 1;
		return 0;
	}

	if (client1->ssc_nlm_caller_name_len !=
	    client2->ssc_nlm_caller_name_len)
		return 1;

	return memcmp(client1->ssc_nlm_caller_name,
		      client2->ssc_nlm_caller_name,
		      client1->ssc_nlm_caller_name_len);
}
// virtual
bool TcpSocketServerImpl::initializeSpecific()
{
  sockFd_ = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
  if(sockFd_ < 0)
  {
    std::cerr << "Error initializing TCP socket" << std::endl;
    return false;
  }

  if(bind(sockFd_, (struct sockaddr *) &serverAddress_, sizeof(struct sockaddr_in)) < 0)
  {
    std::cerr << "Error binding socket" << std::endl;
    return false;
  }

  if(listen(sockFd_, 5) < 0)
  {
    std::cerr << "Error listening on socket" << std::endl;
    return false;
  }

  if(isDebug())
  {
    std::cout << "TCP server successfully bound to port: " << port_;
  }

  return true;
}
Exemplo n.º 19
0
static unsigned int fsal_acl_hash_both(hash_parameter_t * p_hparam,
                                       hash_buffer_t * buffclef, uint32_t * phashval, uint32_t * prbtval)
{
  char printbuf[2 * MD5_DIGEST_LENGTH];
  uint32_t h1 = 0 ;
  uint32_t h2 = 0 ;

  char *p_aclkey = (char *) (buffclef->pdata);

  Lookup3_hash_buff_dual((char *)(p_aclkey), MD5_DIGEST_LENGTH, &h1, &h2);

  h1 = h1 % p_hparam->index_size;

  *phashval = h1 ;
  *prbtval = h2 ;

  if(isDebug(COMPONENT_NFS_V4_ACL))
    {
      snprintmem(printbuf, 2 * MD5_DIGEST_LENGTH, p_aclkey, MD5_DIGEST_LENGTH);
      LogDebug(COMPONENT_NFS_V4_ACL, "p_aclkey=%s, hashvalue=%u, rbtvalue=%u", printbuf, h1, h2);
    }

  /* Success */
  return 1 ;
} /*  fsal_acl_hash_both */
Exemplo n.º 20
0
inline bool getAgileSecretKey(std::string& secretKey, const EncryptionInfo& info, const std::string& pass)
{
	const CipherParam& keyData = info.keyData;
	const CipherParam& encryptedKey = info.encryptedKey;
	const std::string& iv = encryptedKey.saltValue;

	const std::string pwHash = hashPassword(encryptedKey.hashName, iv, pass, info.spinCount);
	const std::string skey1 = generateKey(encryptedKey, pwHash, ms::blkKey_VerifierHashInput);
	const std::string skey2 = generateKey(encryptedKey, pwHash, ms::blkKey_encryptedVerifierHashValue);

	const std::string verifierHashInput = cipher(encryptedKey.cipherName, info.encryptedVerifierHashInput, skey1, iv, cybozu::crypto::Cipher::Decoding);
	const std::string hashedVerifier = cybozu::crypto::Hash::digest(encryptedKey.hashName, verifierHashInput);
	const std::string verifierHash = cipher(encryptedKey.cipherName, info.encryptedVerifierHashValue, skey2, iv, cybozu::crypto::Cipher::Decoding).substr(0, hashedVerifier.size());

	if (hashedVerifier != verifierHash) {
		return false;
	}
	const std::string skey3 = generateKey(encryptedKey, pwHash, ms::blkKey_encryptedKeyValue);
	secretKey = cipher(encryptedKey.cipherName, info.encryptedKeyValue, skey3, iv, cybozu::crypto::Cipher::Decoding);
	if (isDebug()) {
		printf("salt = "); dump(keyData.saltValue, false);
		printf("secretKey = "); dump(secretKey, false);
	}
	return true;
}
Exemplo n.º 21
0
/**
 * nlm_client_Set
 * 
 *
 * This routine sets a NLM client into the related hashtable
 *
 * @return 1 if ok, 0 otherwise.
 *
 */
int nlm_client_Set(state_nlm_client_t * pkey,
                   state_nlm_client_t * pclient)
{
  hash_buffer_t buffkey;
  hash_buffer_t buffval;

  if(isFullDebug(COMPONENT_STATE) && isDebug(COMPONENT_HASHTABLE))
    {
      char str[HASHTABLE_DISPLAY_STRLEN];

      buffkey.pdata = (caddr_t) pkey;
      buffkey.len = sizeof(*pkey);

      display_nlm_client_key(&buffkey, str);
      LogFullDebug(COMPONENT_STATE,
                   "KEY {%s}", str);
    }

  buffkey.pdata = (caddr_t) pkey;
  buffkey.len = sizeof(*pkey);

  buffval.pdata = (caddr_t) pclient;
  buffval.len = sizeof(*pclient);

  if(HashTable_Test_And_Set
     (ht_nlm_client, &buffkey, &buffval,
      HASHTABLE_SET_HOW_SET_NO_OVERWRITE) != HASHTABLE_SUCCESS)
    return 0;

  return 1;
}                               /* nlm_client_Set */
Exemplo n.º 22
0
int MergeKernel::execute()
{
    PointTable table;

    MergeFilter filter;

    for (size_t i = 0; i < m_files.size(); ++i)
    {
        Options readerOpts;
        readerOpts.add("filename", m_files[i]);
        readerOpts.add("debug", isDebug());
        readerOpts.add("verbose", getVerboseLevel());

        Stage& reader = makeReader(m_files[i]);
        reader.setOptions(readerOpts);

        filter.setInput(reader);
    }

    Options writerOpts;

    Stage& writer = makeWriter(m_outputFile, filter);
    applyExtraStageOptionsRecursive(&writer);

    writer.prepare(table);
    writer.execute(table);
    return 0;
}
Exemplo n.º 23
0
/**
 * @brief Compute the RBT hash for an NFSv4 owner
 *
 * @todo Destroy this function and replace it with a real hash.
 *
 * @param[in] hparam Hash parameter
 * @param[in] key    The key
 *
 * @return The RBT hash.
 */
uint64_t nfs4_owner_rbt_hash_func(hash_parameter_t *hparam,
				  struct gsh_buffdesc *key)
{
	state_owner_t *pkey = key->addr;

	unsigned int sum = 0;
	unsigned int i = 0;
	unsigned char c = 0;
	uint64_t res = 0;

	/* Compute the sum of all the characters */
	for (i = 0; i < pkey->so_owner_len; i++) {
		c = ((char *)pkey->so_owner_val)[i];
		sum += c;
	}

	res =
	    (uint64_t) pkey->so_owner.so_nfs4_owner.so_clientid +
	    (uint64_t) sum + pkey->so_owner_len + (uint64_t) pkey->so_type;

	if (isDebug(COMPONENT_HASHTABLE))
		LogFullDebug(COMPONENT_STATE, "rbt = %" PRIu64, res);

	return res;
}
Exemplo n.º 24
0
uint64_t nsm_client_rbt_hash_func(hash_parameter_t * p_hparam,
                                      hash_buffer_t * buffclef)
{
  unsigned long        res;
  state_nsm_client_t * pkey = (state_nsm_client_t *)buffclef->pdata;

  if(nfs_param.core_param.nsm_use_caller_name)
    {
      unsigned int sum = 0;
      unsigned int i;

      /* Compute the sum of all the characters */
      for(i = 0; i < pkey->ssc_nlm_caller_name_len; i++)
        sum +=(unsigned char) pkey->ssc_nlm_caller_name[i];

      res = (unsigned long) sum +
            (unsigned long) pkey->ssc_nlm_caller_name_len;
    }
  else
    {
      res = hash_sockaddr(&pkey->ssc_client_addr, IGNORE_PORT);
    }

  if(isDebug(COMPONENT_HASHTABLE))
    LogFullDebug(COMPONENT_STATE, "rbt = %lu", res);

  return res;
}                               /* nsm_client_rbt_hash_func */
void SoundManager2::loadMusic(const char* filename){
    musicHandle = FSOUND_Sample_Load (musicChannel, filename, 0, 0, 0);
    if(isDebug()){
        printf("Music Loaded on Channel: %i\n", musicChannel);
    }
    //TODO allow loading a dictionary of music and playing them based on a selection
}
Exemplo n.º 26
0
int compare_nlm_client(state_nlm_client_t *pclient1,
                       state_nlm_client_t *pclient2)
{
  if(isFullDebug(COMPONENT_STATE) && isDebug(COMPONENT_HASHTABLE))
    {
      char str1[HASHTABLE_DISPLAY_STRLEN];
      char str2[HASHTABLE_DISPLAY_STRLEN];

      display_nlm_client(pclient1, str1);
      display_nlm_client(pclient2, str2);
      LogFullDebug(COMPONENT_STATE,
                   "{%s} vs {%s}", str1, str2);
    }

  if(pclient1 == NULL || pclient2 == NULL)
    return 1;

  if(pclient1 == pclient2)
    return 0;

  if(compare_nsm_client(pclient1->slc_nsm_client, pclient2->slc_nsm_client) != 0)
    return 1;

  if(pclient1->slc_client_type != pclient2->slc_client_type)
    return 1;

  if(pclient1->slc_nlm_caller_name_len != pclient2->slc_nlm_caller_name_len)
    return 1;

  return memcmp(pclient1->slc_nlm_caller_name,
                pclient2->slc_nlm_caller_name,
                pclient1->slc_nlm_caller_name_len);
}
Exemplo n.º 27
0
uint32_t nfs4_owner_value_hash_func(hash_parameter_t * p_hparam,
                                    hash_buffer_t * buffclef)
{
  unsigned int sum = 0;
  unsigned int i = 0;
  unsigned char c = 0;
  unsigned long res = 0;

  state_nfs4_owner_name_t *pname = (state_nfs4_owner_name_t *) buffclef->pdata;

  /* Compute the sum of all the characters */
  for(i = 0; i < pname->son_owner_len; i++)
    {
      c = ((char *)pname->son_owner_val)[i];
      sum += c;
    }

  res = (unsigned long)(pname->son_clientid) + (unsigned long)sum + pname->son_owner_len + pname->son_islock;

  if(isDebug(COMPONENT_HASHTABLE))
    LogFullDebug(COMPONENT_STATE,
                 "value = %lu", res % p_hparam->index_size);

  return (unsigned long)(res % p_hparam->index_size);

}                               /* nfs4_owner_value_hash_func */
Exemplo n.º 28
0
int compare_nsm_client(state_nsm_client_t *pclient1,
                       state_nsm_client_t *pclient2)
{
  if(isFullDebug(COMPONENT_STATE) && isDebug(COMPONENT_HASHTABLE))
    {
      char str1[HASHTABLE_DISPLAY_STRLEN];
      char str2[HASHTABLE_DISPLAY_STRLEN];

      display_nsm_client(pclient1, str1);
      display_nsm_client(pclient2, str2);
      LogFullDebug(COMPONENT_STATE,
                   "{%s} vs {%s}", str1, str2);
    }

  if(pclient1 == NULL || pclient2 == NULL)
    return 1;

  if(pclient1 == pclient2)
    return 0;

  if(!nfs_param.core_param.nsm_use_caller_name)
    {
      if(cmp_sockaddr(&pclient1->ssc_client_addr, &pclient2->ssc_client_addr, IGNORE_PORT) == 0)
        return 1;
      return 0;
    }

  if(pclient1->ssc_nlm_caller_name_len != pclient2->ssc_nlm_caller_name_len)
    return 1;

  return memcmp(pclient1->ssc_nlm_caller_name,
                pclient2->ssc_nlm_caller_name,
                pclient1->ssc_nlm_caller_name_len);
}
Exemplo n.º 29
0
IPState FocusSim::MoveAbsFocuser(uint32_t targetTicks)
{
    if (targetTicks < FocusAbsPosN[0].min || targetTicks > FocusAbsPosN[0].max)
    {
        IDMessage(getDeviceName(), "Error, requested absolute position is out of range.");
        return IPS_ALERT;
    }

    double mid = (FocusAbsPosN[0].max - FocusAbsPosN[0].min)/2;

    IDMessage(getDeviceName() , "Focuser is moving to requested position...");

    // Limit to +/- 10 from initTicks
    ticks = initTicks + (targetTicks - mid) / 5000.0;

    if (isDebug())
        IDLog("Current ticks: %g\n", ticks);

    // simulate delay in motion as the focuser moves to the new position

    usleep( abs(targetTicks - FocusAbsPosN[0].value) * FOCUS_MOTION_DELAY);

    FocusAbsPosN[0].value = targetTicks;

    FWHMN[0].value = 0.5625*ticks*ticks +  SeeingN[0].value;

    if (FWHMN[0].value < SeeingN[0].value)
        FWHMN[0].value = SeeingN[0].value;

    IDSetNumber(&FWHMNP, NULL);

    return IPS_OK;

}
Exemplo n.º 30
0
bool LX200Autostar::ISNewSwitch(const char *dev, const char *name, ISState *states, char *names[], int n)
{
    int index = 0;

    if (dev != nullptr && strcmp(dev, getDeviceName()) == 0)
    {
        // Focus Motion
        if (!strcmp(name, FocusMotionSP.name))
        {
            // If speed is "halt"
            if (FocusSpeedN[0].value == 0)
            {
                FocusMotionSP.s = IPS_IDLE;
                IDSetSwitch(&FocusMotionSP, nullptr);
                return false;
            }

            int last_motion = IUFindOnSwitchIndex(&FocusMotionSP);

            if (IUUpdateSwitch(&FocusMotionSP, states, names, n) < 0)
                return false;

            index = IUFindOnSwitchIndex(&FocusMotionSP);

            // If same direction and we're busy, stop
            if (last_motion == index && FocusMotionSP.s == IPS_BUSY)
            {
                IUResetSwitch(&FocusMotionSP);
                FocusMotionSP.s = IPS_IDLE;
                setFocuserSpeedMode(PortFD, 0);
                IDSetSwitch(&FocusMotionSP, nullptr);
                return true;
            }

            if (!isSimulation() && setFocuserMotion(PortFD, index) < 0)
            {
                FocusMotionSP.s = IPS_ALERT;
                IDSetSwitch(&FocusMotionSP, "Error setting focuser speed.");
                return false;
            }

            FocusMotionSP.s = IPS_BUSY;

            // with a timer
            if (FocusTimerNP.np[0].value > 0)
            {
                FocusTimerNP.s = IPS_BUSY;
                if (isDebug())
                    IDLog("Starting Focus Timer BUSY\n");

                IEAddTimer(50, LX200Generic::updateFocusHelper, this);
            }

            IDSetSwitch(&FocusMotionSP, nullptr);
            return true;
        }
    }

    return LX200Generic::ISNewSwitch(dev, name, states, names, n);
}