nfs-ganesha 1.4

gss_clnt_send_err.c

Go to the documentation of this file.
00001 /*
00002   Copyright (c) 2000 The Regents of the University of Michigan.
00003   All rights reserved.
00004 
00005   Copyright (c) 2004 Bruce Fields <bfields@umich.edu>
00006 
00007   Redistribution and use in source and binary forms, with or without
00008   modification, are permitted provided that the following conditions
00009   are met:
00010 
00011   1. Redistributions of source code must retain the above copyright
00012      notice, this list of conditions and the following disclaimer.
00013   2. Redistributions in binary form must reproduce the above copyright
00014      notice, this list of conditions and the following disclaimer in the
00015      documentation and/or other materials provided with the distribution.
00016   3. Neither the name of the University nor the names of its
00017      contributors may be used to endorse or promote products derived
00018      from this software without specific prior written permission.
00019 
00020   THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
00021   WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
00022   MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
00023   DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
00024   FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
00025   CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
00026   SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
00027   BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
00028   LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
00029   NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
00030   SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00031 */
00032 
00033 #ifdef HAVE_CONFIG_H
00034 #include <config.h>
00035 #endif  /* HAVE_CONFIG_H */
00036 
00037 #include <sys/param.h>
00038 #include <sys/socket.h>
00039 #include <sys/types.h>
00040 #include <sys/stat.h>
00041 #include <rpc/rpc.h>
00042 
00043 #include <unistd.h>
00044 #include <err.h>
00045 #include <stdio.h>
00046 #include <stdlib.h>
00047 #include <string.h>
00048 #include <pwd.h>
00049 #include <fcntl.h>
00050 
00051 #include "gssd.h"
00052 #include "write_bytes.h"
00053 
00054 char pipefsdir[PATH_MAX] = GSSD_PIPEFS_DIR;
00055 
00056 static void
00057 usage(char *progname)
00058 {
00059         fprintf(stderr, "usage: %s clntdir user [user ...]\n", progname);
00060         exit(1);
00061 }
00062 
00063 static int
00064 do_error_downcall(int k5_fd, uid_t uid, int err)
00065 {
00066         char    buf[1024];
00067         char    *p = buf, *end = buf + 1024;
00068         unsigned int timeout = 0;
00069         int     zero = 0;
00070 
00071         if (WRITE_BYTES(&p, end, uid)) return -1;
00072         if (WRITE_BYTES(&p, end, timeout)) return -1;
00073         /* use seq_win = 0 to indicate an error: */
00074         if (WRITE_BYTES(&p, end, zero)) return -1;
00075         if (WRITE_BYTES(&p, end, err)) return -1;
00076 
00077         if (write(k5_fd, buf, p - buf) < p - buf) return -1;
00078         return 0;
00079 }
00080 
00081 int
00082 main(int argc, char *argv[])
00083 {
00084         int fd;
00085         int i;
00086         uid_t uid;
00087         char *endptr;
00088         struct passwd *pw;
00089 
00090         if (argc < 3)
00091                 usage(argv[0]);
00092         fd = open(argv[1], O_WRONLY);
00093         if (fd == -1)
00094                 err(1, "unable to open %s", argv[1]);
00095 
00096         for (i = 2; i < argc; i++) {
00097                 uid = strtol(argv[i], &endptr, 10);
00098                 if (*endptr != '\0') {
00099                         pw = getpwnam(argv[i]);
00100                         if (!pw)
00101                                 err(1, "unknown user %s", argv[i]);
00102                         uid = pw->pw_uid;
00103                 }
00104                 if (do_error_downcall(fd, uid, -1))
00105                         err(1, "failed to destroy cred for user %s", argv[i]);
00106         }
00107         exit(0);
00108 }