libexplain
1.4.D001
|
00001 /* 00002 * libexplain - Explain errno values returned by libc functions 00003 * Copyright (C) 2009, 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/sys/stat.h> 00021 00022 #include <libexplain/buffer/dac.h> 00023 #include <libexplain/buffer/eacces.h> 00024 #include <libexplain/buffer/efault.h> 00025 #include <libexplain/buffer/eio.h> 00026 #include <libexplain/buffer/eloop.h> 00027 #include <libexplain/buffer/enametoolong.h> 00028 #include <libexplain/buffer/enoent.h> 00029 #include <libexplain/buffer/enomem.h> 00030 #include <libexplain/buffer/enotdir.h> 00031 #include <libexplain/buffer/errno/generic.h> 00032 #include <libexplain/buffer/errno/chroot.h> 00033 #include <libexplain/buffer/errno/path_resolution.h> 00034 #include <libexplain/buffer/gettext.h> 00035 #include <libexplain/buffer/pathname.h> 00036 #include <libexplain/explanation.h> 00037 00038 00039 static void 00040 explain_buffer_errno_chroot_system_call(explain_string_buffer_t *sb, int errnum, 00041 const char *pathname) 00042 { 00043 (void)errnum; 00044 explain_string_buffer_puts(sb, "chroot(pathname = "); 00045 explain_buffer_pathname(sb, pathname); 00046 explain_string_buffer_putc(sb, ')'); 00047 } 00048 00049 00050 static void 00051 explain_buffer_errno_chroot_explanation(explain_string_buffer_t *sb, int errnum, 00052 const char *pathname) 00053 { 00054 explain_final_t final_component; 00055 00056 explain_final_init(&final_component); 00057 final_component.want_to_search = 1; 00058 final_component.must_be_a_st_mode = 1; 00059 final_component.st_mode = S_IFDIR; 00060 00061 /* 00062 * http://www.opengroup.org/onlinepubs/009695399/functions/chroot.html 00063 */ 00064 switch (errnum) 00065 { 00066 case EACCES: 00067 explain_buffer_eacces(sb, pathname, "pathname", &final_component); 00068 break; 00069 00070 case EFAULT: 00071 explain_buffer_efault(sb, "pathname"); 00072 break; 00073 00074 case EIO: 00075 explain_buffer_eio(sb); 00076 break; 00077 00078 case ELOOP: 00079 explain_buffer_eloop(sb, pathname, "pathname", &final_component); 00080 break; 00081 00082 case ENAMETOOLONG: 00083 explain_buffer_enametoolong(sb, pathname, "pathname", &final_component); 00084 break; 00085 00086 case ENOENT: 00087 explain_buffer_enoent(sb, pathname, "pathname", &final_component); 00088 break; 00089 00090 case ENOMEM: 00091 explain_buffer_enomem_kernel(sb); 00092 break; 00093 00094 case ENOTDIR: 00095 explain_buffer_enotdir(sb, pathname, "pathname", &final_component); 00096 break; 00097 00098 case EPERM: 00099 explain_buffer_gettext 00100 ( 00101 sb, 00102 /* 00103 * xgettext: This error message is issued when a 00104 * process attempts to change its root directory. 00105 */ 00106 i18n("the process does not have permission to change its root " 00107 "directory") 00108 ); 00109 explain_buffer_dac_sys_chroot(sb); 00110 break; 00111 00112 default: 00113 explain_buffer_errno_generic(sb, errnum, "chroot"); 00114 break; 00115 } 00116 } 00117 00118 00119 void 00120 explain_buffer_errno_chroot(explain_string_buffer_t *sb, int errnum, const char 00121 *pathname) 00122 { 00123 explain_explanation_t exp; 00124 00125 explain_explanation_init(&exp, errnum); 00126 explain_buffer_errno_chroot_system_call(&exp.system_call_sb, errnum, 00127 pathname); 00128 explain_buffer_errno_chroot_explanation(&exp.explanation_sb, errnum, 00129 pathname); 00130 explain_explanation_assemble(&exp, sb); 00131 } 00132 00133 00134 /* vim: set ts=8 sw=4 et : */