Expand PMF_FN_* macros.
[netbsd-mini2440.git] / external / ibm-public / postfix / dist / src / global / dot_lockfile_as.c
blob402a662680505ed0c982b893eca526e1148f44dd
1 /* $NetBSD$ */
3 /*++
4 /* NAME
5 /* dot_lockfile_as 3
6 /* SUMMARY
7 /* dotlock file as user
8 /* SYNOPSIS
9 /* #include <dot_lockfile_as.h>
11 /* int dot_lockfile_as(path, why, euid, egid)
12 /* const char *path;
13 /* VSTRING *why;
14 /* uid_t euid;
15 /* gid_t egid;
17 /* void dot_unlockfile_as(path, euid, egid)
18 /* const char *path;
19 /* uid_t euid;
20 /* gid_t egid;
21 /* DESCRIPTION
22 /* dot_lockfile_as() and dot_unlockfile_as() are wrappers around
23 /* the dot_lockfile() and dot_unlockfile() routines. The routines
24 /* change privilege to the designated privilege, perform the
25 /* requested operation, and restore privileges.
26 /* DIAGNOSTICS
27 /* Fatal error: no permission to change privilege level.
28 /* SEE ALSO
29 /* dot_lockfile(3) dotlock file management
30 /* set_eugid(3) switch effective rights
31 /* LICENSE
32 /* .ad
33 /* .fi
34 /* The Secure Mailer license must be distributed with this software.
35 /* AUTHOR(S)
36 /* Wietse Venema
37 /* IBM T.J. Watson Research
38 /* P.O. Box 704
39 /* Yorktown Heights, NY 10598, USA
40 /*--*/
42 /* System library. */
44 #include <sys_defs.h>
45 #include <unistd.h>
47 /* Utility library. */
49 #include "msg.h"
50 #include "set_eugid.h"
51 #include "dot_lockfile.h"
52 #include "dot_lockfile_as.h"
54 /* dot_lockfile_as - dotlock file as user */
56 int dot_lockfile_as(const char *path, VSTRING *why, uid_t euid, gid_t egid)
58 uid_t saved_euid = geteuid();
59 gid_t saved_egid = getegid();
60 int result;
63 * Switch to the target user privileges.
65 set_eugid(euid, egid);
68 * Lock that file.
70 result = dot_lockfile(path, why);
73 * Restore saved privileges.
75 set_eugid(saved_euid, saved_egid);
77 return (result);
80 /* dot_unlockfile_as - dotlock file as user */
82 void dot_unlockfile_as(const char *path, uid_t euid, gid_t egid)
84 uid_t saved_euid = geteuid();
85 gid_t saved_egid = getegid();
88 * Switch to the target user privileges.
90 set_eugid(euid, egid);
93 * Lock that file.
95 dot_unlockfile(path);
98 * Restore saved privileges.
100 set_eugid(saved_euid, saved_egid);