libexplain  1.4.D001
libexplain/buffer/eagain/setuid.c
Go to the documentation of this file.
00001 /*
00002  * libexplain - a library of system-call-specific strerror replacements
00003  * Copyright (C) 2012, 2013 Peter Miller
00004  *
00005  * This program is free software; you can redistribute it and/or modify
00006  * it under the terms of the GNU Lesser General Public License as
00007  * published by the Free Software Foundation; either version 3 of the
00008  * License, or (at 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/sys/resource.h>
00020 #include <libexplain/ac/unistd.h>
00021 
00022 #include <libexplain/buffer/eagain.h>
00023 #include <libexplain/buffer/gettext.h>
00024 #include <libexplain/buffer/rlimit.h>
00025 #include <libexplain/buffer/uid.h>
00026 #include <libexplain/option.h>
00027 
00028 
00029 static int
00030 explain_buffer_rlimit_nproc(explain_string_buffer_t *sb)
00031 {
00032     struct rlimit   rlim;
00033 
00034     if (getrlimit(RLIMIT_NPROC, &rlim) >= 0)
00035     {
00036         explain_string_buffer_puts(sb, " (RLIMIT_NPROC: ");
00037         explain_buffer_rlimit(sb, &rlim);
00038         explain_string_buffer_putc(sb, ')');
00039         return 1;
00040     }
00041     return 0;
00042 }
00043 
00044 
00045 void
00046 explain_buffer_eagain_setuid(explain_string_buffer_t *sb, const char *caption)
00047 {
00048     explain_string_buffer_t uid_sb;
00049     char            buid[100];
00050 
00051     explain_string_buffer_init(&uid_sb, buid, sizeof(buid));
00052     explain_buffer_uid(&uid_sb, getuid());
00053 
00054     explain_string_buffer_printf_gettext
00055     (
00056         sb,
00057         i18n
00058         (
00059             /*
00060              * xgettext: This error message is used to explain an EAGAIN
00061              * error reported by the setuid(2) system call (or similar) in the
00062              * case where the uid does not match the real user ID and 'uid'
00063              * would take the process count of the new real user ID
00064              * 'uid' over its RLIMIT_NPROC resource limit.
00065              *
00066              * %1$s => the name of the offending system call argument
00067              * %2$s => real user ID and user name of current process
00068              */
00069             "the %1$s argument does not match the process's real user ID "
00070             "(%2$s), and would take the new real user ID over its "
00071             "maximum number of processes/threads that can be created"
00072         ),
00073         caption,
00074         buid
00075     );
00076     if (explain_option_dialect_specific())
00077         explain_buffer_rlimit_nproc(sb);
00078 }
00079 
00080 
00081 /* vim: set ts=8 sw=4 et : */