~ubuntu-branches/ubuntu/quantal/xdm/quantal

« back to all changes in this revision

Viewing changes to session.c

  • Committer: Bazaar Package Importer
  • Author(s): Brice Goglin
  • Date: 2010-03-14 11:44:38 UTC
  • mto: (9.1.1 sid)
  • mto: This revision was merged to the branch mainline in revision 12.
  • Revision ID: james.westby@ubuntu.com-20100314114438-xce9zkmf88jtlq0l
Tags: upstream-1.1.9
ImportĀ upstreamĀ versionĀ 1.1.9

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* $XdotOrg: app/xdm/session.c,v 1.7 2006-06-03 00:05:24 alanc Exp $ */
2
 
/* $Xorg: session.c,v 1.8 2001/02/09 02:05:40 xorgcvs Exp $ */
3
1
/*
4
2
 
5
3
Copyright 1988, 1998  The Open Group
27
25
from The Open Group.
28
26
 
29
27
*/
30
 
/* $XFree86: xc/programs/xdm/session.c,v 3.36 2003/09/29 21:00:08 herrb Exp $ */
31
28
 
32
29
/*
33
30
 * xdm - display manager daemon
54
51
#endif
55
52
 
56
53
#ifndef USE_PAM        /* PAM modules should handle these */
57
 
#ifdef SECURE_RPC
58
 
# include <rpc/rpc.h>
59
 
# include <rpc/key_prot.h>
60
 
# if !HAVE_DECL_KEY_SETNET
 
54
# ifdef SECURE_RPC
 
55
#  include <rpc/rpc.h>
 
56
#  include <rpc/key_prot.h>
 
57
#  if !HAVE_DECL_KEY_SETNET
61
58
extern int key_setnet(struct key_netstarg *arg);
62
 
# endif
63
 
#endif
64
 
#ifdef K5AUTH
65
 
# include <krb5/krb5.h>
66
 
#endif
 
59
#  endif
 
60
# endif
 
61
# ifdef K5AUTH
 
62
#  include <krb5/krb5.h>
 
63
# endif
67
64
#endif /* USE_PAM */
68
65
 
69
66
#ifdef __SCO__
70
 
#include <prot.h>
 
67
# include <prot.h>
71
68
#endif
72
69
 
73
70
#ifndef GREET_USER_STATIC
609
606
#endif
610
607
 
611
608
#ifndef AIXV3
612
 
#ifndef HAS_SETUSERCONTEXT
613
 
        if (setgid(verify->gid) < 0) {
614
 
            LogError ("setgid %d (user \"%s\") failed, errno=%d\n",
615
 
                     verify->gid, name, errno);
616
 
            return (0);
617
 
        }
618
 
#if defined(BSD) && (BSD >= 199103)
619
 
        if (setlogin(name) < 0) {
620
 
            LogError ("setlogin for \"%s\" failed, errno=%d", name, errno);
621
 
            return(0);
622
 
        }
623
 
#endif
624
 
#ifndef QNX4
625
 
        if (initgroups(name, verify->gid) < 0) {
626
 
            LogError ("initgroups for \"%s\" failed, errno=%d\n", name, errno);
627
 
            return (0);
628
 
        }
629
 
#endif   /* QNX4 doesn't support multi-groups, no initgroups() */
630
 
#endif /* !HAS_SETUSERCONTEXT */
 
609
# ifndef HAS_SETUSERCONTEXT
 
610
        if (setgid (verify->gid) < 0) {
 
611
            LogError ("setgid %d (user \"%s\") failed: %s\n",
 
612
                      verify->gid, name, _SysErrorMsg (errno));
 
613
            return (0);
 
614
        }
 
615
#  if defined(BSD) && (BSD >= 199103)
 
616
        if (setlogin (name) < 0) {
 
617
            LogError ("setlogin for \"%s\" failed: %s\n",
 
618
                      name, _SysErrorMsg (errno));
 
619
            return (0);
 
620
        }
 
621
#  endif
 
622
#  ifndef QNX4
 
623
        if (initgroups (name, verify->gid) < 0) {
 
624
            LogError ("initgroups for \"%s\" failed: %s\n",
 
625
                      name, _SysErrorMsg (errno));
 
626
            return (0);
 
627
        }
 
628
#  endif   /* QNX4 doesn't support multi-groups, no initgroups() */
 
629
# endif /* !HAS_SETUSERCONTEXT */
631
630
 
632
 
#ifdef USE_PAM
 
631
# ifdef USE_PAM
633
632
        if (pamh) {
634
633
            long i;
635
634
            char **pam_env;
648
647
            }
649
648
 
650
649
        }
651
 
#endif
 
650
# endif
652
651
 
653
 
#ifndef HAS_SETUSERCONTEXT
 
652
# ifndef HAS_SETUSERCONTEXT
654
653
        if (setuid(verify->uid) < 0) {
655
 
            LogError ("setuid %d (user \"%s\") failed, errno=%d\n",
656
 
                     verify->uid, name, errno);
 
654
            LogError ("setuid %d (user \"%s\") failed: %s\n",
 
655
                      verify->uid, name, _SysErrorMsg (errno));
657
656
            return (0);
658
657
        }
