File: sgessh.c

package info (click to toggle)
gridengine 8.1.9%2Bdfsg-10
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 56,880 kB
  • sloc: ansic: 432,689; java: 87,068; cpp: 31,958; sh: 29,429; jsp: 7,757; perl: 6,336; xml: 5,828; makefile: 4,701; csh: 3,928; ruby: 2,221; tcl: 1,676; lisp: 669; yacc: 519; python: 503; lex: 361; javascript: 200
file content (108 lines) | stat: -rw-r--r-- 2,321 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
#include <syslog.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <sys/types.h>
#include <grp.h>
#include <pwd.h>

#if defined SOLARIS || HPUX || NECSX5 || CRAY
#define _PATH_NOLOGIN "/etc/nologin"
#define _PATH_BSHELL "/bin/sh"
#define _PATH_DEFPATH "/usr/bin:/bin"
#else
#include <paths.h>
#endif

#include <sge_unistd.h>
#include <setosjobid.h>
#include <setrlimits.h>
#include <config_file.h>
#include <sge_uidgid.h>

#ifndef MAXPATHLEN
#define MAXPATHLEN 1024
#endif

extern int foreground;
bool  g_new_interactive_job_support = false; /* This is needed in err_trace.c */

static char *s_qsub_gid = NULL;
static char start_dir[MAXPATHLEN] = "";

int sgessh_readconfig(void)
{
  char err_str[2048];

  read_config("config");

  if (sge_set_admin_username(get_conf_val("admin_user"), err_str, sizeof(err_str)))
  {
    perror(err_str);
    exit(1);
  }

  getcwd(start_dir, MAXPATHLEN);

  s_qsub_gid = get_conf_val("qsub_gid");

  return 0;
}



int sgessh_do_setusercontext(struct passwd *pwd)
{
   char work_dir[MAXPATHLEN];
   gid_t add_grp_id;

   getcwd(work_dir, MAXPATHLEN);
   chdir(start_dir);

   sge_switch2admin_user();
   foreground = 0; /* setosjobid shall write to shepherd trace file */
   setosjobid(0, &add_grp_id, pwd);
   setrlimits(0);
   sge_switch2start_user();

   if (*pwd->pw_shell == '\0')
     pwd->pw_shell = _PATH_BSHELL;

#if BSD > 43
   if (setlogin(pwd->pw_name) < 0)
     syslog(LOG_ERR, "setlogin() failed: %m");
#endif

   if(s_qsub_gid != NULL && strcmp(s_qsub_gid, "no") != 0)
      pwd->pw_gid = atoi(s_qsub_gid);

   (void) setgid((gid_t)pwd->pw_gid);

#if !defined(INTERIX) /* EB: TODO: There is no initgroups() in INTERIX */
   initgroups(pwd->pw_name, pwd->pw_gid);
#endif

#if (SOLARIS || ALPHA || LINUX || DARWIN)
   /* add Additional group id to current list of groups */
   if (add_grp_id) {
      char err_str[1024];
      bool skip_silently = false;
      const char *tmp_str = search_conf_val("skip_ngroups_max_silently");

      if (tmp_str != NULL && strcmp(tmp_str, "yes") == 0) {
         skip_silently = true;
      }
      if (sge_add_group(add_grp_id, err_str, sizeof(err_str), skip_silently) == -1) {
         perror(err_str);
      }
   }
#endif

   setuid((uid_t)pwd->pw_uid);

   chdir(work_dir);

   return 0;

}