1 ;;; -*- Mode: LISP; Syntax: COMMON-LISP; Package: HUNCHENTOOT; Base: 10 -*-
2 ;;; $Header: /usr/local/cvsrep/hunchentoot/unix-lw.lisp,v 1.5 2008/02/13 16:02:19 edi Exp $
4 ;;; Copyright (c) 2004-2008, Dr. Edmund Weitz. All rights reserved.
6 ;;; Redistribution and use in source and binary forms, with or without
7 ;;; modification, are permitted provided that the following conditions
10 ;;; * Redistributions of source code must retain the above copyright
11 ;;; notice, this list of conditions and the following disclaimer.
13 ;;; * Redistributions in binary form must reproduce the above
14 ;;; copyright notice, this list of conditions and the following
15 ;;; disclaimer in the documentation and/or other materials
16 ;;; provided with the distribution.
18 ;;; THIS SOFTWARE IS PROVIDED BY THE AUTHOR 'AS IS' AND ANY EXPRESSED
19 ;;; OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
20 ;;; WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21 ;;; ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
22 ;;; DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23 ;;; DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
24 ;;; GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25 ;;; INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
26 ;;; WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
27 ;;; NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
28 ;;; SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 (in-package :hunchentoot
)
32 (fli:define-foreign-function
(%setuid
"setuid")
37 "Sets the effective user ID of the current process to UID - see
39 (unless (zerop (%setuid uid
))
40 (parameter-error "setuid failed: ~A" (lw:get-unix-error
(lw:errno-value
)))))
42 (fli:define-foreign-function
(%setgid
"setgid")
47 "Sets the effective group ID of the current process to GID -
49 (unless (zerop (%setgid gid
))
50 (parameter-error "setgid failed: ~A" (lw:get-unix-error
(lw:errno-value
)))))
52 (fli:define-c-struct passwd
53 (name (:pointer
:char
))
54 (passwd (:pointer
:char
))
57 (gecos (:pointer
:char
))
58 (dir (:pointer
:char
))
59 (shell (:pointer
:char
)))
61 (fli:define-foreign-function
(getpwnam "getpwnam")
62 ((name (:reference-pass
:ef-mb-string
)))
63 :result-type
(:pointer passwd
))
65 (defun get-uid-from-name (name)
66 "Returns the UID for the user named NAME."
67 (let ((passwd (getpwnam name
)))
68 (when (fli:null-pointer-p passwd
)
69 (let ((errno (lw:errno-value
)))
71 (parameter-error "User ~S not found." name
))
72 (t (parameter-error "getpwnam failed: ~A" (lw:get-unix-error errno
))))))
73 (fli:foreign-slot-value passwd
'uid
)))
75 (fli:define-c-struct group
76 (name (:pointer
:char
))
77 (passwd (:pointer
:char
))
79 (mem (:pointer
(:pointer
:char
))))
81 (fli:define-foreign-function
(getgrnam "getgrnam")
82 ((name (:reference-pass
:ef-mb-string
)))
83 :result-type
(:pointer group
))
85 (defun get-gid-from-name (name)
86 "Returns the GID for the group named NAME."
87 (let ((group (getgrnam name
)))
88 (when (fli:null-pointer-p group
)
89 (let ((errno (lw:errno-value
)))
91 (parameter-error "Group ~S not found." name
))
92 (t (parameter-error "getgrnam failed: ~A" (lw:get-unix-error errno
))))))
93 (fli:foreign-slot-value group
'gid
)))