[BACK]Return to session.c CVS log [TXT][DIR] Up to [local] / src / usr.bin / cvs

Annotation of src/usr.bin/cvs/session.c, Revision 1.1

1.1     ! krapht      1: /*     $OpenBSD$       */
        !             2: /*
        !             3:  * Copyright (c) 2004 Jean-Francois Brousseau <jfb@openbsd.org>
        !             4:  * All rights reserved.
        !             5:  *
        !             6:  * Redistribution and use in source and binary forms, with or without
        !             7:  * modification, are permitted provided that the following conditions
        !             8:  * are met:
        !             9:  *
        !            10:  * 1. Redistributions of source code must retain the above copyright
        !            11:  *    notice, this list of conditions and the following disclaimer.
        !            12:  * 2. The name of the author may not be used to endorse or promote products
        !            13:  *    derived from this software without specific prior written permission.
        !            14:  *
        !            15:  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
        !            16:  * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
        !            17:  * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
        !            18:  * THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
        !            19:  * EXEMPLARY, OR CONSEQUENTIAL  DAMAGES (INCLUDING, BUT NOT LIMITED TO,
        !            20:  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
        !            21:  * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
        !            22:  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
        !            23:  * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
        !            24:  * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
        !            25:  */
        !            26:
        !            27: #include <sys/param.h>
        !            28: #include <sys/stat.h>
        !            29: #include <sys/wait.h>
        !            30: #include <sys/time.h>
        !            31: #include <sys/uio.h>
        !            32:
        !            33: #include <err.h>
        !            34: #include <pwd.h>
        !            35: #include <grp.h>
        !            36: #include <poll.h>
        !            37: #include <fcntl.h>
        !            38: #include <dirent.h>
        !            39: #include <stdlib.h>
        !            40: #include <stdio.h>
        !            41: #include <unistd.h>
        !            42: #include <signal.h>
        !            43: #include <errno.h>
        !            44: #include <string.h>
        !            45: #include <sysexits.h>
        !            46:
        !            47: #include "log.h"
        !            48: #include "sock.h"
        !            49: #include "cvs.h"
        !            50: #include "cvsd.h"
        !            51:
        !            52:
        !            53: /*
        !            54:  * cvsd_sess_alloc()
        !            55:  *
        !            56:  * Allocate a new session.
        !            57:  */
        !            58:
        !            59: struct cvsd_sess*
        !            60: cvsd_sess_alloc(int fd)
        !            61: {
        !            62:        gid_t gid;
        !            63:        struct cvsd_sess *sp;
        !            64:
        !            65:        sp = (struct cvsd_sess *)malloc(sizeof(*sp));
        !            66:        if (sp == NULL) {
        !            67:                cvs_log(LP_ERRNO, "failed to allocate session");
        !            68:                return (NULL);
        !            69:        }
        !            70:
        !            71:        sp->cs_fd = fd;
        !            72:        /* only local sessions are currently supported */
        !            73:        sp->cs_type = CVSD_SESS_LOCAL;
        !            74:
        !            75:        if (sp->cs_type == CVSD_SESS_LOCAL) {
        !            76:                if (getpeereid(fd, &(sp->cs_uid), &gid) == -1) {
        !            77:                        cvs_log(LP_ERRNO, "failed to get remote effective ID");
        !            78:                        free(sp);
        !            79:                        return (NULL);
        !            80:                }
        !            81:        }
        !            82:
        !            83:        cvs_log(LP_INFO, "session opened for user %u", sp->cs_uid);
        !            84:
        !            85:        return (sp);
        !            86: }
        !            87:
        !            88:
        !            89: /*
        !            90:  * cvsd_sess_free()
        !            91:  *
        !            92:  */
        !            93:
        !            94: void
        !            95: cvsd_sess_free(struct cvsd_sess *sessp)
        !            96: {
        !            97:        if (sessp != NULL) {
        !            98:                free(sessp);
        !            99:        }
        !           100: }