⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 security.c

📁 大量的汇编程序源代码
💻 C
📖 第 1 页 / 共 3 页
字号:

   while ( (parameter = strtok( token, WHITESPACE )) != NULL)
   {
      token = strtok( NULL, ""); /* Save for next pass               */
#ifdef _DEBUG
      printmsg(8,"InitEntry: Parameter is \"%s\"", parameter);
      if ( token != NULL )
         printmsg(10,"InitEntry: Buffer remaining is \"%s\"", token);
#endif
      if (!processconfig(parameter, SYSTEM_CONFIG,B_UUXQT,securetable,NULL))
      {
         printmsg(0,
          "Unknown keyword \"%s\" in %s ignored",parameter, fname);
         success = FALSE;
      } /* if */
   } /* while ( (parameter = strtok( token, WHITESPACE )) != NULL) */

   anchor->commands = (char **) commands;
   anchor->validate = (char **) validate;

/*--------------------------------------------------------------------*/
/*    Now we have the data procesed by keyword, break it down more    */
/*--------------------------------------------------------------------*/

   if ((logname == NULL) && (machine == NULL))
   {
      printmsg(0,"InitEntry: No machine or logname given in %s",
                  fname );
      success = FALSE;
   } /* if ((logname == NULL) && (machine == NULL)) */

/*--------------------------------------------------------------------*/
/*                        Handle a login name                         */
/*--------------------------------------------------------------------*/

   if (logname != NULL)
   {
      printmsg(10,"InitEntry: Processing logname=%s",logname );
      userp = checkuser( logname );
      if ( userp == BADUSER )
      {
         printmsg(0,"InitEntry: Invalid user id in %s, LOGNAME=%s",
                     fname, logname );
         success = FALSE;
      } /* if ( userp == BADUSER ) */
      else if (userp->hsecure == NULL)
         userp->hsecure = anchor;
      else {
         printmsg(0,"InitEntry: Duplicate user id in %s, LOGNAME=%s",
                     fname, logname );
         success = FALSE;
      } /* else */
   } /* if (logname != NULL) */

/*--------------------------------------------------------------------*/
/*                        Handle machine names                        */
/*--------------------------------------------------------------------*/

   token = machine;
   while( token != NULL )
   {
      char *host = strtok( token, ":");
      printmsg(10,"InitEntry: Processing machine=%s", host );

      token = strtok( NULL, "");
      if ( equal( host , ANY_HOST ) )
      {
         if ( default_security == NULL )
            default_security = anchor;
         else {
            printmsg(0,"InitEntry: "
                       "Multiple MACHINE entries in %s which specify OTHER",
                       fname);
            success = FALSE;
         } /* else */
      } /* if ( equal( host , ANY_HOST ) ) */
      else {
         hostp = checkreal( host );
         if ( hostp == BADUSER )
         {
            printmsg(0,"InitEntry: Invalid host id in %s, MACHINE=%s",
                        fname, host );
            success = FALSE;
         } /* if ( hostp == BADUSER ) */
         else if (hostp->hsecure == NULL)
            hostp->hsecure = anchor;
         else {
            printmsg(0,"InitEntry: Duplicate host id in %s, MACHINE=%s",
                        fname, token );
            success = FALSE;
         } /* else */
      } /* else */
   } /* while( token != NULL ) */

   if ( machine != NULL )
      free( machine );

/*--------------------------------------------------------------------*/
/*                       Handle validated names                       */
/*--------------------------------------------------------------------*/

   if ( anchor->validate != NULL )
   {
      char **plist = anchor->validate;

      while ( *plist != NULL )
      {
         hostp = checkreal( *plist );

         if ( hostp == BADUSER )
         {
            printmsg(0,"InitEntry: Invalid host id in %s, VALIDATE=%s",
                        fname, *plist);
            success = FALSE;
         } /* if ( hostp == BADUSER ) */
         else
            hostp->anylogin = FALSE;   /* Flag we must use specific
                                          login                      */

         plist++;             /* Step to next hostname in list       */

      } /* while ( *plist != NULL ) */

   } /* if ( anchor->validate != NULL ) */

/*--------------------------------------------------------------------*/
/*                          Handle CALLBACK                           */
/*--------------------------------------------------------------------*/

   if ( callback != NULL )
   {
      if (equal(strlwr(callback),"no"))
         anchor->callback = FALSE;
      else if (equal(callback,"yes"))
         anchor->callback = TRUE;
      else {
         printmsg(0,"InitEntry: Invalid value in %s, CALLBACK=%s",
                     fname, callback );
         success = FALSE;
      } /* else */
   } /* if ( callback != NULL ) */

