libexplain
1.4.D001
|
00001 /* 00002 * libexplain - Explain errno values returned by libc functions 00003 * Copyright (C) 2012, 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, but 00011 * WITHOUT ANY WARRANTY; without even the implied warranty of 00012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser 00013 * 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 00021 #include <libexplain/buffer/dac.h> 00022 #include <libexplain/buffer/eagain.h> 00023 #include <libexplain/buffer/eperm.h> 00024 #include <libexplain/buffer/errno/generic.h> 00025 #include <libexplain/buffer/errno/setresgid.h> 00026 #include <libexplain/buffer/gid.h> 00027 #include <libexplain/explanation.h> 00028 00029 00030 static void 00031 explain_buffer_eperm_setresgid(explain_string_buffer_t *sb, const char *caption, 00032 const char *rgid_str, const char *egid_str, const char *sgid_str) 00033 { 00034 explain_string_buffer_printf_gettext 00035 ( 00036 sb, 00037 i18n 00038 ( 00039 /* 00040 * xgettext: This error message is used to explain an EPERM error 00041 * reported by the setresgid system call, in the case where gid does 00042 * not match the real group ID or saved group ID of the calling 00043 * process, and the process is not privileged (Linux: does not have 00044 * the CAP_SETGID capability) 00045 */ 00046 "the %1$s argument does not match the real group ID (%2$s) or the " 00047 "effective group ID (%3$s) or the saved group ID (%4$s) of the " 00048 "calling process" 00049 ), 00050 caption, 00051 rgid_str, 00052 egid_str, 00053 sgid_str 00054 ); 00055 explain_buffer_dac_setgid(sb); 00056 } 00057 00058 00059 static void 00060 explain_buffer_errno_setresgid_system_call(explain_string_buffer_t *sb, 00061 int errnum, gid_t rgid, gid_t egid, gid_t sgid) 00062 { 00063 (void)errnum; 00064 explain_string_buffer_puts(sb, "setresgid(rgid = "); 00065 explain_buffer_gid(sb, rgid); 00066 explain_string_buffer_puts(sb, ", egid = "); 00067 explain_buffer_gid(sb, egid); 00068 explain_string_buffer_puts(sb, ", sgid = "); 00069 explain_buffer_gid(sb, sgid); 00070 explain_string_buffer_putc(sb, ')'); 00071 } 00072 00073 00074 void 00075 explain_buffer_errno_setresgid_explanation(explain_string_buffer_t *sb, 00076 int errnum, const char *syscall_name, gid_t rgid, gid_t egid, gid_t sgid) 00077 { 00078 gid_t crgid = -1; 00079 char rgid_str[100]; 00080 gid_t cegid = -1; 00081 char egid_str[100]; 00082 gid_t csgid = -1; 00083 char sgid_str[100]; 00084 const gid_t minus1 = -1; 00085 00086 /* 00087 * http://www.opengroup.org/onlinepubs/009695399/functions/setresgid.html 00088 */ 00089 switch (errnum) 00090 { 00091 case EPERM: 00092 /* build the strings we will need to report the error */ 00093 { 00094 explain_string_buffer_t rgid_sb; 00095 explain_string_buffer_t egid_sb; 00096 explain_string_buffer_t sgid_sb; 00097 00098 explain_string_buffer_init(&rgid_sb, rgid_str, sizeof(rgid_str)); 00099 explain_buffer_gid(&rgid_sb, crgid); 00100 explain_string_buffer_init(&egid_sb, egid_str, sizeof(egid_str)); 00101 explain_buffer_gid(&egid_sb, cegid); 00102 explain_string_buffer_init(&sgid_sb, sgid_str, sizeof(sgid_str)); 00103 explain_buffer_gid(&sgid_sb, csgid); 00104 } 00105 00106 if (rgid != minus1 && rgid != crgid && rgid != cegid && rgid != csgid) 00107 { 00108 explain_buffer_eperm_setresgid(sb, "rgid", rgid_str, egid_str, 00109 sgid_str); 00110 break; 00111 } 00112 if (egid != minus1 && egid != crgid && egid != cegid && egid != csgid) 00113 { 00114 explain_buffer_eperm_setresgid(sb, "egid", rgid_str, egid_str, 00115 sgid_str); 00116 break; 00117 } 00118 if (sgid != minus1 && sgid != crgid && sgid != cegid && sgid != csgid) 00119 { 00120 explain_buffer_eperm_setresgid(sb, "sgid", rgid_str, egid_str, 00121 sgid_str); 00122 break; 00123 } 00124 /* Fall through... */ 00125 00126 default: 00127 explain_buffer_errno_generic(sb, errnum, syscall_name); 00128 break; 00129 } 00130 } 00131 00132 00133 void 00134 explain_buffer_errno_setresgid(explain_string_buffer_t *sb, int errnum, gid_t 00135 rgid, gid_t egid, gid_t sgid) 00136 { 00137 explain_explanation_t exp; 00138 00139 explain_explanation_init(&exp, errnum); 00140 explain_buffer_errno_setresgid_system_call(&exp.system_call_sb, errnum, 00141 rgid, egid, sgid); 00142 explain_buffer_errno_setresgid_explanation(&exp.explanation_sb, errnum, 00143 "setresgid", rgid, egid, sgid); 00144 explain_explanation_assemble(&exp, sb); 00145 } 00146 00147 00148 /* vim: set ts=8 sw=4 et : */