view libtomcrypt/demos/constants.c @ 1930:299f4f19ba19

Add /usr/sbin and /sbin to default root PATH When dropbear is used in a very restricted environment (such as in a initrd), the default user shell is often also very restricted and doesn't take care of setting the PATH so the user ends up with the PATH set by dropbear. Unfortunately, dropbear always sets "/usr/bin:/bin" as default PATH even for the root user which should have /usr/sbin and /sbin too. For a concrete instance of this problem, see the "Remote Unlocking" section in this tutorial: https://paxswill.com/blog/2013/11/04/encrypted-raspberry-pi/ It speaks of a bug in the initramfs script because it's written "blkid" instead of "/sbin/blkid"... this is just because the scripts from the initramfs do not expect to have a PATH without the sbin directories and because dropbear is not setting the PATH appropriately for the root user. I'm thus suggesting to use the attached patch to fix this misbehaviour (I did not test it, but it's easy enough). It might seem anecdotic but multiple Kali users have been bitten by this. From https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=903403
author Raphael Hertzog <hertzog@debian.org>
date Mon, 09 Jul 2018 16:27:53 +0200
parents e9dba7abd939
children
line wrap: on
line source

/* LibTomCrypt, modular cryptographic library -- Tom St Denis
 *
 * LibTomCrypt is a library that provides various cryptographic
 * algorithms in a highly modular and flexible manner.
 *
 * The library is free for all purposes without any express
 * guarantee it works.
 */
#include "tomcrypt.h"

#if defined(_POSIX_C_SOURCE) && _POSIX_C_SOURCE >= 200112L
#include <libgen.h>
#else
#define basename(x) x
#endif

/**
  @file demo_crypt_constants.c

  Demo how to get various constants to dynamic languages
  like Python

  Larry Bugbee, February 2013
*/

static void _print_line(const char* cmd, const char* desc)
{
   printf("  %-16s - %s\n", cmd, desc);
}

int main(int argc, char **argv)
{
   if (argc == 1) {
      /* given a specific constant name, get and print its value */
      char name[] = "CTR_COUNTER_BIG_ENDIAN";
      int value;
      char *names_list;
      unsigned int names_list_len;

      if (crypt_get_constant(name, &value) != 0) exit(EXIT_FAILURE);
      printf("\n  %s is %d \n\n", name, value);

      /* get and print the length of the names (and values) list */

      if (crypt_list_all_constants(NULL, &names_list_len) != 0) exit(EXIT_FAILURE);
      printf("  need to allocate %u bytes \n\n", names_list_len);

      /* get and print the names (and values) list */
      if ((names_list = malloc(names_list_len)) == NULL) exit(EXIT_FAILURE);
      if (crypt_list_all_constants(names_list, &names_list_len) != 0) exit(EXIT_FAILURE);
      printf("  supported constants:\n\n%s\n\n", names_list);
      free(names_list);
   } else if (argc == 2) {
      if (strcmp(argv[1], "-h") == 0 || strcmp(argv[1], "--help") == 0) {
         char* base = strdup(basename(argv[0]));
         printf("Usage: %s [-a] [-s name]\n\n", base);
         _print_line("<no argument>", "The old behavior of the demo");
         _print_line("-a", "Only lists all constants");
         _print_line("-s name", "List a single constant given as argument");
         _print_line("-h", "The help you're looking at");
         free(base);
      } else if (strcmp(argv[1], "-a") == 0) {
         char *names_list;
         unsigned int names_list_len;
         /* get and print the length of the names (and values) list */
         if (crypt_list_all_constants(NULL, &names_list_len) != 0) exit(EXIT_FAILURE);
         /* get and print the names (and values) list */
         if ((names_list = malloc(names_list_len)) == NULL) exit(EXIT_FAILURE);
         if (crypt_list_all_constants(names_list, &names_list_len) != 0) exit(EXIT_FAILURE);
         printf("%s\n", names_list);
         free(names_list);
      }
   } else if (argc == 3) {
      if (strcmp(argv[1], "-s") == 0) {
         int value;
         if (crypt_get_constant(argv[2], &value) != 0) exit(EXIT_FAILURE);
         printf("%s,%u\n", argv[2], value);
      }
   }

   return 0;
}


/* ref:         $Format:%D$ */
/* git commit:  $Format:%H$ */
/* commit time: $Format:%ai$ */