659
 
#else /* HAS_SETUSERCONTEXT */
 
658
# else /* HAS_SETUSERCONTEXT */
660
659
        /*
661
660
         * Set the user's credentials: uid, gid, groups,
662
661
         * environment variables, resource limits, and umask.
664
663
        pwd = getpwnam(name);
665
664
        if (pwd) {
666
665
            if (setusercontext(NULL, pwd, pwd->pw_uid, LOGIN_SETALL) < 0) {
667
 
                LogError ("setusercontext for \"%s\" failed, errno=%d\n", name,
668
 
                    errno);
 
666
                LogError ("setusercontext for \"%s\" failed: %s\n",
 
667
                          name, _SysErrorMsg (errno));
669
668
                return (0);
670
669
            }
671
670
            endpwent();
672
671
        } else {
673
 
            LogError ("getpwnam for \"%s\" failed, errno=%d\n", name, errno);
 
672
            LogError ("getpwnam for \"%s\" failed: %s\n",
 
673
                      name, _SysErrorMsg (errno));
674
674
            return (0);
675
675
        }
676
 
#endif /* HAS_SETUSERCONTEXT */
 
676
# endif /* HAS_SETUSERCONTEXT */
677
677
#else /* AIXV3 */
678
678
        /*
679
679
         * Set the user's credentials: uid, gid, groups,
680
680
         * audit classes, user limits, and umask.
681
681
         */
682
682
        if (setpcred(name, NULL) == -1) {
683
 
            LogError ("setpcred for \"%s\" failed, errno=%d\n", name, errno);
 
683
            LogError ("setpcred for \"%s\" failed: %s\n",
 
684
                      name, _SysErrorMsg (errno));
684
685
            return (0);
685
686
        }
686
687
#endif /* AIXV3 */
690
691
         * for user-based authorization schemes,
691
692
         * use the password to get the user's credentials.
692
693
         */
693
 
#ifdef SECURE_RPC
 
694
# ifdef SECURE_RPC
694
695
        /* do like "keylogin" program */
695
696
        {
696
697
            char    netname[MAXNETNAMELEN+1], secretkey[HEXKEYBYTES+1];
713
714
            if (key_setnet(&netst) < 0) {
714
715
                Debug ("Could not set secret key.\n");
715
716
            }
716
 
            free(netst.st_netname);     
 
717
            free(netst.st_netname);
717
718
            /* is there a key, and do we have the right password? */
718
719
            if (keyret == 1) {
719
720
                if (*secretkey) {
744
745
            }
745
746
            bzero(secretkey, strlen(secretkey));
746
747
        }
747
 
#endif
748
 
#ifdef K5AUTH
 
748
# endif
 
749
# ifdef K5AUTH
749
750
        /* do like "kinit" program */
750
751
        {
751
752
            int i, j;
771
772
                }
772
773
            }
773
774
        }
774
 
#endif /* K5AUTH */
 
775
# endif /* K5AUTH */
775
776
#endif /* !USE_PAM */
776
777
 
777
778
        if (d->windowPath)
804
805
        if (passwd != NULL)
805
806
            bzero(passwd, strlen(passwd));
806
807
        Debug ("StartSession, fork failed\n");
807
 
        LogError ("can't start session on \"%s\", fork failed, errno=%d\n",
808
 
                  d->name, errno);
 
808
        LogError ("can't start session on \"%s\", fork failed: %s\n",
 
809
                  d->name, _SysErrorMsg (errno));
809
810
        return 0;
810
811
    default:
811
812
        if (passwd != NULL)
869
870
void
870
871
execute (char **argv, char **environ)
871
872
{
 
873
    int err;
872
874
    /* give /dev/null as stdin */
873
875
    (void) close (0);
874
876
    open ("/dev/null", O_RDONLY);
875
877
    /* make stdout follow stderr to the log file */
876
878
    dup2 (2,1);
 
879
    Debug ("attempting to execve() %s\n", argv[0]);
877
880
    execve (argv[0], argv, environ);
 
881
    err = errno;
 
882
    Debug ("execve() of %s failed: %s\n", argv[0], _SysErrorMsg (errno));
878
883
    /*
879
884
     * In case this is a shell script which hasn't been
880
885
     * made executable (or this is a SYSV box), do
881
886
     * a reasonable thing
882
887
     */
883
 
    if (errno != ENOENT) {
 
888
    if (err != ENOENT) {
884
889
        char    program[1024], *e, *p, *optarg;
885
890
        FILE    *f;
886
891
        char    **newargv, **av;
938
943
        while ((*av++ = *argv++))
939
944
            /* SUPPRESS 530 */
940
945
            ;
 
946
        Debug ("Attempting to execve() %s\n", newargv[0]);
941
947
        execve (newargv[0], newargv, environ);
942
948
    }
943
949
}
977
983
            env = setEnv (env, "WINDOWPATH", d->windowPath);
978
984
    return env;
979
985
}
980
 
 
981
 
#if (defined(Lynx) && !defined(HAS_CRYPT))
982
 
char *crypt(char *s1, char *s2)
983
 
{
984
 
        return(s2);
985
 
}
986
 
#endif