<commit_before>#include "config.h"

#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <pwd.h>
#include <grp.h>
#include <fnmatch.h>
#include <ctype.h>
#ifdef HAVE_ALLOCA_H
#include <alloca.h>
#endif
#include <Eina.h>

/* local subsystem functions */
static int auth_action_ok(char *a,
                          uid_t uid,
                          gid_t gid,
                          gid_t *gl,
                          int gn,
                          gid_t egid);
static int auth_etc_enlightenment_sysactions(char *a,
                                             char *u,
                                             char **g);
static char *get_word(char *s,
                      char *d);

/* local subsystem globals */
static Eina_Hash *actions = NULL;

/* externally accessible functions */
int
main(int argc,
     char **argv)
{
   int i, gn;
   int test = 0;
   Eina_Bool mnt = EINA_FALSE;
   char *action, *cmd;
   uid_t uid;
   gid_t gid, gl[65536], egid;

   for (i = 1; i < argc; i++)
     {
        if ((!strcmp(argv[i], "-h")) ||
            (!strcmp(argv[i], "-help")) ||
            (!strcmp(argv[i], "--help")))
          {
             printf(
               "This is an internal tool for Enlightenment.\n"
               "do not use it.\n"
               );
             exit(0);
          }
     }
   if (argc >= 3)
     {
        if ((argc == 3) && (!strcmp(argv[1], "-t")))
          {
             test = 1;
             action = argv[2];
          }
        else
          {
             const char *s;

             s = strrchr(argv[1], '/');
             if ((!s) || (!(++s))) exit(1); /* eeze always uses complete path */
             if (strcmp(s, "mount") && strcmp(s, "umount") && strcmp(s, "eject")) exit(1);
             mnt = EINA_TRUE;
             action = argv[1];
          }
     }
   else if (argc == 2)
     {
        action = argv[1];
     }
   else
     {
        exit(1);
     }

   uid = getuid();
   gid = getgid();
   egid = getegid();
   gn = getgroups(65536, gl);
   if (gn < 0)
     {
        printf("ERROR: MEMBER OF MORE THAN 65536 GROUPS\n");
        exit(3);
     }
   if (setuid(0) != 0)
     {
        printf("ERROR: UNABLE TO ASSUME ROOT PRIVILEGES\n");
        exit(5);
     }
   if (setgid(0) != 0)
     {
        printf("ERROR: UNABLE TO ASSUME ROOT GROUP PRIVILEGES\n");
        exit(7);
     }

   eina_init();

   if (!auth_action_ok(action, uid, gid, gl, gn, egid))
     {
        printf("ERROR: ACTION NOT ALLOWED: %s\n", action);
        exit(10);
     }
   /* we can add more levels of auth here */

   /* when mounting, this will match the exact path to the exe,
    * as required in sysactions.conf
    * this is intentionally pedantic for security
    */
   cmd = eina_hash_find(actions, action);
   if (!cmd)
     {
        printf("ERROR: UNDEFINED ACTION: %s\n", action);
        exit(20);
     }
   if ((!test) && (!mnt)) return system(cmd);
   if (mnt)
     {
        Eina_Strbuf *buf;
        int ret = 0;
        const char *mp = NULL;

        buf = eina_strbuf_new();
        if (!buf) goto err;
        for (i = 1; i < argc; i++)
          {
             if (!strncmp(argv[i], "/media/", 7))
               {
                  mp = argv[i];
                  if (!strcmp(action, "mount"))
                    {
                       struct stat s;

                       if (stat("/media", &s))
                         {
                            mode_t um;

                            um = umask(0);
                            if (mkdir("/media", S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH))
                              {
                                 printf("ERROR: COULD NOT CREATE DIRECTORY /media\n");
                                 exit(40);
                              }
                            umask(um);
                         }
                       else if (!S_ISDIR(s.st_mode))
                         {
                            printf("ERROR: NOT A DIRECTORY: /media\n");
                            exit(40);
                         }

                       if (stat(argv[i], &s))
                         {
                            mode_t um;

                            um = umask(0);
                            if (mkdir(argv[i], S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH))
                              {
                                 printf("ERROR: COULD NOT CREATE DIRECTORY %s\n", argv[i]);
                                 exit(40);
                              }
                            umask(um);
                         }
                       else if (!S_ISDIR(s.st_mode))
                         {
                            printf("ERROR: NOT A DIRECTORY: %s\n", argv[i]);
                            exit(40);
                         }
                    }
               }
             eina_strbuf_append_printf(buf, "%s ", argv[i]);
          }
        ret = system(eina_strbuf_string_get(buf));
        if ((!strcmp(action, "umount")) && (!ret))
          {<commit_msg>I guess make this explicit even though it will never happen<commit_after>#include "config.h"

#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <pwd.h>
#include <grp.h>
#include <fnmatch.h>
#include <ctype.h>
#ifdef HAVE_ALLOCA_H
#include <alloca.h>
#endif
#include <Eina.h>

/* local subsystem functions */
static int auth_action_ok(char *a,
                          uid_t uid,
                          gid_t gid,
                          gid_t *gl,
                          int gn,
                          gid_t egid);
static int auth_etc_enlightenment_sysactions(char *a,
                                             char *u,
                                             char **g);
static char *get_word(char *s,
                      char *d);

/* local subsystem globals */
static Eina_Hash *actions = NULL;

/* externally accessible functions */
int
main(int argc,
     char **argv)
{
   int i, gn;
   int test = 0;
   Eina_Bool mnt = EINA_FALSE;
   char *action, *cmd;
   uid_t uid;
   gid_t gid, gl[65536], egid;

   for (i = 1; i < argc; i++)
     {
        if ((!strcmp(argv[i], "-h")) ||
            (!strcmp(argv[i], "-help")) ||
            (!strcmp(argv[i], "--help")))
          {
             printf(
               "This is an internal tool for Enlightenment.\n"
               "do not use it.\n"
               );
             exit(0);
          }
     }
   if (argc >= 3)
     {
        if ((argc == 3) && (!strcmp(argv[1], "-t")))
          {
             test = 1;
             action = argv[2];
          }
        else
          {
             const char *s;

             s = strrchr(argv[1], '/');
             if ((!s) || (!(++s))) exit(1); /* eeze always uses complete path */
             if (strcmp(s, "mount") && strcmp(s, "umount") && strcmp(s, "eject")) exit(1);
             mnt = EINA_TRUE;
             action = argv[1];
          }
     }
   else if (argc == 2)
     {
        action = argv[1];
     }
   else
     {
        exit(1);
     }

   uid = getuid();
   gid = getgid();
   egid = getegid();
   gn = getgroups(65536, gl);
   if (gn < 0)
     {
        printf("ERROR: MEMBER OF MORE THAN 65536 GROUPS\n");
        exit(3);
     }
   if (setuid(0) != 0)
     {
        printf("ERROR: UNABLE TO ASSUME ROOT PRIVILEGES\n");
        exit(5);
     }
   if (setgid(0) != 0)
     {
        printf("ERROR: UNABLE TO ASSUME ROOT GROUP PRIVILEGES\n");
        exit(7);
     }

   eina_init();

   if (!auth_action_ok(action, uid, gid, gl, gn, egid))
     {
        printf("ERROR: ACTION NOT ALLOWED: %s\n", action);
        exit(10);
     }
   /* we can add more levels of auth here */

   /* when mounting, this will match the exact path to the exe,
    * as required in sysactions.conf
    * this is intentionally pedantic for security
    */
   cmd = eina_hash_find(actions, action);
   if (!cmd)
     {
        printf("ERROR: UNDEFINED ACTION: %s\n", action);
        exit(20);
     }
   if ((!test) && (!mnt)) return system(cmd);
   if (mnt)
     {
        Eina_Strbuf *buf;
        int ret = 0;
        const char *mp = NULL;

        buf = eina_strbuf_new();
        if (!buf) goto err;
        for (i = 1; i < argc; i++)
          {
             if (!strncmp(argv[i], "/media/", 7))
               {
                  mp = argv[i];
                  if (!strcmp(action, "mount"))
                    {
                       struct stat s;

                       if (stat("/media", &s))
                         {
                            mode_t um;

                            um = umask(0);
                            if (mkdir("/media", S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH))
                              {
                                 printf("ERROR: COULD NOT CREATE DIRECTORY /media\n");
                                 exit(40);
                              }
                            umask(um);
                         }
                       else if (!S_ISDIR(s.st_mode))
                         {
                            printf("ERROR: NOT A DIRECTORY: /media\n");
                            exit(40);
                         }

                       if (stat(argv[i], &s))
                         {
                            mode_t um;

                            um = umask(0);
                            if (mkdir(argv[i], S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH))
                              {
                                 printf("ERROR: COULD NOT CREATE DIRECTORY %s\n", argv[i]);
                                 exit(40);
                              }
                            umask(um);
                         }
                       else if (!S_ISDIR(s.st_mode))
                         {
                            printf("ERROR: NOT A DIRECTORY: %s\n", argv[i]);
                            exit(40);
                         }
                    }
               }
             eina_strbuf_append_printf(buf, "%s ", argv[i]);
          }
        ret = system(eina_strbuf_string_get(buf));
        if (mp && (!strcmp(action, "umount")) && (!ret))
          {
{'fraction_non_alphanumeric': 0.12990291262135922, 'fraction_numerical': 0.010679611650485437, 'mean_word_length': 1.0630883236531143, 'pattern_counts': {'":': 0, '<': 33, '<?xml version=': 0, '>': 29, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 16, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7180485', 'n_tokens_mistral': 3257, 'n_tokens_neox': 3072, 'n_words': 761}