Print this page
1575 untangle libmlrpc ... pre2:
 Get rid of ndr_rpc_server_{info,os}
1575 untangle libmlrpc ... pre1:
 Move srvsvc_timecheck where it belongs

Split Close
Expand all
Collapse all
          --- old/usr/src/lib/smbsrv/libmlsvc/common/srvsvc_clnt.c
          +++ new/usr/src/lib/smbsrv/libmlsvc/common/srvsvc_clnt.c
↓ open down ↓ 26 lines elided ↑ open up ↑
  27   27  /*
  28   28   * Server Service (srvsvc) client side RPC library interface. The
  29   29   * srvsvc interface allows a client to query a server for information
  30   30   * on shares, sessions, connections and files on the server. Some
  31   31   * functions are available via anonymous IPC while others require
  32   32   * administrator privilege. Also, some functions return NT status
  33   33   * values while others return Win32 errors codes.
  34   34   */
  35   35  
  36   36  #include <sys/errno.h>
       37 +#include <sys/tzfile.h>
  37   38  #include <stdio.h>
  38   39  #include <time.h>
  39   40  #include <strings.h>
       41 +#include <unistd.h>
  40   42  
  41   43  #include <smbsrv/libsmb.h>
  42   44  #include <smbsrv/libmlsvc.h>
  43   45  #include <smbsrv/smbinfo.h>
  44   46  #include <smbsrv/ndl/srvsvc.ndl>
  45   47  
  46   48  /*
  47   49   * Information level for NetShareGetInfo.
  48   50   */
  49   51  DWORD srvsvc_info_level = 1;
↓ open down ↓ 291 lines elided ↑ open up ↑
 341  343          default:
 342  344                  smb_tracef("srvsvc: unknown level");
 343  345                  break;
 344  346          }
 345  347  
 346  348          srvsvc_close(&handle);
 347  349          return (0);
 348  350  }
 349  351  
 350  352  /*
 351      - * Windows 95+ and Windows NT4.0 both report the version as 4.0.
 352      - * Windows 2000+ reports the version as 5.x.
      353 + * Compare the time here with the remote time on the server
      354 + * and report clock skew.
 353  355   */
 354      -int
 355      -srvsvc_net_server_getinfo(char *server, char *domain,
 356      -    srvsvc_server_info_t *svinfo)
      356 +void
      357 +srvsvc_timecheck(char *server, char *domain)
 357  358  {
 358      -        mlsvc_handle_t handle;
 359      -        struct mslm_NetServerGetInfo arg;
 360      -        struct mslm_SERVER_INFO_101 *sv101;
 361      -        int len, opnum, rc;
 362      -        char user[SMB_USERNAME_MAXLEN];
      359 +        char                    hostname[MAXHOSTNAMELEN];
      360 +        struct timeval          dc_tv;
      361 +        struct tm               dc_tm;
      362 +        struct tm               *tm;
      363 +        time_t                  tnow;
      364 +        time_t                  tdiff;
      365 +        int                     priority;
 363  366  
 364      -        smb_ipc_get_user(user, SMB_USERNAME_MAXLEN);
      367 +        if (srvsvc_net_remote_tod(server, domain, &dc_tv, &dc_tm) < 0) {
      368 +                syslog(LOG_DEBUG, "srvsvc_net_remote_tod failed");
      369 +                return;
      370 +        }
 365  371  
 366      -        if (srvsvc_open(server, domain, user, &handle) != 0)
 367      -                return (-1);
      372 +        tnow = time(NULL);
 368  373  
 369      -        opnum = SRVSVC_OPNUM_NetServerGetInfo;
 370      -        bzero(&arg, sizeof (arg));
      374 +        if (tnow > dc_tv.tv_sec)
      375 +                tdiff = (tnow - dc_tv.tv_sec) / SECSPERMIN;
      376 +        else
      377 +                tdiff = (dc_tv.tv_sec - tnow) / SECSPERMIN;
 371  378  
 372      -        len = strlen(server) + 4;
 373      -        arg.servername = ndr_rpc_malloc(&handle, len);
 374      -        if (arg.servername == NULL)
 375      -                return (-1);
      379 +        if (tdiff != 0) {
      380 +                (void) strlcpy(hostname, "localhost", MAXHOSTNAMELEN);
      381 +                (void) gethostname(hostname, MAXHOSTNAMELEN);
 376  382  
 377      -        (void) snprintf((char *)arg.servername, len, "\\\\%s", server);
 378      -        arg.level = 101;
      383 +                priority = (tdiff > 2) ? LOG_NOTICE : LOG_DEBUG;
      384 +                syslog(priority, "DC [%s] clock skew detected: %u minutes",
      385 +                    server, tdiff);
 379  386  
 380      -        rc = ndr_rpc_call(&handle, opnum, &arg);
 381      -        if ((rc != 0) || (arg.status != 0)) {
 382      -                srvsvc_close(&handle);
 383      -                return (-1);
      387 +                tm = gmtime(&dc_tv.tv_sec);
      388 +                syslog(priority, "%-8s  UTC: %s", server, asctime(tm));
      389 +                tm = gmtime(&tnow);
      390 +                syslog(priority, "%-8s  UTC: %s", hostname, asctime(tm));
 384  391          }
 385      -
 386      -        sv101 = arg.result.bufptr.bufptr101;
 387      -
 388      -        bzero(svinfo, sizeof (srvsvc_server_info_t));
 389      -        svinfo->sv_platform_id = sv101->sv101_platform_id;
 390      -        svinfo->sv_version_major = sv101->sv101_version_major;
 391      -        svinfo->sv_version_minor = sv101->sv101_version_minor;
 392      -        svinfo->sv_type = sv101->sv101_type;
 393      -        if (sv101->sv101_name)
 394      -                svinfo->sv_name = strdup((char *)sv101->sv101_name);
 395      -        if (sv101->sv101_comment)
 396      -                svinfo->sv_comment = strdup((char *)sv101->sv101_comment);
 397      -
 398      -        if (svinfo->sv_type & SV_TYPE_WFW)
 399      -                svinfo->sv_os = NATIVE_OS_WIN95;
 400      -        if (svinfo->sv_type & SV_TYPE_WINDOWS)
 401      -                svinfo->sv_os = NATIVE_OS_WIN95;
 402      -        if ((svinfo->sv_type & SV_TYPE_NT) ||
 403      -            (svinfo->sv_type & SV_TYPE_SERVER_NT))
 404      -                svinfo->sv_os = NATIVE_OS_WINNT;
 405      -        if (svinfo->sv_version_major > 4)
 406      -                svinfo->sv_os = NATIVE_OS_WIN2000;
 407      -
 408      -        srvsvc_close(&handle);
 409      -        return (0);
 410  392  }
 411  393  
 412  394  /*
 413  395   * Synchronize the local system clock with the domain controller.
 414  396   */
 415  397  void
 416  398  srvsvc_timesync(void)
 417  399  {
 418  400          smb_domainex_t di;
 419  401          struct timeval tv;
↓ open down ↓ 116 lines elided ↑ open up ↑
 536  518                  tm->tm_min = tod->tod_mins;
 537  519                  tm->tm_hour = tod->tod_hours;
 538  520                  tm->tm_mday = tod->tod_day;
 539  521                  tm->tm_mon = tod->tod_month - 1;
 540  522                  tm->tm_year = tod->tod_year - 1900;
 541  523                  tm->tm_wday = tod->tod_weekday;
 542  524          }
 543  525  
 544  526          srvsvc_close(&handle);
 545  527          return (0);
 546      -}
 547      -
 548      -void
 549      -srvsvc_net_test(char *server, char *domain, char *netname)
 550      -{
 551      -        smb_domainex_t di;
 552      -        srvsvc_server_info_t svinfo;
 553      -
 554      -        (void) smb_tracef("%s %s %s", server, domain, netname);
 555      -
 556      -        if (smb_domain_getinfo(&di)) {
 557      -                server = di.d_dci.dc_name;
 558      -                domain = di.d_primary.di_nbname;
 559      -        }
 560      -
 561      -        if (srvsvc_net_server_getinfo(server, domain, &svinfo) == 0) {
 562      -                smb_tracef("NetServerGetInfo: %s %s (%d.%d) id=%d type=0x%08x",
 563      -                    svinfo.sv_name ? svinfo.sv_name : "NULL",
 564      -                    svinfo.sv_comment ? svinfo.sv_comment : "NULL",
 565      -                    svinfo.sv_version_major, svinfo.sv_version_minor,
 566      -                    svinfo.sv_platform_id, svinfo.sv_type);
 567      -
 568      -                free(svinfo.sv_name);
 569      -                free(svinfo.sv_comment);
 570      -        }
 571      -
 572      -        (void) srvsvc_net_share_get_info(server, domain, netname);
 573      -#if 0
 574      -        /*
 575      -         * The NetSessionEnum server-side definition was updated.
 576      -         * Disabled until the client-side has been updated.
 577      -         */
 578      -        (void) srvsvc_net_session_enum(server, domain, netname);
 579      -#endif
 580      -        (void) srvsvc_net_connect_enum(server, domain, netname, 0);
 581      -        (void) srvsvc_net_connect_enum(server, domain, netname, 1);
 582  528  }
    
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX