extractor_helper.c (2837B)
1 /* 2 This file is part of libextractor. 3 Copyright (C) 2026 Vidyut Samanta and Christian Grothoff 4 5 libextractor is free software; you can redistribute it and/or modify 6 it under the terms of the GNU General Public License as published 7 by the Free Software Foundation; either version 3, or (at your 8 option) any later version. 9 10 libextractor is distributed in the hope that it will be useful, but 11 WITHOUT ANY WARRANTY; without even the implied warranty of 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 General Public License for more details. 14 15 You should have received a copy of the GNU General Public License 16 along with libextractor; see the file COPYING. If not, write to the 17 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 18 Boston, MA 02110-1301, USA. 19 */ 20 /** 21 * @file main/extractor_helper.c 22 * @brief program that runs one plugin out-of-process; started by 23 * extractor_ipc_gnu.c, never by hand 24 * @author Christian Grothoff 25 */ 26 #include "platform.h" 27 #include "extractor.h" 28 #include "extractor_plugins.h" 29 #include "extractor_plugin_main.h" 30 #if HAVE_SYS_APPARMOR_H 31 #include <sys/apparmor.h> 32 #endif 33 34 35 /** 36 * Run a plugin for the process that started us. 37 * 38 * @param argc number of arguments, 5 or 6 39 * @param argv file descriptor to read requests from, file descriptor 40 * to write replies to, full path of the plugin, its short name 41 * and, optionally, its options 42 * @return 1 on usage errors, otherwise does not return 43 */ 44 int 45 main (int argc, 46 char *const *argv) 47 { 48 struct EXTRACTOR_PluginList plugin; 49 int in; 50 int out; 51 52 if ( (argc < 5) || 53 (argc > 6) ) 54 { 55 fprintf (stderr, 56 "%s runs plugins for GNU libextractor and is not meant to be started directly\n", 57 argv[0]); 58 return 1; 59 } 60 in = atoi (argv[1]); 61 out = atoi (argv[2]); 62 #if HAVE_SYS_APPARMOR_H 63 #if HAVE_APPARMOR 64 if (0 > aa_change_profile ("libextractor")) 65 { 66 int eno = errno; 67 68 if ( (EINVAL != eno) && 69 (ENOENT != eno) ) 70 { 71 fprintf (stderr, 72 "Failure changing AppArmor profile: %s\n", 73 strerror (eno)); 74 _exit (1); 75 } 76 } 77 #endif 78 #endif 79 memset (&plugin, 80 0, 81 sizeof (plugin)); 82 /* EXTRACTOR_plugin_load_() frees the name if loading fails */ 83 if (NULL == (plugin.libname = strdup (argv[3]))) 84 _exit (1); 85 plugin.short_libname = argv[4]; 86 plugin.plugin_options = (6 == argc) ? argv[5] : NULL; 87 plugin.flags = EXTRACTOR_OPTION_DEFAULT_POLICY; 88 EXTRACTOR_plugin_main_ (&plugin, 89 in, 90 out); 91 /* like the forked child we replace: skip destructors of the 92 plugin's libraries, some of which do not survive them */ 93 _exit (0); 94 } 95 96 97 /* end of extractor_helper.c */