1124208Sdes/*
2124208Sdes * Copyright (c) 2000 Denis Parker.  All rights reserved.
3124208Sdes * Copyright (c) 2000 Michael Stone.  All rights reserved.
4124208Sdes *
5124208Sdes * Redistribution and use in source and binary forms, with or without
6124208Sdes * modification, are permitted provided that the following conditions
7124208Sdes * are met:
8124208Sdes * 1. Redistributions of source code must retain the above copyright
9124208Sdes *    notice, this list of conditions and the following disclaimer.
10124208Sdes * 2. Redistributions in binary form must reproduce the above copyright
11124208Sdes *    notice, this list of conditions and the following disclaimer in the
12124208Sdes *    documentation and/or other materials provided with the distribution.
13124208Sdes *
14124208Sdes * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
15124208Sdes * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
16124208Sdes * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
17124208Sdes * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
18124208Sdes * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
19124208Sdes * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
20124208Sdes * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
21124208Sdes * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22124208Sdes * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
23124208Sdes * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24124208Sdes */
25124208Sdes
2698937Sdes#include "includes.h"
2798937Sdes
28124208Sdes#if defined(WITH_IRIX_PROJECT) || \
29124208Sdes    defined(WITH_IRIX_JOBS) || \
30124208Sdes    defined(WITH_IRIX_ARRAY)
3198937Sdes
32162852Sdes#include <errno.h>
33162852Sdes#include <string.h>
34162852Sdes#include <unistd.h>
35162852Sdes
3698937Sdes#ifdef WITH_IRIX_PROJECT
37124208Sdes# include <proj.h>
3898937Sdes#endif /* WITH_IRIX_PROJECT */
3998937Sdes#ifdef WITH_IRIX_JOBS
40124208Sdes# include <sys/resource.h>
4198937Sdes#endif
4298937Sdes#ifdef WITH_IRIX_AUDIT
43124208Sdes# include <sat.h>
4498937Sdes#endif /* WITH_IRIX_AUDIT */
4598937Sdes
4698937Sdesvoid
4798937Sdesirix_setusercontext(struct passwd *pw)
4898937Sdes{
4998937Sdes#ifdef WITH_IRIX_PROJECT
50323134Sdes	prid_t projid;
51124208Sdes#endif
5298937Sdes#ifdef WITH_IRIX_JOBS
53323134Sdes	jid_t jid = 0;
54124208Sdes#elif defined(WITH_IRIX_ARRAY)
55323134Sdes	int jid = 0;
56124208Sdes#endif
5798937Sdes
5898937Sdes#ifdef WITH_IRIX_JOBS
59323134Sdes	jid = jlimit_startjob(pw->pw_name, pw->pw_uid, "interactive");
60323134Sdes	if (jid == -1)
61323134Sdes		fatal("Failed to create job container: %.100s",
62323134Sdes		    strerror(errno));
6398937Sdes#endif /* WITH_IRIX_JOBS */
6498937Sdes#ifdef WITH_IRIX_ARRAY
65323134Sdes	/* initialize array session */
66323134Sdes	if (jid == 0  && newarraysess() != 0)
67323134Sdes		fatal("Failed to set up new array session: %.100s",
68323134Sdes		    strerror(errno));
6998937Sdes#endif /* WITH_IRIX_ARRAY */
7098937Sdes#ifdef WITH_IRIX_PROJECT
71323134Sdes	/* initialize irix project info */
72323134Sdes	if ((projid = getdfltprojuser(pw->pw_name)) == -1) {
73323134Sdes		debug("Failed to get project id, using projid 0");
74323134Sdes		projid = 0;
75323134Sdes	}
76323134Sdes	if (setprid(projid))
77323134Sdes		fatal("Failed to initialize project %d for %s: %.100s",
78323134Sdes		    (int)projid, pw->pw_name, strerror(errno));
7998937Sdes#endif /* WITH_IRIX_PROJECT */
8098937Sdes#ifdef WITH_IRIX_AUDIT
81323134Sdes	if (sysconf(_SC_AUDIT)) {
82323134Sdes		debug("Setting sat id to %d", (int) pw->pw_uid);
83323134Sdes		if (satsetid(pw->pw_uid))
84323134Sdes			debug("error setting satid: %.100s", strerror(errno));
85323134Sdes	}
8698937Sdes#endif /* WITH_IRIX_AUDIT */
8798937Sdes}
8898937Sdes
8998937Sdes
9098937Sdes#endif /* defined(WITH_IRIX_PROJECT) || defined(WITH_IRIX_JOBS) || defined(WITH_IRIX_ARRAY) */
91