Source

blake / blake_authorisedclients.c

Full commit
/*
Copyright (C) 2001-2006 Daybo Logic.
All rights reserved.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
1. Redistributions of source code must retain the above copyright
   notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
   notice, this list of conditions and the following disclaimer in the
   documentation and/or other materials provided with the distribution.
3. Neither the name of the project nor the names of its contributors
   may be used to endorse or promote products derived from this software
   without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED.  IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
SUCH DAMAGE.
*/
/*
  Functions for dealing with the secure authorised closed source clients.
  Nothing to do with the "Open Blake" clients.
  Everything here is to do with that mechanism of ensuring a client
  is authentically Daybo Logic authorised.  If it's not we disconnect
  them =)
*/

#define BLAKE_SOURCE

#ifdef HAVE_CONFIG_H
# include "config.h"
#endif /*HAVE_CONFIG_H*/

#include <stdio.h>
#include <time.h>

#ifdef HAVE_LIMITS_H
# include <limits.h>
#endif /*HAVE_LIMITS_H*/

#ifdef HAVE_STRING_H
# include <string.h>
#endif /*HAVE_STRING_H*/

#ifdef BLAKE_HDRSTOP
# pragma hdrstop
#endif /*BLAKE_HDRSTOP*/

#ifdef HAVE_DLSTDINC_H
# include "dlstdinc.h"
#endif /*HAVE_DLSTDINC_H*/

#include "blake_threads.h"
#include "blake.h"
#include "blake_authorisedclients.h"
/*---------------------------------------------------------------------*/
static const char *rcsid =
  "$Id: blake_authorisedclients.c,v 0.6 2006/03/16 21:11:00 ddrp Exp $";

static const char* ClientIDs[] = {
  "OberChatten (C)2002 Daybo Logic, all rights reserved.",
  "OCTurbo (C) Daybo Logic, all rights reserved.",
  "OCLogin (debugging client)",
  "DDRP login (private debugging client)",
  "OC32 (C) 2001 digiServ, Total Konfuzion, all rights reserved.",
  "Java client",
  "Sarah (C) 2002 Neil Dagger."
};

/* Fill these in on our first run */
static unsigned int ClientIDLengths[sizeof(ClientIDs)/sizeof(ClientIDs[0])];
/*-------------------------------------------------------------------------*/
static void CopyStringToCaller(
  const char *Source,
  char *PBuffOut,
  const size_t MaxBuffSz
);
static void InitClientIDLengths(void);
/*---------------------------------------------------------------------*/
void blake_int_authorisedclients_NCI()
{
    blake_Unused(rcsid);
}
/*---------------------------------------------------------------------*/
BLAKEAPI(unsigned int) blake_GetClientIDString(
  const enum blakeClientID ClientID,
  char *PBuffOut,
  const size_t MaxBuffSz
)
{
  const char def[] = "UNKNOWN";
  static unsigned int deflen;
  static bool ran_once; /* flag for initialisation */

  if ( !ran_once ) {
    ran_once = true; /* Don't run init again */
    deflen = strlen(def);
    InitClientIDLengths();
  }

  if ( ClientID >= sizeof(ClientIDs)/sizeof(ClientIDs[0]) ) {
    CopyStringToCaller(def, PBuffOut, MaxBuffSz);
    return deflen;
  }

  CopyStringToCaller(ClientIDs[ClientID], PBuffOut, MaxBuffSz);
  return ClientIDLengths[ClientID];
}
/*-------------------------------------------------------------------------*/
static void CopyStringToCaller(
  const char *Source,
  char *PBuffOut,
  const size_t MaxBuffSz
)
{
  if ( PBuffOut && MaxBuffSz ) {
    PBuffOut[0] = '\0';
    strncat(PBuffOut, Source, MaxBuffSz-1);
  }
}
/*-------------------------------------------------------------------------*/
static void InitClientIDLengths()
{
  /* Init the string lengths for fast access */
  unsigned int i, c;
  c = sizeof(ClientIDs)/sizeof(ClientIDs[0]);

  for ( i = 0U; i < c; i++ )
    ClientIDLengths[i] = strlen(ClientIDs[i]);

  return;
}
/*-------------------------------------------------------------------------*/