libexplain
1.4.D001
|
00001 /* 00002 * libexplain - Explain errno values returned by libc functions 00003 * Copyright (C) 2013, 2014 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/acl_type.h> 00022 #include <libexplain/buffer/eacces.h> 00023 #include <libexplain/buffer/efault.h> 00024 #include <libexplain/buffer/eloop.h> 00025 #include <libexplain/buffer/enametoolong.h> 00026 #include <libexplain/buffer/enoent.h> 00027 #include <libexplain/buffer/enomem.h> 00028 #include <libexplain/buffer/enosys.h> 00029 #include <libexplain/buffer/enotdir.h> 00030 #include <libexplain/buffer/errno/acl_get_file.h> 00031 #include <libexplain/buffer/errno/generic.h> 00032 #include <libexplain/buffer/errno/path_resolution.h> 00033 #include <libexplain/buffer/is_the_null_pointer.h> 00034 #include <libexplain/buffer/pathname.h> 00035 #include <libexplain/buffer/software_error.h> 00036 #include <libexplain/explanation.h> 00037 #include <libexplain/is_efault.h> 00038 00039 00040 static void 00041 explain_buffer_errno_acl_get_file_system_call(explain_string_buffer_t *sb, 00042 int errnum, const char *pathname, acl_type_t type) 00043 { 00044 (void)errnum; 00045 explain_string_buffer_puts(sb, "acl_get_file(pathname = "); 00046 explain_buffer_pathname(sb, pathname); 00047 explain_string_buffer_puts(sb, ", type = "); 00048 explain_buffer_acl_type(sb, type); 00049 explain_string_buffer_putc(sb, ')'); 00050 } 00051 00052 00053 void explain_buffer_errno_acl_get_file_explanation(explain_string_buffer_t *sb, 00054 int errnum, const char *syscall_name, const char *pathname, 00055 acl_type_t type) 00056 { 00057 explain_final_t final_component; 00058 00059 (void)type; 00060 explain_final_init(&final_component); 00061 final_component.want_to_modify_inode = 0; 00062 00063 /* 00064 * http://www.opengroup.org/onlinepubs/009695399/functions/acl_get_file.html 00065 */ 00066 switch (errnum) 00067 { 00068 case EFAULT: 00069 if (!pathname) 00070 { 00071 explain_buffer_is_the_null_pointer(sb, "pathname"); 00072 break; 00073 } 00074 if (explain_is_efault_path(pathname)) 00075 { 00076 explain_buffer_efault(sb, "pathname"); 00077 break; 00078 } 00079 goto oops; 00080 00081 case EACCES: 00082 /* 00083 * search permission is denied for a component of the 00084 * path prefix or the object exists and the process does 00085 * not have appropriate access rights. 00086 * 00087 * Argument type specifies a type of ACL that cannot be 00088 * associated with pathname. 00089 */ 00090 explain_buffer_eacces(sb, pathname, "pathname", &final_component); 00091 break; 00092 00093 case EINVAL: 00094 if (!pathname) 00095 { 00096 explain_buffer_is_the_null_pointer(sb, "pathname"); 00097 break; 00098 } 00099 explain_string_buffer_printf 00100 ( 00101 sb, 00102 /* FIXME: i18n */ 00103 "the %s argument is not a known ACL type", 00104 "type" 00105 ); 00106 explain_buffer_software_error(sb); 00107 break; 00108 00109 case ENAMETOOLONG: 00110 /* 00111 * The length of the argument pathname is too long. 00112 */ 00113 explain_buffer_enametoolong(sb, pathname, "pathname", &final_component); 00114 break; 00115 00116 case ENOENT: 00117 /* 00118 * The named object does not exist or the argument pathname 00119 * points to an empty string. 00120 */ 00121 explain_buffer_enoent(sb, pathname, "pathname", &final_component); 00122 break; 00123 00124 case ENOMEM: 00125 /* 00126 * The ACL working storage requires more memory than is 00127 * allowed by the hardware or system-imposed memory management 00128 * constraints. 00129 */ 00130 explain_buffer_enomem_user(sb, 0); 00131 break; 00132 00133 case ENOTDIR: 00134 /* 00135 * A component of the path prefix is not a directory. 00136 */ 00137 explain_buffer_enotdir(sb, pathname, "pathname", &final_component); 00138 break; 00139 00140 case ELOOP: 00141 case EMLINK: /* BSD */ 00142 explain_buffer_eloop(sb, pathname, "pathname", &final_component); 00143 break; 00144 00145 case ENOTSUP: 00146 case ENOSYS: 00147 #if defined(EOPNOTSUP) && ENOSYS != EOPNOTSUP 00148 case EOPNOTSUP: 00149 #endif 00150 /* 00151 * The file system on which the file identified by pathname 00152 * is located does not support ACLs, or ACLs are disabled. 00153 */ 00154 explain_buffer_enosys_acl(sb, "pathname", syscall_name); 00155 break; 00156 00157 default: 00158 oops: 00159 explain_buffer_errno_generic(sb, errnum, syscall_name); 00160 break; 00161 } 00162 } 00163 00164 00165 void 00166 explain_buffer_errno_acl_get_file(explain_string_buffer_t *sb, int errnum, const 00167 char *pathname, acl_type_t type) 00168 { 00169 explain_explanation_t exp; 00170 00171 explain_explanation_init(&exp, errnum); 00172 explain_buffer_errno_acl_get_file_system_call(&exp.system_call_sb, errnum, 00173 pathname, type); 00174 explain_buffer_errno_acl_get_file_explanation(&exp.explanation_sb, errnum, 00175 "acl_get_file", pathname, type); 00176 explain_explanation_assemble(&exp, sb); 00177 } 00178 00179 00180 /* vim: set ts=8 sw=4 et : */