/*--------------------------------------------------------------------*/
/*                          Handle REQUEST                            */
/*--------------------------------------------------------------------*/

   if ( request != NULL )
   {
      if (equal(strlwr(request),"no"))
         anchor->request = FALSE;
      else if (equal(request,"yes"))
         anchor->request = TRUE;
      else {
         printmsg(0,"InitEntry: Invalid value in %s, REQUEST=%s",
                     fname, request );
         success = FALSE;
      } /* else */

   } /* if ( request != NULL ) */

/*--------------------------------------------------------------------*/
/*                          Handle SENDFILES                          */
/*--------------------------------------------------------------------*/

   if ( sendfiles != NULL)
   {
      if (equal(strlwr(sendfiles),"call"))
         anchor->sendfiles = FALSE;
      else if (equal(sendfiles,"yes"))
         anchor->sendfiles = TRUE;
      else {
         printmsg(0,"InitEntry: Invalid value in %s, SENDFILES=%s",
                     fname, sendfiles );
         success = FALSE;
      } /* else */
   } /* if */

/*--------------------------------------------------------------------*/
/*                          handle commands                           */
/*--------------------------------------------------------------------*/

   if ( anchor->commands == NULL )
      anchor->commands = command_list;

/*--------------------------------------------------------------------*/
/*                 Handle local system name aliasing                  */
/*--------------------------------------------------------------------*/

   if (myname == NULL)
      anchor->myname = E_nodename;
   else
      anchor->myname = myname;

/*--------------------------------------------------------------------*/
/*                      Directory processing                          */
/*--------------------------------------------------------------------*/

   anchor->dirlist = malloc( sizeof anchor->dirlist[0] * max_elements );
   checkref( anchor->dirlist );

   max_elements = InitDir( read,    ALLOW_READ,  TRUE,  anchor,
            max_elements );
   free( read );
   max_elements = InitDir( noread,  ALLOW_READ,  FALSE, anchor,
            max_elements );
   free( noread );
   max_elements = InitDir( write,   ALLOW_WRITE, TRUE,  anchor,
            max_elements );
   free( write );
   max_elements = InitDir( nowrite, ALLOW_WRITE, FALSE, anchor,
                           max_elements );
   free( nowrite );

/*--------------------------------------------------------------------*/
/*                 Provide a default public directory                 */
/*--------------------------------------------------------------------*/

   if (xpubdir == NULL)
       anchor->pubdir = E_pubdir;
   else
       anchor->pubdir = xpubdir;

/*--------------------------------------------------------------------*/
/*    If no explicit directories given, give them access to pubdir    */
/*--------------------------------------------------------------------*/

   if ( anchor->dirsize == 0)
   {
      max_elements = InitDir( anchor->pubdir, ALLOW_READ, TRUE,
                              anchor, max_elements );
      max_elements = InitDir( anchor->pubdir, ALLOW_WRITE, TRUE,
                              anchor, max_elements );
   }

   if ( max_elements == 0 )
      success = FALSE;
   else {
      size_t subscript;
      anchor->dirlist = realloc( anchor->dirlist,
                                 anchor->dirsize * sizeof anchor->dirlist[0]);
      checkref( anchor->dirlist );
      qsort(anchor->dirlist, anchor->dirsize, sizeof(anchor->dirlist[0]),
               dircmp);
      if ( debuglevel > 4 )
      for ( subscript = 0; subscript < anchor->dirsize; subscript++ )
         printmsg(4, "InitEntry: dirlist[%d] %s\t%s\t%s",
                  subscript,
                  anchor->dirlist[subscript].grant ? "grant" : "deny" ,
                  anchor->dirlist[subscript].priv == ALLOW_WRITE ?
                           "WRITE" : "READ" ,
                  anchor->dirlist[subscript].path );
   } /* else */

/*--------------------------------------------------------------------*/
/*                          Return to caller                          */
/*--------------------------------------------------------------------*/

   return success;

} /* InitEntry */

/*--------------------------------------------------------------------*/
/*    I n i t D i r                                                   */
/*                                                                    */
/*    Initialize security table directory entries                     */
/*--------------------------------------------------------------------*/

static size_t InitDir( char *directories,
         const REMOTE_ACCESS access,
         const boolean grant,
         struct HostSecurity *anchor,
         size_t max_elements )
{
   char *field = directories;
   char *token = directories;
   struct  stat    statbuf;
   size_t subscript;

/*--------------------------------------------------------------------*/
/*    Don't process data if no input or we previously had an error    */
/*--------------------------------------------------------------------*/

   if ( (directories == NULL ) || ( max_elements == 0) )
      return max_elements;

/*--------------------------------------------------------------------*/
/*              Begin loop to process names in the path               */
/*--------------------------------------------------------------------*/

   while ( (token = NextField( field )) != NULL)
   {
      char path[FILENAME_MAX];

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -