Annotation of q_a/samples/sd_flppy/chgflpsd.c, revision 1.1.1.1

1.1       root        1: ////////////////////////////////////////////////////////
                      2: //
                      3: //  Client.c --
                      4: //
                      5: //      This program is a command line oriented
                      6: //      demonstration of the FloppyLocker service
                      7: //      sample, aka floplock.exe
                      8: //
                      9: //      Copyright 1993, Microsoft Corp.  All Rights Reserved
                     10: 
                     11: /****************************************************************************\
                     12: *  INCLUDES, DEFINES, TYPEDEFS
                     13: \****************************************************************************/
                     14: #define STRICT
                     15: #include <windows.h>
                     16: #include <stdio.h>
                     17: #include <stdlib.h>
                     18: #include <string.h>
                     19: 
                     20: #define PERR(api) printf("\n%s: Error %d from %s on line %d",  \
                     21:     __FILE__, GetLastError(), api, __LINE__);
                     22: #define PMSG(msg) printf("\n%s line %d: %s",  \
                     23:     __FILE__, __LINE__, msg);
                     24: 
                     25: /****************************************************************************\
                     26: * GLOBAL VARIABLES
                     27: \****************************************************************************/
                     28: 
                     29: #define              SZ_NAME_BUF 30
                     30: UCHAR   ucMchNameBuf[SZ_NAME_BUF] = "";
                     31: LPTSTR  lpszMchName = (LPTSTR)&ucMchNameBuf;
                     32: UCHAR   ucOperation;
                     33: 
                     34: /****************************************************************************\
                     35: * FUNCTION PROTOTYPES
                     36: \****************************************************************************/
                     37: 
                     38: BOOL CrackArgs(UINT argc, char *argv[]);
                     39: VOID DisplayHelp(VOID);
                     40: 
                     41: VOID main(int argc, char *argv[])
                     42: {
                     43:   char    inbuf[180];
                     44:   char    outbuf[180];
                     45:   DWORD   bytesRead;
                     46:   BOOL    ret;
                     47:   #define               SZ_PIPE_NAME_BUF 50
                     48:   UCHAR   ucPipeNameBuf[SZ_PIPE_NAME_BUF] = "";
                     49:   LPTSTR  lpszPipeName = (LPTSTR)&ucPipeNameBuf;
                     50: 
                     51:   if (!CrackArgs(argc,argv))
                     52:     exit(1);
                     53: 
                     54:   strcpy(lpszPipeName,lpszMchName);
                     55:   strcat(lpszPipeName,"\\pipe\\sd_flppy");
                     56: 
                     57:   outbuf[0] = ucOperation;
                     58:   outbuf[1] = '\0';
                     59: 
                     60:   ret = CallNamedPipe(lpszPipeName,
                     61:                       outbuf,
                     62:                       sizeof(outbuf),
                     63:                       inbuf,
                     64:                       sizeof(inbuf),
                     65:                       &bytesRead,
                     66:                       NMPWAIT_WAIT_FOREVER);
                     67: 
                     68:   if (!ret)
                     69:   { if (ERROR_ACCESS_DENIED == GetLastError())
                     70:     { printf("\nAccess denied\n");
                     71:     }
                     72:     else if (ERROR_BAD_NETPATH == GetLastError())
                     73:     { printf("\nMachine %s not found\n",lpszMchName);
                     74:     }
                     75:     else
                     76:     { PERR("CallNamedPipe");
                     77:     }
                     78:     exit(1);
                     79:   }
                     80: 
                     81:   printf("\n%s %s\n",lpszMchName,inbuf);
                     82: }
                     83: 
                     84: /****************************************************************************\
                     85: *
                     86: * FUNCTION: CrackArgs
                     87: *
                     88: \****************************************************************************/
                     89: 
                     90: BOOL CrackArgs(UINT argc, char *argv[])
                     91: {
                     92:   char *p;
                     93: 
                     94:   /**************************************************************************\
                     95:   *
                     96:   * There must be two arguments
                     97:   *
                     98:   \**************************************************************************/
                     99: 
                    100:   if (argc != 3)
                    101:   { DisplayHelp();
                    102:     return(FALSE);
                    103:   }
                    104: 
                    105:   p=argv[1];
                    106: 
                    107:   /**************************************************************************\
                    108:   *
                    109:   * The machine name argument must be 3 to (SZ_NAME_BUF-3) chars long
                    110:   *
                    111:   \**************************************************************************/
                    112: 
                    113:   if ((strlen(p) < 3) || (strlen(p) > (SZ_NAME_BUF-3) ))
                    114:   { DisplayHelp();
                    115:     return(FALSE);
                    116:   }
                    117: 
                    118:   /**************************************************************************\
                    119:   *
                    120:   * The first two chars in the machine name argument must be \
                    121:   *
                    122:   \**************************************************************************/
                    123: 
                    124:   if ('\\' != *p)
                    125:   { DisplayHelp();
                    126:     return(FALSE);
                    127:   }
                    128:   if ('\\' != *(p+1))
                    129:   { DisplayHelp();
                    130:     return(FALSE);
                    131:   }
                    132: 
                    133:   /**************************************************************************\
                    134:   *
                    135:   * Set up the machine name
                    136:   *
                    137:   \**************************************************************************/
                    138: 
                    139:   strcpy(lpszMchName,"\\\\");
                    140:   strcat(lpszMchName,(p+2));
                    141: 
                    142: 
                    143:   p=argv[2];
                    144: 
                    145:   /**************************************************************************\
                    146:   *
                    147:   * The switch argument must be 2 chars long
                    148:   *
                    149:   \**************************************************************************/
                    150: 
                    151:   if (strlen(p) != 2)
                    152:   { DisplayHelp();
                    153:     return(FALSE);
                    154:   }
                    155: 
                    156:   /**************************************************************************\
                    157:   *
                    158:   * The first char in the switch argument must be /
                    159:   *
                    160:   \**************************************************************************/
                    161: 
                    162:   if ('/' != *p)
                    163:   { DisplayHelp();
                    164:     return(FALSE);
                    165:   }
                    166: 
                    167:   /**************************************************************************\
                    168:   *
                    169:   * Chars 2 must be U or L or Q
                    170:   *
                    171:   \**************************************************************************/
                    172: 
                    173: 
                    174:   switch (*(p+1))
                    175:   { case 'u':
                    176:     case 'U':
                    177:       ucOperation = 'U';
                    178:       break;
                    179:     case 'l':
                    180:     case 'L':
                    181:       ucOperation = 'L';
                    182:       break;
                    183:     case 'q':
                    184:     case 'Q':
                    185:       ucOperation = 'Q';
                    186:       break;
                    187:     default :
                    188:       DisplayHelp();
                    189:       return(FALSE);
                    190:   }
                    191: 
                    192:   return(TRUE);
                    193: }
                    194: 
                    195: /****************************************************************************\
                    196: *
                    197: * FUNCTION: DisplayHelp
                    198: *
                    199: \****************************************************************************/
                    200: 
                    201: VOID DisplayHelp(VOID)
                    202: {
                    203:   printf("\nusage: chgflpsd \\\\machinenam /switch");
                    204:   printf("\n                  Values for /switch");
                    205:   printf("\n                        /u      Unlock");
                    206:   printf("\n                        /l      Lock");
                    207:   printf("\n                        /q      Query\n");
                    208:   printf("\nFor example to manage DACLs on machine \\\\flip5's floppies");
                    209:   printf("\n       chgflpsd \\\\flip5 /u      Gives access to everyone");
                    210:   printf("\n       chgflpsd \\\\flip5 /l      Gives access to only local admins");
                    211:   printf("\n       chgflpsd \\\\flip5 /q      Query current access on \\\\flip5\n");
                    212: 
                    213:   return;
                    214: }

unix.superglobalmegacorp.com

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