libexplain  1.4.D001
libexplain/buffer/errno/acl_set_fd.c
Go to the documentation of this file.
00001 /*
00002  * libexplain - Explain errno values returned by libc functions
00003  * Copyright (C) 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 #include <libexplain/ac/acl/libacl.h>
00021 
00022 #include <libexplain/buffer/does_not_have_inode_modify_permission.h>
00023 #include <libexplain/buffer/acl.h>
00024 #include <libexplain/buffer/ebadf.h>
00025 #include <libexplain/buffer/einval.h>
00026 #include <libexplain/buffer/enosys.h>
00027 #include <libexplain/buffer/enospc.h>
00028 #include <libexplain/buffer/erofs.h>
00029 #include <libexplain/buffer/errno/acl_set_fd.h>
00030 #include <libexplain/buffer/errno/generic.h>
00031 #include <libexplain/buffer/fildes.h>
00032 #include <libexplain/buffer/is_the_null_pointer.h>
00033 #include <libexplain/explanation.h>
00034 
00035 
00036 static void
00037 explain_buffer_errno_acl_set_fd_system_call(explain_string_buffer_t *sb,
00038     int errnum, int fildes, acl_t acl)
00039 {
00040     (void)errnum;
00041     explain_string_buffer_puts(sb, "acl_set_fd(fildes = ");
00042     explain_buffer_fildes(sb, fildes);
00043     explain_string_buffer_puts(sb, ", acl = ");
00044     explain_buffer_acl(sb, acl);
00045     explain_string_buffer_putc(sb, ')');
00046 }
00047 
00048 
00049 void
00050 explain_buffer_errno_acl_set_fd_explanation(explain_string_buffer_t *sb,
00051     int errnum, const char *syscall_name, int fildes, acl_t acl)
00052 {
00053     /* acl_type_t type = ACL_TYPE_ACCESS; */
00054 
00055     /*
00056      * http://www.opengroup.org/onlinepubs/009695399/functions/acl_set_fd.html
00057      */
00058     switch (errnum)
00059     {
00060     case EBADF:
00061         /*
00062          * The fildes argument is not a valid file descriptor.
00063          */
00064         explain_buffer_ebadf(sb, fildes, "fildes");
00065         break;
00066 
00067     case EINVAL:
00068         if (!acl)
00069         {
00070             explain_buffer_is_the_null_pointer(sb, "acl");
00071             break;
00072         }
00073         if (acl_valid(acl) < 0)
00074         {
00075             /*
00076              * The argument acl does not point to a valid ACL.
00077              */
00078             explain_string_buffer_printf
00079             (
00080                 sb,
00081                 /* FIXME: i18n */
00082                 "The argument %s does not point to a valid ACL",
00083                 "acl"
00084             );
00085             break;
00086         }
00087 
00088         /*
00089          * The ACL has more entries than the file referred to by fildes
00090          * can obtain.
00091          */
00092         {
00093             long num = acl_entries(acl);
00094 #ifdef _PC_ACL_PATH_MAX
00095             long max = pathconf(pathname, _PC_ACL_PATH_MAX);
00096 #else
00097             long max = -1;
00098 #endif
00099             if (num > max)
00100             {
00101                 explain_string_buffer_printf
00102                 (
00103                     sb,
00104                     /* FIXME: i18n */
00105                     ("The ACL has more entries than the file referred to "
00106                     "by %s can obtain"),
00107                     "fildes"
00108                 );
00109 #ifdef _PC_ACL_PATH_MAX
00110                 if (explain_option_dialect_specific())
00111                 {
00112                     explain_string_buffer_printf(" (%d > %d)", num, max);
00113                 }
00114 #endif
00115                 break;
00116             }
00117         }
00118 
00119         explain_buffer_einval_vague(sb, "acl");
00120         break;
00121 
00122     case ENOSPC:
00123         /*
00124          * The directory or file system that would contain the new
00125          * ACL cannot be extended or the file system is out of file
00126          * allocation resources.
00127          */
00128         explain_buffer_enospc_fildes(sb, fildes, "fildes");
00129         break;
00130 
00131     case ENOSYS:
00132     case ENOTSUP:
00133 #if defined(EOPNOTSUP) && ENOSYS != EOPNOTSUP
00134     case EOPNOTSUP:
00135 #endif
00136         /*
00137          * The file identified by fildes cannot be associated with the ACL
00138          * because the file system on which the file is located does not
00139          * support this.
00140          */
00141         explain_buffer_enosys_acl(sb, "fildes", syscall_name);
00142         break;
00143 
00144     case EPERM:
00145         /*
00146          * The process does not have appropriate privilege to perform
00147          * the operation to set the ACL.
00148          */
00149         explain_buffer_does_not_have_inode_modify_permission_fd
00150         (
00151             sb,
00152             fildes,
00153             "fildes"
00154         );
00155         break;
00156 
00157     case EROFS:
00158         /*
00159          * This function requires modification of a file system which is
00160          * currently read-only.
00161          */
00162         explain_buffer_erofs_fildes(sb, fildes, "fildes");
00163         break;
00164 
00165     default:
00166         explain_buffer_errno_generic(sb, errnum, syscall_name);
00167         break;
00168     }
00169 }
00170 
00171 
00172 void
00173 explain_buffer_errno_acl_set_fd(explain_string_buffer_t *sb, int errnum,
00174     int fildes, acl_t acl)
00175 {
00176     explain_explanation_t exp;
00177 
00178     explain_explanation_init(&exp, errnum);
00179     explain_buffer_errno_acl_set_fd_system_call(&exp.system_call_sb, errnum,
00180         fildes, acl);
00181     explain_buffer_errno_acl_set_fd_explanation(&exp.explanation_sb, errnum,
00182         "acl_set_fd", fildes, acl);
00183     explain_explanation_assemble(&exp, sb);
00184 }
00185 
00186 
00187 /* vim: set ts=8 sw=4 et : */