libexplain  1.4.D001
libexplain/buffer/eperm/mknod.c
Go to the documentation of this file.
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
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/buffer/dac.h>
00020 #include <libexplain/buffer/eperm.h>
00021 #include <libexplain/buffer/file_type.h>
00022 #include <libexplain/buffer/gettext.h>
00023 #include <libexplain/buffer/mount_point.h>
00024 #include <libexplain/capability.h>
00025 #include <libexplain/string_buffer.h>
00026 
00027 
00028 void
00029 explain_buffer_eperm_mknod(explain_string_buffer_t *sb,
00030     const char *pathname, const char *pathname_caption, int mode)
00031 {
00032     explain_string_buffer_t filtyp_sb;
00033     char            filtyp[100];
00034 
00035     explain_string_buffer_init(&filtyp_sb, filtyp, sizeof(filtyp));
00036     explain_buffer_file_type(&filtyp_sb, mode);
00037 
00038     /*
00039      * mode requested creation of something other than a regular file,
00040      * FIFO (named pipe), or Unix domain socket, and the caller is not
00041      * privileged (Linux: does not have the CAP_MKNOD capability); also
00042      * returned if the file system containing pathname does not support
00043      * the type of node requested.
00044      */
00045     if ((S_ISCHR(mode) || S_ISBLK(mode)) && !explain_capability_mknod())
00046     {
00047         explain_string_buffer_printf_gettext
00048         (
00049             sb,
00050             /*
00051              * xgettext: This error message is issued when a system call
00052              * reports an EPERM error, in the case where a file node is
00053              * being created (e.g. mkdir or mknod).
00054              *
00055              * %1$s => The name of the offending syscall argument.
00056              * %2$s => The name of the mount point, in parentheses
00057              * %3$s => The type of node being created, already translated
00058              */
00059             i18n("the process does not have permission to create a %s"),
00060             filtyp
00061         );
00062         explain_buffer_dac_sys_mknod(sb);
00063     }
00064     else
00065     {
00066         explain_string_buffer_t mntpt_sb;
00067         char            mntpt[100];
00068 
00069         explain_string_buffer_init(&mntpt_sb, mntpt, sizeof(mntpt));
00070         explain_buffer_mount_point_dirname(&mntpt_sb, pathname);
00071 
00072         explain_string_buffer_printf_gettext
00073         (
00074             sb,
00075             /*
00076              * xgettext: This error message is issued when a system call
00077              * reports an EPERM error, in the case where a file node is
00078              * being created (e.g. mkdir or mknod).
00079              *
00080              * %1$s => The name of the offending syscall argument.
00081              * %2$s => The name of the mount point, in parentheses
00082              * %3$s => The type of node being created, already translated
00083              */
00084             i18n("the file system containing %s %s does not support the "
00085                 "creation of a %s"),
00086             pathname_caption,
00087             mntpt,
00088             filtyp
00089         );
00090     }
00091 }
00092 
00093 
00094 /* vim: set ts=8 sw=4 et : */