]> git.decadent.org.uk Git - nfs-utils.git/blob - utils/gssd/gss_clnt_send_err.c
nfs-utils: Fix source code character encoding
[nfs-utils.git] / utils / gssd / gss_clnt_send_err.c
1 /*
2   Copyright (c) 2000 The Regents of the University of Michigan.
3   All rights reserved.
4
5   Copyright (c) 2004 Bruce Fields <bfields@umich.edu>
6
7   Redistribution and use in source and binary forms, with or without
8   modification, are permitted provided that the following conditions
9   are met:
10
11   1. Redistributions of source code must retain the above copyright
12      notice, this list of conditions and the following disclaimer.
13   2. Redistributions in binary form must reproduce the above copyright
14      notice, this list of conditions and the following disclaimer in the
15      documentation and/or other materials provided with the distribution.
16   3. Neither the name of the University nor the names of its
17      contributors may be used to endorse or promote products derived
18      from this software without specific prior written permission.
19
20   THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
21   WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
22   MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
23   DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
24   FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
25   CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
26   SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
27   BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
28   LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
29   NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
30   SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 */
32
33 #ifdef HAVE_CONFIG_H
34 #include <config.h>
35 #endif  /* HAVE_CONFIG_H */
36
37 #include <sys/param.h>
38 #include <sys/socket.h>
39 #include <sys/types.h>
40 #include <sys/stat.h>
41 #include <rpc/rpc.h>
42
43 #include <unistd.h>
44 #include <err.h>
45 #include <stdio.h>
46 #include <stdlib.h>
47 #include <string.h>
48 #include <pwd.h>
49 #include <fcntl.h>
50
51 #include "gssd.h"
52 #include "write_bytes.h"
53
54 char pipefsdir[PATH_MAX] = GSSD_PIPEFS_DIR;
55
56 static void
57 usage(char *progname)
58 {
59         fprintf(stderr, "usage: %s clntdir user [user ...]\n", progname);
60         exit(1);
61 }
62
63 static int
64 do_error_downcall(int k5_fd, uid_t uid, int err)
65 {
66         char    buf[1024];
67         char    *p = buf, *end = buf + 1024;
68         unsigned int timeout = 0;
69         int     zero = 0;
70
71         if (WRITE_BYTES(&p, end, uid)) return -1;
72         if (WRITE_BYTES(&p, end, timeout)) return -1;
73         /* use seq_win = 0 to indicate an error: */
74         if (WRITE_BYTES(&p, end, zero)) return -1;
75         if (WRITE_BYTES(&p, end, err)) return -1;
76
77         if (write(k5_fd, buf, p - buf) < p - buf) return -1;
78         return 0;
79 }
80
81 int
82 main(int argc, char *argv[])
83 {
84         int fd;
85         int i;
86         uid_t uid;
87         char *endptr;
88         struct passwd *pw;
89
90         if (argc < 3)
91                 usage(argv[0]);
92         fd = open(argv[1], O_WRONLY);
93         if (fd == -1)
94                 err(1, "unable to open %s", argv[1]);
95
96         for (i = 2; i < argc; i++) {
97                 uid = strtol(argv[i], &endptr, 10);
98                 if (*endptr != '\0') {
99                         pw = getpwnam(argv[i]);
100                         if (!pw)
101                                 err(1, "unknown user %s", argv[i]);
102                         uid = pw->pw_uid;
103                 }
104                 if (do_error_downcall(fd, uid, -1))
105                         err(1, "failed to destroy cred for user %s", argv[i]);
106         }
107         exit(0);
108 }