Exemplo n.º 1
0
END_TEST

START_TEST(test_check_pwd_euser)
  {
  job *pjob = (job *)calloc(1, sizeof(job));
  struct passwd *pwd = NULL;

  pwd = check_pwd(pjob);
  fail_unless(pwd == NULL, "check_pwd succeeded with an empty job");

  bad_pwd = true;
  decode_str(&pjob->ji_wattr[JOB_ATR_euser], "euser", NULL, "dbeer", 0);
  pwd = check_pwd(pjob);
  fail_unless(pwd == NULL, "bad pwd fail");

  bad_pwd = false;
  fail_init_groups = true;
  decode_str(&pjob->ji_wattr[JOB_ATR_euser], "euser", NULL, "dbeer", 0);
  pwd = check_pwd(pjob);
  fail_unless(pwd == NULL, "bad grp fail");

  pjob->ji_grpcache = NULL;
  fail_init_groups = false;
  fail_site_grp_check = true;
  decode_str(&pjob->ji_wattr[JOB_ATR_euser], "euser", NULL, "dbeer", 0);
  pwd = check_pwd(pjob);
  fail_unless(pwd == NULL, "bad site fail");
  
  pjob->ji_grpcache = NULL;
  fail_site_grp_check = false;
  decode_str(&pjob->ji_wattr[JOB_ATR_euser], "euser", NULL, "dbeer", 0);
  pwd = check_pwd(pjob);
  fail_unless(pwd != NULL);
  }
Exemplo n.º 2
0
int				display_prompt(char **environ)
{
	char	*pwd;
	char	*user;

	pwd = check_pwd(environ);
	user = check_user(environ);
	ft_putstr("$ ");
	ft_putstr(user);
	ft_putstr(" ~");
	ft_putstr(pwd);
	ft_putstr(" > ");
	return ((int)(ft_strlen(user) + ft_strlen(pwd) + 7));
}
Exemplo n.º 3
0
int main(int argc,char *argv[])
{
    if(argc >= 2)
    {
        if(check_pwd(argv[1]))
        {
            printf("Access Granted");
        }
        else
        {
            printf("Access denied");
        }
    }
    else
    {
        printf("please enter pwd");
    }
    return 0;
}
Exemplo n.º 4
0
void req_mvjobfile(

  struct batch_request *preq)  /* I */

  {
  int          fds;
  enum job_file  jft;
  int          oflag;
  job         *pj;

  struct passwd *pwd;

  jft = (enum job_file)preq->rq_ind.rq_jobfile.rq_type;

  if (preq->rq_ind.rq_jobfile.rq_sequence == 0)
    oflag = O_CREAT | O_WRONLY | O_TRUNC;
  else
    oflag = O_CREAT | O_WRONLY | O_APPEND;

  pj = locate_new_job(preq->rq_conn, NULL);

  if (pj == NULL)
    pj = find_job(preq->rq_ind.rq_jobfile.rq_jobid);

  if (pj == NULL)
    {
    snprintf(log_buffer, 1024, "cannot find job %s for move of %s file",
             preq->rq_ind.rq_jobfile.rq_jobid,
             TJobFileType[jft]);

    log_err(-1, "req_mvjobfile", log_buffer);

    req_reject(PBSE_UNKJOBID, 0, preq, NULL, NULL);

    return;
    }

  if ((pj->ji_grpcache == NULL) && (check_pwd(pj) == NULL))
    {
    req_reject(PBSE_UNKJOBID, 0, preq, NULL, NULL);

    return;
    }

  if (((pwd = getpwnam(pj->ji_wattr[(int)JOB_ATR_euser].at_val.at_str)) == NULL) ||
      ((fds = open_std_file(pj, jft, oflag, pwd->pw_gid)) < 0))
    {
    /* FAILURE */

    req_reject(PBSE_MOMREJECT, 0, preq, NULL, "password lookup failed");

    return;
    }

  if (write(
        fds,
        preq->rq_ind.rq_jobfile.rq_data,
        preq->rq_ind.rq_jobfile.rq_size) != preq->rq_ind.rq_jobfile.rq_size)
    {
    req_reject(PBSE_SYSTEM, 0, preq, NULL, "cannot create file");
    }
  else
    {
    reply_ack(preq);
    }

  close(fds);

  if (LOGLEVEL >= 6)
    {
    sprintf(log_buffer, "successfully moved %s file for job '%s'",
            TJobFileType[jft],
            preq->rq_ind.rq_jobfile.rq_jobid);

    log_record(
      PBSEVENT_JOB,
      PBS_EVENTCLASS_JOB,
      (pj != NULL) ? pj->ji_qs.ji_jobid : "NULL",
      log_buffer);
    }

  return;
  }  /* END req_mvjobfile() */
Exemplo n.º 5
0
void req_mvjobfile(

  struct batch_request *preq)  /* I */

  {
  int          fds;
  enum job_file  jft;
  int          oflag;
  job         *pj;

  struct passwd *pwd;
  char          *buf = NULL;

  jft = (enum job_file)preq->rq_ind.rq_jobfile.rq_type;

  if (preq->rq_ind.rq_jobfile.rq_sequence == 0)
    oflag = O_CREAT | O_WRONLY | O_TRUNC;
  else
    oflag = O_CREAT | O_WRONLY | O_APPEND;

  pj = locate_new_job(preq->rq_conn, NULL);

  if (pj == NULL)
    pj = mom_find_job(preq->rq_ind.rq_jobfile.rq_jobid);

  if (pj == NULL)
    {
    snprintf(log_buffer, 1024, "cannot find job %s for move of %s file",
      preq->rq_ind.rq_jobfile.rq_jobid,
      TJobFileType[jft]);

    log_err(-1, __func__, log_buffer);

    req_reject(PBSE_UNKJOBID, 0, preq, NULL, NULL);

    return;
    }

  bool good;
  good = check_pwd(pj);
  if ((pj->ji_grpcache == NULL) && 
      (good == false))
    {
    req_reject(PBSE_UNKJOBID, 0, preq, NULL, NULL);

    return;
    }

  /* check_pwd allocated pwd and getpwnam_ext is going to allocate
     another one. Free pwd first */
  if ((pwd = getpwnam_ext(&buf, pj->ji_wattr[JOB_ATR_euser].at_val.at_str)) == NULL)
    {
    /* FAILURE */
    req_reject(PBSE_MOMREJECT, 0, preq, NULL, "password lookup failed");

    return;
    }

  if ((fds = open_std_file(pj, jft, oflag, pwd->pw_gid)) < 0)
    {
    int   keeping = 1;
    char *path = std_file_name(pj, jft, &keeping);

    snprintf(log_buffer,sizeof(log_buffer),
      "Cannot create file %s",
      path);

    req_reject(PBSE_SYSTEM, 0, preq, NULL, log_buffer);

    if (pwd)
      {
      free_pwnam(pwd, buf);
      }
    return;
    }
  if (pwd)
    {
    free_pwnam(pwd, buf);
    }

  if (write_ac_socket(
        fds,
        preq->rq_ind.rq_jobfile.rq_data,
        preq->rq_ind.rq_jobfile.rq_size) != preq->rq_ind.rq_jobfile.rq_size)
    {
    req_reject(PBSE_SYSTEM, 0, preq, NULL, "cannot create file");
    }
  else
    {
    if (LOGLEVEL >= 6)
      {
      sprintf(log_buffer, "successfully moved %s file for job '%s'",
        TJobFileType[jft],
        preq->rq_ind.rq_jobfile.rq_jobid);
      
      log_record(
        PBSEVENT_JOB,
        PBS_EVENTCLASS_JOB,
        pj->ji_qs.ji_jobid,
        log_buffer);
      }

    reply_ack(preq);
    }

  close(fds);

  return;
  }  /* END req_mvjobfile() */
