File:  [WindowsNT SDKs] / q_a / samples / sd_flppy / chgflpsd.c
Revision 1.1.1.1 (vendor branch): download - view: text, annotated - select for diffs
Thu Aug 9 18:29:42 2018 UTC (7 years, 9 months ago) by root
Branches: msft, MAIN
CVS tags: ntsdk-nov-1993, ntsdk-jul-1993, HEAD
Microsoft Windows NT Build 511 (SDK Final Release) 07-24-1993

////////////////////////////////////////////////////////
//
//  Client.c --
//
//      This program is a command line oriented
//      demonstration of the FloppyLocker service
//      sample, aka floplock.exe
//
//      Copyright 1993, Microsoft Corp.  All Rights Reserved

/****************************************************************************\
*  INCLUDES, DEFINES, TYPEDEFS
\****************************************************************************/
#define STRICT
#include <windows.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#define PERR(api) printf("\n%s: Error %d from %s on line %d",  \
    __FILE__, GetLastError(), api, __LINE__);
#define PMSG(msg) printf("\n%s line %d: %s",  \
    __FILE__, __LINE__, msg);

/****************************************************************************\
* GLOBAL VARIABLES
\****************************************************************************/

#define              SZ_NAME_BUF 30
UCHAR   ucMchNameBuf[SZ_NAME_BUF] = "";
LPTSTR  lpszMchName = (LPTSTR)&ucMchNameBuf;
UCHAR   ucOperation;

/****************************************************************************\
* FUNCTION PROTOTYPES
\****************************************************************************/

BOOL CrackArgs(UINT argc, char *argv[]);
VOID DisplayHelp(VOID);

VOID main(int argc, char *argv[])
{
  char    inbuf[180];
  char    outbuf[180];
  DWORD   bytesRead;
  BOOL    ret;
  #define               SZ_PIPE_NAME_BUF 50
  UCHAR   ucPipeNameBuf[SZ_PIPE_NAME_BUF] = "";
  LPTSTR  lpszPipeName = (LPTSTR)&ucPipeNameBuf;

  if (!CrackArgs(argc,argv))
    exit(1);

  strcpy(lpszPipeName,lpszMchName);
  strcat(lpszPipeName,"\\pipe\\sd_flppy");

  outbuf[0] = ucOperation;
  outbuf[1] = '\0';

  ret = CallNamedPipe(lpszPipeName,
                      outbuf,
                      sizeof(outbuf),
                      inbuf,
                      sizeof(inbuf),
                      &bytesRead,
                      NMPWAIT_WAIT_FOREVER);

  if (!ret)
  { if (ERROR_ACCESS_DENIED == GetLastError())
    { printf("\nAccess denied\n");
    }
    else if (ERROR_BAD_NETPATH == GetLastError())
    { printf("\nMachine %s not found\n",lpszMchName);
    }
    else
    { PERR("CallNamedPipe");
    }
    exit(1);
  }

  printf("\n%s %s\n",lpszMchName,inbuf);
}

/****************************************************************************\
*
* FUNCTION: CrackArgs
*
\****************************************************************************/

BOOL CrackArgs(UINT argc, char *argv[])
{
  char *p;

  /**************************************************************************\
  *
  * There must be two arguments
  *
  \**************************************************************************/

  if (argc != 3)
  { DisplayHelp();
    return(FALSE);
  }

  p=argv[1];

  /**************************************************************************\
  *
  * The machine name argument must be 3 to (SZ_NAME_BUF-3) chars long
  *
  \**************************************************************************/

  if ((strlen(p) < 3) || (strlen(p) > (SZ_NAME_BUF-3) ))
  { DisplayHelp();
    return(FALSE);
  }

  /**************************************************************************\
  *
  * The first two chars in the machine name argument must be \
  *
  \**************************************************************************/

  if ('\\' != *p)
  { DisplayHelp();
    return(FALSE);
  }
  if ('\\' != *(p+1))
  { DisplayHelp();
    return(FALSE);
  }

  /**************************************************************************\
  *
  * Set up the machine name
  *
  \**************************************************************************/

  strcpy(lpszMchName,"\\\\");
  strcat(lpszMchName,(p+2));


  p=argv[2];

  /**************************************************************************\
  *
  * The switch argument must be 2 chars long
  *
  \**************************************************************************/

  if (strlen(p) != 2)
  { DisplayHelp();
    return(FALSE);
  }

  /**************************************************************************\
  *
  * The first char in the switch argument must be /
  *
  \**************************************************************************/

  if ('/' != *p)
  { DisplayHelp();
    return(FALSE);
  }

  /**************************************************************************\
  *
  * Chars 2 must be U or L or Q
  *
  \**************************************************************************/


  switch (*(p+1))
  { case 'u':
    case 'U':
      ucOperation = 'U';
      break;
    case 'l':
    case 'L':
      ucOperation = 'L';
      break;
    case 'q':
    case 'Q':
      ucOperation = 'Q';
      break;
    default :
      DisplayHelp();
      return(FALSE);
  }

  return(TRUE);
}

/****************************************************************************\
*
* FUNCTION: DisplayHelp
*
\****************************************************************************/

VOID DisplayHelp(VOID)
{
  printf("\nusage: chgflpsd \\\\machinenam /switch");
  printf("\n                  Values for /switch");
  printf("\n                        /u      Unlock");
  printf("\n                        /l      Lock");
  printf("\n                        /q      Query\n");
  printf("\nFor example to manage DACLs on machine \\\\flip5's floppies");
  printf("\n       chgflpsd \\\\flip5 /u      Gives access to everyone");
  printf("\n       chgflpsd \\\\flip5 /l      Gives access to only local admins");
  printf("\n       chgflpsd \\\\flip5 /q      Query current access on \\\\flip5\n");

  return;
}

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.