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

📄 _oncrpc.c

📁 This directory contains source code for tcpdump, a tool for network monitoring and data acquisition
💻 C
字号:
/*
 * Copyright (c) 1992, 1993, 1994, 1995, 1996
 * The Regents of the University of California.  All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that: (1) source code distributions
 * retain the above copyright notice and this paragraph in its entirety, (2)
 * distributions including binary code include the above copyright notice and
 * this paragraph in its entirety in the documentation or other materials
 * provided with the distribution, and (3) all advertising materials mentioning
 * features or use of this software display the following acknowledgement:
 * ``This product includes software developed by the University of California,
 * Lawrence Berkeley Laboratory and its contributors.'' Neither the name of
 * the University 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 ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
 * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
 */

#if 0
static const char rcsid[] =
  "@(#) $Header: /ng/src/proto-analyser/tcpdump/RCS/print-oncrpc.c,v 1.1 1998/06/25 06:32:39 janssen Exp $ (LBL)";
#endif

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <memory.h>
#include <ctype.h>

#include <sys/param.h>
#include <sys/time.h>
#include <sys/socket.h>
#include <net/if.h>
#include <netdb.h>
#include <netinet/in.h>
#include <netinet/if_ether.h>
#include <netinet/in_systm.h>
#include <netinet/ip.h>
#include <netinet/ip_var.h>
#include <netinet/tcp.h>
#include <netinet/tcpip.h>

#include "interfac.h"
#include "a2name.h"


#define ONCRPC_MSGTYPE_REQUEST			0
#define ONCRPC_MSGTYPE_REPLY			1

#define ONCRPC_REPLYSTATUS_ACCEPTED		0
#define ONCRPC_REPLYSTATUS_REJECTED		1

#define ONCRPC_ACCEPTSTATUS_SUCCESS		0
#define ONCRPC_ACCEPTSTATUS_PROG_UNAVAILABLE	1
#define ONCRPC_ACCEPTSTATUS_PROG_MISMATCH	2
#define ONCRPC_ACCEPTSTATUS_PROC_UNAVAILABLE	3
#define ONCRPC_ACCEPTSTATUS_GARBAGE_ARGS	4
#define ONCRPC_ACCEPTSTATUS_SYSTEM_ERROR	5

#define ONCRPC_REJECTSTATUS_RPC_MISMATCH	0
#define ONCRPC_REJECTSTATUS_AUTH_ERROR		1

#define ONCRPC_AUTHTYPE_NONE			0
#define ONCRPC_AUTHTYPE_SYS			1
#define ONCRPC_AUTHTYPE_SHORT			2
#define ONCRPC_AUTHTYPE_DES			3
#define ONCRPC_AUTHTYPE_KERB			4

#define ONCRPC_AUTHSTAT_OK			0
#define ONCRPC_AUTHSTAT_BADCRED			1
#define ONCRPC_AUTHSTAT_REJECTEDCRED		2
#define ONCRPC_AUTHSTAT_BADVERF			3
#define ONCRPC_AUTHSTAT_REJECTEDVERF		4
#define ONCRPC_AUTHSTAT_TOOWEAK			5
#define ONCRPC_AUTHSTAT_INVALIDRESP		6
#define ONCRPC_AUTHSTAT_FAILED			7
#define ONCRPC_AUTHSTAT_KERBGENERIC		8
#define ONCRPC_AUTHSTAT_TIMEEXPIRE		9
#define ONCRPC_AUTHSTAT_TKT_FILE		10
#define ONCRPC_AUTHSTAT_DECODE			11
#define ONCRPC_AUTHSTAT_NET_ADDR		12

struct oncrpc_state {
       u_int id;        /* connection id */
     };

struct state_list {
       struct state_list   *next;
       struct oncrpc_state  state;
     };

static struct state_list *connections = NULL;

static __inline struct oncrpc_state *add_state (u_int id)
{
  struct state_list *newstate = malloc (sizeof(*newstate));

  newstate->state.id = id;
  newstate->next = connections;
  connections    = newstate;
  return (&newstate->state);
}

static __inline struct oncrpc_state *find_state (u_int id)
{
  struct state_list *p;

  for (p = connections; p; p = p->next)
      if (p->state.id == id)
         return (&p->state);
  return (NULL);
}

