(root)/
libxcrypt-4.4.36/
lib/
util-make-failure-token.c
       1  /* Copyright (C) 2018-2019 Björn Esser <besser82@fedoraproject.org>
       2   *
       3   * Redistribution and use in source and binary forms, with or without
       4   * modification, are permitted.
       5   *
       6   * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
       7   * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
       8   * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
       9   * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
      10   * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
      11   * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
      12   * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
      13   * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
      14   * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
      15   * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
      16   * SUCH DAMAGE.
      17   */
      18  
      19  #include "crypt-port.h"
      20  
      21  /* Fill the output buffer with a failure token.  */
      22  void
      23  make_failure_token (const char *setting, char *output, int size)
      24  {
      25    if (size >= 3)
      26      {
      27        output[0] = '*';
      28        output[1] = '0';
      29        output[2] = '\0';
      30  
      31        if (setting && setting[0] == '*' && setting[1] == '0')
      32          output[1] = '1';
      33      }
      34  
      35    /* If there's not enough space for the full failure token, do the
      36       best we can.  */
      37    else if (size == 2)
      38      {
      39        output[0] = '*';
      40        output[1] = '\0';
      41      }
      42    else if (size == 1)
      43      {
      44        output[0] = '\0';
      45      }
      46  }