Exemplo n.º 6
0
gboolean monitor_cmdline(struct Page *page_data)
{
#ifdef FULL
	g_debug("! Launch monitor_cmdline() with page_data = %p", page_data);
#endif
#ifdef DEFENSIVE
	if ((page_data==NULL) || (page_data->lost_focus==NULL) || (page_data->keep_vte_size==NULL) ||
	    (page_data->current_vte==NULL) || (page_data->window_title_tpgid==NULL)) return FALSE;
#endif
	if (page_data->pid<1) return FALSE;

	gboolean lost_focus = *(page_data->lost_focus);

	// g_debug("Get page_data->keep_vte_size = %d in monitor_cmdline()", *(page_data->keep_vte_size));

	// g_debug ("\nvte_terminal_get_status_line = %s,"
	//	"vte_terminal_get_icon_title = %s,\n"
	//	"vte_terminal_get_window_title = %s\n",
	//	vte_terminal_get_status_line(VTE_TERMINAL(page_data->vte)),
	//	vte_terminal_get_icon_title(VTE_TERMINAL(page_data->vte)),
	//	vte_terminal_get_window_title(VTE_TERMINAL(page_data->vte)));

	// The pagename won't be updated if LilyTerm is not on focus or when resizing.
	// But it will still update the window title.
	// 0xfe = 11,111,110
	if ((*(page_data->keep_vte_size)&0xfffc) ||
	    (lost_focus && (*(page_data->current_vte) != (page_data->vte))) ||
	    page_data->custom_page_name ||
	    dialog_activated)
		return TRUE;
	// if we should call get_and_update_page_name or not
	gboolean page_name_changed = FALSE;

	// backup page_data datas
	gint page_update_method = page_data->page_update_method;

	page_data->page_update_method = PAGE_METHOD_AUTOMATIC;
	// g_debug("INIT: lost_focus = %d", lost_focus);
	// g_debug("INIT: page_data->window_title_updated = %d", page_data->window_title_updated);

	if (lost_focus)
		page_name_changed = check_cmdline(page_data, *(page_data->window_title_tpgid));
	else
	{
		page_name_changed = check_cmdline(page_data, page_data->displayed_tpgid);
		
		if ((page_name_changed)	&& page_data->check_root_privileges)
			page_data->is_root = check_is_root(page_data->current_tpgid);
	}

	// g_debug("lost_focus = %d", lost_focus);
	// g_debug("page_data->window_title_updated = %d", page_data->window_title_updated);

	if (check_window_title(page_data, lost_focus))
		page_name_changed = TRUE;

	gchar *old_pwd;
	if (lost_focus)
		old_pwd = page_data->window_title_pwd;
	else
		old_pwd = page_data->pwd;

	gchar *new_pwd = get_tab_name_with_current_dir(page_data->current_tpgid);

	if (check_pwd(page_data, old_pwd, new_pwd, page_update_method))
	{
		page_name_changed = TRUE;
		if (lost_focus)
			page_data->window_title_pwd = new_pwd;
		else
			page_data->pwd = new_pwd;
		new_pwd = old_pwd;
	}

	// g_debug("check_tpgid = %d, and current_tpgid = %d", *check_tpgid, page_data->current_tpgid);
	// only update the page name when tpgid is updated.
	// g_debug("Final: page_data->page_update_method = %d", page_data->page_update_method);
	if (page_name_changed)
	{
		// g_debug("!!! Update the page name for page_no %d", page_data->page_no);
		page_data->is_bold = page_data->bold_action_page_name;
		page_data->should_be_bold = TRUE;
		// g_debug("page_data->is_bold = %d for page_data %p", page_data->is_bold, page_data);

		// g_debug("Launch get_and_update_page_name() in monitor_cmdline()");
		if (( ! get_and_update_page_name(page_data, *(page_data->lost_focus))) && (! lost_focus))
		{
			// if update "tab title" fault. upate window title will never fault.
			// g_debug("!! Tab name is NOT changed to '%s'", page_data->pwd);
			// exchange old_pwd and new_pwd again!
			new_pwd = page_data->pwd;
			page_data->pwd = old_pwd;
			// g_debug("Restore page_data->pwd to %s", page_data->pwd);
		}
	}
	else
	{
		page_data->page_update_method = page_update_method;
		// g_debug("Restore page_data->page_update_method to %d!!!", page_data->page_update_method);
	}

	g_free(new_pwd);

	return TRUE;
}