void oncrpc_print (u_int connection, const u_char *msg, u_int msglen)
{
  struct oncrpc_state *s = find_state (connection);
  u_int32_t            sn, msgtype;

  if (!s)
     s = add_state (connection);

  PRINTF ("%s <oncrpc", Pflag ? "\n " : "");

  sn  = ntohl (*(u_int32_t*)msg);
  msg += 4;
  msgtype = ntohl (*(u_int32_t*)msg);
  msg += 4;

  switch (msgtype)
  {
    case ONCRPC_MSGTYPE_REQUEST:
         {
           u_int32_t version, programnumber, programversion, methodid;
           u_int32_t authtype, authlen;

           version = ntohl (*(u_int32_t*)msg);
           msg += 4;
           programnumber = ntohl (*(u_int32_t*)msg);
           msg += 4;
           programversion = ntohl (*(u_int32_t*)msg);
           msg += 4;
           methodid = ntohl (*(u_int32_t*)msg);
           msg += 4;

           PRINTF (" i(%lu,rpcvers=%lu,prognum=%lu,progvers=%lu,proc=%lu",
                   sn, version, programnumber, programversion, methodid);

           authtype = ntohl (*(u_int32_t*)msg);
           msg += 4;
           authlen = ntohl (*(u_int32_t*)msg);
           msg += 4;
           msg += (((authlen + 3) / 4) * 4);

           switch (authtype)
           {
             case ONCRPC_AUTHTYPE_NONE:
                  break;

             case ONCRPC_AUTHTYPE_SYS:
                  PRINTF (",auth=System(%lu)", authlen);
                  break;

             case ONCRPC_AUTHTYPE_SHORT:
                  PRINTF (",auth=Short(%lu)", authlen);
                  break;

             case ONCRPC_AUTHTYPE_DES:
                  PRINTF (",auth=DES(%lu)", authlen);
                  break;

             case ONCRPC_AUTHTYPE_KERB:
                  PRINTF (",auth=Kerberos(%lu)", authlen);
                  break;

             default:
                  PRINTF (",auth=%lu(%lu)", authlen);
                  break;
           }

           /* now do the verifier
            */
           authtype = ntohl (*(u_int32_t*)msg);
           msg += 4;
           authlen = ntohl (*(u_int32_t*)msg);
           msg += 4;
           msg += (((authlen + 3) / 4) * 4);

           switch (authtype)
           {
             case ONCRPC_AUTHTYPE_NONE:
                  break;

             case ONCRPC_AUTHTYPE_SYS:
                  PRINTF (",verf=System(%lu)", authlen);
                  break;

             case ONCRPC_AUTHTYPE_SHORT:
                  PRINTF (",verf=Short(%lu)", authlen);
                  break;

             case ONCRPC_AUTHTYPE_DES:
                  PRINTF (",verf=DES(%lu)", authlen);
                  break;

             case ONCRPC_AUTHTYPE_KERB:
                  PRINTF (",verf=Kerberos(%lu)", authlen);
                  break;

             default:
                  PRINTF (",verf=%lu(%lu)", authlen);
                  break;
           } 
         }
         break;

    case ONCRPC_MSGTYPE_REPLY:
         {
           u_int32_t status = ntohl (*(u_int32_t*)msg);

           msg += 4;
           PRINTF (" r(%lu", sn);

           if (status == ONCRPC_REPLYSTATUS_ACCEPTED)
           {
             u_int32_t authtype, authlen, actualstatus;

             PUTS (",accepted");

             authtype = ntohl (*(u_int32_t*)msg);
             msg += 4;
             authlen = ntohl (*(u_int32_t*)msg);
             msg += 4;
             msg += (((authlen + 3) / 4) * 4);
             if (authtype)
                PRINTF ("authtype=%lu,verifierlen=%lu", authtype, authlen);

             actualstatus = ntohl (*(u_int32_t*)msg);
             msg += 4;

             switch (actualstatus)
             {
               case ONCRPC_ACCEPTSTATUS_SUCCESS:
                    PUTS (",status=Success");
                    break;

               case ONCRPC_ACCEPTSTATUS_PROG_MISMATCH:
                    {
                      unsigned long number, version;

                      number = ntohl (*(u_int32_t*)msg);
                      msg += 4;
                      version = ntohl (*(u_int32_t*)msg);
                      msg += 4;
                      PRINTF (",status=ProgramMismatch(low=%lu,high=%lu)\n",
                              number, version);
                    }
                    break;

               case ONCRPC_ACCEPTSTATUS_PROG_UNAVAILABLE:
                    PUTS (",status=ProgramUnavailable");
                    break;

               case ONCRPC_ACCEPTSTATUS_PROC_UNAVAILABLE:
                    PUTS (",status=ProcedureUnavailable");
                    break;

               case ONCRPC_ACCEPTSTATUS_GARBAGE_ARGS:
                    PUTS (",status=GarbageArgs");
                    break;

               case ONCRPC_ACCEPTSTATUS_SYSTEM_ERROR:
                    PUTS (",status=SystemError");
                    break;

               default:
                    PRINTF (",status=Error(%lu)", actualstatus);
                    break;
             }
           }
           else if (status == ONCRPC_REPLYSTATUS_REJECTED)
           {
             u_int32_t rejstatus;

             PUTS (",rejected");
             rejstatus = ntohl (*(u_int32_t*)msg);
             msg += 4;

             switch (rejstatus)
             {
               case ONCRPC_REJECTSTATUS_RPC_MISMATCH:
                    {
                      unsigned long low, high;

                      low = ntohl (*(u_int32_t*)msg);
                      msg += 4;
                      high = ntohl (*(u_int32_t*)msg);
                      msg += 4;
                      PRINTF (",status=ProgramMismatch(low=%lu,high=%lu)\n",
                              low, high);
                    }
                    break;

               case ONCRPC_REJECTSTATUS_AUTH_ERROR:
                    {
                      unsigned long authstat;

                      authstat = ntohl (*(u_int32_t*)msg);
                      msg += 4;

                      switch (authstat)
                      {
                        case ONCRPC_AUTHSTAT_OK:
                             PUTS (",status=AuthError(OK?)");
                             break;

                        case ONCRPC_AUTHSTAT_BADCRED:
                             PUTS (",status=AuthError(BadCredentials)");
                             break;

                        case ONCRPC_AUTHSTAT_REJECTEDCRED:
                             PUTS (",status=AuthError(RejectedCredentials)");
                             break;

                        case ONCRPC_AUTHSTAT_BADVERF:
                             PUTS (",status=AuthError(BadVerifier)");
                             break;

                        case ONCRPC_AUTHSTAT_REJECTEDVERF:
                             PUTS (",status=AuthError(RejectedVerifier)");
                             break;

                        case ONCRPC_AUTHSTAT_TOOWEAK:
                             PUTS (",status=AuthError(TooWeak)");
                             break;

                        case ONCRPC_AUTHSTAT_INVALIDRESP:
                             PUTS (",status=AuthError(InvalidResponse)");
                             break;

                        case ONCRPC_AUTHSTAT_FAILED:
                             PUTS (",status=AuthError(Unknown)");
                             break;

                        case ONCRPC_AUTHSTAT_KERBGENERIC:
                             PUTS (",status=AuthError(KerberosGeneric)");
                             break;

                        case ONCRPC_AUTHSTAT_TIMEEXPIRE:
                             PUTS (",status=AuthError(KerberosCredentialExpired)");
                             break;

                        case ONCRPC_AUTHSTAT_TKT_FILE:
                             PUTS (",status=AuthError(KerberosBadTicketFile)");
                             break;

                        case ONCRPC_AUTHSTAT_DECODE:
                             PUTS (",status=AuthError(KerberosDecode)");
                             break;

                        case ONCRPC_AUTHSTAT_NET_ADDR:
                             PUTS (",status=AuthError(KerberosNetAddress)");
                             break;

                        default:
                             PRINTF (",status=AuthError(%lu)\n", authstat);
                             break;
                      }
                    }

               default:
                    PRINTF (",status=%lu\n", rejstatus);
                    break;
             }
           }
           else
           {
             PRINTF ("[unknown reply status %lu!]\n", status);
             return;
           }
         }
         break;

    default:
         PRINTF ("[unknown msg type %lu!]\n", msgtype);
         return;
  }
  PUTCHAR ('>');
}

⌨️ 快捷键说明

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