libexplain  1.4.D001
libexplain/buffer/errno/setgroups.c
Go to the documentation of this file.
00001 /*
00002  * libexplain - Explain errno values returned by libc functions
00003  * Copyright (C) 2009, 2010, 2013 Peter Miller
00004  *
00005  * This program is free software; you can redistribute it and/or modify it
00006  * under the terms of the GNU Lesser General Public License as published by
00007  * the Free Software Foundation; either version 3 of the License, or (at
00008  * your option) any later version.
00009  *
00010  * This program is distributed in the hope that it will be useful,
00011  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00012  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013  * Lesser General Public License for more details.
00014  *
00015  * You should have received a copy of the GNU Lesser General Public License
00016  * along with this program. If not, see <http://www.gnu.org/licenses/>.
00017  */
00018 
00019 #include <libexplain/ac/errno.h>
00020 #include <libexplain/ac/limits.h> /* for NGROUPS_MAX on Solaris */
00021 
00022 #include <libexplain/buffer/efault.h>
00023 #include <libexplain/buffer/einval.h>
00024 #include <libexplain/buffer/enomem.h>
00025 #include <libexplain/buffer/eperm.h>
00026 #include <libexplain/buffer/errno/generic.h>
00027 #include <libexplain/buffer/errno/setgroups.h>
00028 #include <libexplain/buffer/pointer.h>
00029 #include <libexplain/buffer/size_t.h>
00030 #include <libexplain/explanation.h>
00031 #include <libexplain/option.h>
00032 
00033 
00034 static void
00035 explain_buffer_errno_setgroups_system_call(explain_string_buffer_t *sb, int
00036     errnum, size_t data_size, const gid_t *data)
00037 {
00038     (void)errnum;
00039     explain_string_buffer_puts(sb, "setgroups(data_size = ");
00040     explain_buffer_size_t(sb, data_size);
00041     explain_string_buffer_puts(sb, ", data = ");
00042     explain_buffer_pointer(sb, data);
00043     explain_string_buffer_putc(sb, ')');
00044 }
00045 
00046 
00047 static void
00048 explain_buffer_errno_setgroups_explanation(explain_string_buffer_t *sb, int
00049     errnum, size_t data_size, const gid_t *data)
00050 {
00051     /*
00052      * http://www.opengroup.org/onlinepubs/009695399/functions/setgroups.html
00053      */
00054     (void)data;
00055     switch (errnum)
00056     {
00057     case EFAULT:
00058         explain_buffer_efault(sb, "data");
00059         break;
00060 
00061     case EINVAL:
00062         explain_buffer_einval_too_large(sb, "data_size");
00063         if (data_size > NGROUPS_MAX && explain_option_dialect_specific())
00064         {
00065             explain_string_buffer_printf
00066             (
00067                 sb,
00068                 " (%lu > %lu)",
00069                 (unsigned long)data_size,
00070                 (unsigned long)NGROUPS_MAX
00071             );
00072         }
00073         break;
00074 
00075     case ENOMEM:
00076         explain_buffer_enomem_kernel(sb);
00077         break;
00078 
00079     case EPERM:
00080         explain_buffer_eperm_setgid(sb);
00081         break;
00082 
00083     default:
00084         explain_buffer_errno_generic(sb, errnum, "setgroups");
00085         break;
00086     }
00087 }
00088 
00089 
00090 void
00091 explain_buffer_errno_setgroups(explain_string_buffer_t *sb, int errnum, size_t
00092     data_size, const gid_t *data)
00093 {
00094     explain_explanation_t exp;
00095 
00096     explain_explanation_init(&exp, errnum);
00097     explain_buffer_errno_setgroups_system_call(&exp.system_call_sb, errnum,
00098         data_size, data);
00099     explain_buffer_errno_setgroups_explanation(&exp.explanation_sb, errnum,
00100         data_size, data);
00101     explain_explanation_assemble(&exp, sb);
00102 }
00103 
00104 
00105 /* vim: set ts=8 sw=4 et : */