port-irix.c revision 162852
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
5098937Sdes        prid_t projid;
51124208Sdes#endif
5298937Sdes#ifdef WITH_IRIX_JOBS
5398937Sdes        jid_t jid = 0;
54124208Sdes#elif defined(WITH_IRIX_ARRAY)
5598937Sdes        int jid = 0;
56124208Sdes#endif
5798937Sdes
5898937Sdes#ifdef WITH_IRIX_JOBS
5998937Sdes        jid = jlimit_startjob(pw->pw_name, pw->pw_uid, "interactive");
6098937Sdes        if (jid == -1)
6198937Sdes                fatal("Failed to create job container: %.100s",
6298937Sdes                    strerror(errno));
6398937Sdes#endif /* WITH_IRIX_JOBS */
6498937Sdes#ifdef WITH_IRIX_ARRAY
6598937Sdes        /* initialize array session */
6698937Sdes        if (jid == 0  && newarraysess() != 0)
6798937Sdes                fatal("Failed to set up new array session: %.100s",
6898937Sdes                    strerror(errno));
6998937Sdes#endif /* WITH_IRIX_ARRAY */
7098937Sdes#ifdef WITH_IRIX_PROJECT
7198937Sdes        /* initialize irix project info */
7298937Sdes        if ((projid = getdfltprojuser(pw->pw_name)) == -1) {
7398937Sdes                debug("Failed to get project id, using projid 0");
7498937Sdes                projid = 0;
7598937Sdes        }
7698937Sdes        if (setprid(projid))
7798937Sdes                fatal("Failed to initialize project %d for %s: %.100s",
7898937Sdes                    (int)projid, pw->pw_name, strerror(errno));
7998937Sdes#endif /* WITH_IRIX_PROJECT */
8098937Sdes#ifdef WITH_IRIX_AUDIT
8198937Sdes        if (sysconf(_SC_AUDIT)) {
8298937Sdes                debug("Setting sat id to %d", (int) pw->pw_uid);
8398937Sdes                if (satsetid(pw->pw_uid))
8498937Sdes                        debug("error setting satid: %.100s", strerror(errno));
8598937Sdes        }
8698937Sdes#endif /* WITH_IRIX_AUDIT */
8798937Sdes}
8898937Sdes
8998937Sdes
9098937Sdes#endif /* defined(WITH_IRIX_PROJECT) || defined(WITH_IRIX_JOBS) || defined(WITH_IRIX_ARRAY) */
91