示例#1
0
bool
passwd_cache::init_groups( const char* user, gid_t additional_gid ) {

	gid_t *gid_list;
	bool result;
	int siz;

	siz = num_groups(user);
	result = true;
	gid_list = NULL;

	if ( siz > 0 ) {

		gid_list = new gid_t[siz + 1];

		if ( get_groups(user, siz, gid_list) ) { 

			if (additional_gid != 0) {
				gid_list[siz] = additional_gid;
				siz++;
			}

			if ( setgroups(siz, gid_list) != 0 ) {
				dprintf(D_ALWAYS, "passwd_cache: setgroups( %s ) failed.\n", user);
				result = false;
			} else {
					/* success */
				result = true;			
			}
			
		} else {
			dprintf(D_ALWAYS, "passwd_cache: getgroups( %s ) failed.\n", user);
			result = false;
		}

	} else {
			/* error */
		dprintf(D_ALWAYS,
		        "passwd_cache: num_groups( %s ) returned %d\n",
		        user,
		        siz);
		result = false;
	}

	if ( gid_list ) { delete[] gid_list; }
	return result;
}
示例#2
0
文件: gbm.cpp 项目: RyanMichaluk/gbm
std::auto_ptr<CDistribution> gbm_setup
(
 const CDataset& data,
 const std::string& family,
 int cTrees,
 int cDepth,
 int cMinObsInNode,
 int cNumClasses,
 double dShrinkage,
 double dBagFraction,
 int cTrain,
 int cFeatures,
 int& cGroups
 )
{
  std::auto_ptr<CDistribution> pDist;
  cGroups = -1;
  
    // set the distribution
  if (family == "gamma") {
    pDist.reset(new CGamma());
  } 
  else if (family == "tweedie") {
    pDist.reset(new CTweedie(data.misc_ptr()[0]));
  }
  else if (family == "bernoulli") 
    {
      pDist.reset(new CBernoulli());
    }
  else if (family == "gaussian") 
    {
      pDist.reset(new CGaussian());
    }
  else if (family == "poisson")
    {
      pDist.reset(new CPoisson());
    }
  else if (family == "adaboost")
    {
      pDist.reset(new CAdaBoost());
    }
  else if (family == "coxph")
    {
      pDist.reset(new CCoxPH());
    }
  else if (family == "laplace")
    {
      pDist.reset(new CLaplace());
    }
  else if (family == "quantile")
    {
      pDist.reset(new CQuantile(data.misc_ptr()[0]));
    }
  else if (family == "tdist")
    {
      pDist.reset(new CTDist(data.misc_ptr()[0]));
    }
  else if (family == "multinomial")
    {
      pDist.reset(new CMultinomial(cNumClasses, data.nrow()));
    }
  else if (family == "huberized")
    {
      pDist.reset(new CHuberized());
    }
  else if (family == "pairwise_conc")
    {
      pDist.reset(new CPairwise("conc"));
    }
  else if (family == "pairwise_ndcg")
    {
      pDist.reset(new CPairwise("ndcg"));
    }
  else if (family == "pairwise_map")
    {
      pDist.reset(new CPairwise("map"));
    }
  else if (family == "pairwise_mrr")
    {
      pDist.reset(new CPairwise("mrr"));
    }
  else
    {
      throw GBM::invalid_argument();
    }

  if (0==family.compare(0, 8, "pairwise")) 
    {
      cGroups = num_groups(data.misc_ptr(), cTrain);
    }
  
  return pDist;
}
示例#3
0
/* DDS3.2.26: Reconstruct Keystrokes */
static struct preference_set recon_keystrokes(const struct rotation *rot,
					      const char *keystroke)
{
	struct cursor where;
	unsigned int i;
	struct preference_set prefs;

	/* Start on top left group heading, with no preferences */
	where = HOME_CURSOR;
	prefs.num_preferences = 0;

	/* Run through keystrokes until we hit end of string */
	for (i = 0; keystroke[i]; i++) {
		switch (keystroke[i]) {
		case 'U':
			/* UP: Wrap if they are at the top (they can't
                           get back to the title though) */
			if (where.screen_candidate_index <= 0)
				where.screen_candidate_index 
					= num_candidates(where.group_index)-1;
			else
				where.screen_candidate_index--;
			break;

		case 'D':
			/* DOWN: Wrap if they are at the bottom (don't
                           go back to title though) */
			if (where.screen_candidate_index
			    == num_candidates(where.group_index)-1)
				where.screen_candidate_index = 0;
			else
				where.screen_candidate_index++;
			break;

		case 'N':
			/* NEXT: Wrap if they are at the last group */
			if (where.group_index == num_groups()-1)
				where.group_index = 0;
			else
				where.group_index++;
			where.screen_candidate_index = -1;
			break;

		case 'P':
			/* PREVIOUS: Wrap if they are at the first group */
			if (where.group_index == 0)
				where.group_index = num_groups()-1;
			else
				where.group_index--;
			where.screen_candidate_index = -1;
			break;

		case 'S':
			/* SELECT: Select if on candidate, and not already
			   selected */
			if (can_place_in_prefs(&prefs, where, rot))
				place_cand_in_prefs(&prefs, where, rot);
			break;

		case 'X': /* UNDO: move to last selected candidate,
			     and unselect them, or do nothing. */
			where = remove_cand_from_prefs(&prefs, rot, where);
			break;

		default:
			bailout("Invalid keystroke `%c' detected\n",
				keystroke[i]);
		}
	}
	return prefs;
}