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


  17  * information: Portions Copyright [yyyy] [name of copyright owner]
  18  *
  19  * CDDL HEADER END
  20  */
  21 
  22 /*
  23  * Copyright (c) 2009, 2010, Oracle and/or its affiliates. All rights reserved.
  24  * Copyright 2015 Nexenta Systems, Inc.  All rights reserved.
  25  */
  26 
  27 /*
  28  * Server Service (srvsvc) client side RPC library interface. The
  29  * srvsvc interface allows a client to query a server for information
  30  * on shares, sessions, connections and files on the server. Some
  31  * functions are available via anonymous IPC while others require
  32  * administrator privilege. Also, some functions return NT status
  33  * values while others return Win32 errors codes.
  34  */
  35 
  36 #include <sys/errno.h>

  37 #include <stdio.h>
  38 #include <time.h>
  39 #include <strings.h>

  40 
  41 #include <smbsrv/libsmb.h>
  42 #include <smbsrv/libmlsvc.h>
  43 #include <smbsrv/smbinfo.h>
  44 #include <smbsrv/ndl/srvsvc.ndl>
  45 
  46 /*
  47  * Information level for NetShareGetInfo.
  48  */
  49 DWORD srvsvc_info_level = 1;
  50 
  51 /*
  52  * Bind to the the SRVSVC.
  53  *
  54  * If username argument is NULL, an anonymous connection will be established.
  55  * Otherwise, an authenticated connection will be established.
  56  */
  57 static int
  58 srvsvc_open(char *server, char *domain, char *username, mlsvc_handle_t *handle)
  59 {


 331                             cib1->coni1_netname ?
 332                             (char *)cib1->coni1_netname : "(null)");
 333                         smb_tracef("srvsvc coni1_nopens=%u",
 334                             cib1->coni1_num_opens);
 335                         smb_tracef("srvsvc coni1_time=%u", cib1->coni1_time);
 336                         smb_tracef("srvsvc coni1_num_users=%u",
 337                             cib1->coni1_num_users);
 338                 }
 339                 break;
 340 
 341         default:
 342                 smb_tracef("srvsvc: unknown level");
 343                 break;
 344         }
 345 
 346         srvsvc_close(&handle);
 347         return (0);
 348 }
 349 
 350 /*
 351  * Windows 95+ and Windows NT4.0 both report the version as 4.0.
 352  * Windows 2000+ reports the version as 5.x.
 353  */
 354 int
 355 srvsvc_net_server_getinfo(char *server, char *domain,
 356     srvsvc_server_info_t *svinfo)
 357 {
 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];


 363 
 364         smb_ipc_get_user(user, SMB_USERNAME_MAXLEN);



 365 
 366         if (srvsvc_open(server, domain, user, &handle) != 0)
 367                 return (-1);
 368 
 369         opnum = SRVSVC_OPNUM_NetServerGetInfo;
 370         bzero(&arg, sizeof (arg));


 371 
 372         len = strlen(server) + 4;
 373         arg.servername = ndr_rpc_malloc(&handle, len);
 374         if (arg.servername == NULL)
 375                 return (-1);
 376 
 377         (void) snprintf((char *)arg.servername, len, "\\\\%s", server);
 378         arg.level = 101;

 379 
 380         rc = ndr_rpc_call(&handle, opnum, &arg);
 381         if ((rc != 0) || (arg.status != 0)) {
 382                 srvsvc_close(&handle);
 383                 return (-1);
 384         }
 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 }
 411 
 412 /*
 413  * Synchronize the local system clock with the domain controller.
 414  */
 415 void
 416 srvsvc_timesync(void)
 417 {
 418         smb_domainex_t di;
 419         struct timeval tv;
 420         struct tm tm;
 421         time_t tsecs;
 422 
 423         if (!smb_domain_getinfo(&di))
 424                 return;
 425 
 426         if (srvsvc_net_remote_tod(di.d_dci.dc_name, di.d_primary.di_nbname,
 427             &tv, &tm) != 0)
 428                 return;
 429 


 526          */
 527         tod = arg.bufptr;
 528 
 529         if (tv) {
 530                 tv->tv_sec = tod->tod_elapsedt;
 531                 tv->tv_usec = tod->tod_msecs;
 532         }
 533 
 534         if (tm) {
 535                 tm->tm_sec = tod->tod_secs;
 536                 tm->tm_min = tod->tod_mins;
 537                 tm->tm_hour = tod->tod_hours;
 538                 tm->tm_mday = tod->tod_day;
 539                 tm->tm_mon = tod->tod_month - 1;
 540                 tm->tm_year = tod->tod_year - 1900;
 541                 tm->tm_wday = tod->tod_weekday;
 542         }
 543 
 544         srvsvc_close(&handle);
 545         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 }


  17  * information: Portions Copyright [yyyy] [name of copyright owner]
  18  *
  19  * CDDL HEADER END
  20  */
  21 
  22 /*
  23  * Copyright (c) 2009, 2010, Oracle and/or its affiliates. All rights reserved.
  24  * Copyright 2015 Nexenta Systems, Inc.  All rights reserved.
  25  */
  26 
  27 /*
  28  * Server Service (srvsvc) client side RPC library interface. The
  29  * srvsvc interface allows a client to query a server for information
  30  * on shares, sessions, connections and files on the server. Some
  31  * functions are available via anonymous IPC while others require
  32  * administrator privilege. Also, some functions return NT status
  33  * values while others return Win32 errors codes.
  34  */
  35 
  36 #include <sys/errno.h>
  37 #include <sys/tzfile.h>
  38 #include <stdio.h>
  39 #include <time.h>
  40 #include <strings.h>
  41 #include <unistd.h>
  42 
  43 #include <smbsrv/libsmb.h>
  44 #include <smbsrv/libmlsvc.h>
  45 #include <smbsrv/smbinfo.h>
  46 #include <smbsrv/ndl/srvsvc.ndl>
  47 
  48 /*
  49  * Information level for NetShareGetInfo.
  50  */
  51 DWORD srvsvc_info_level = 1;
  52 
  53 /*
  54  * Bind to the the SRVSVC.
  55  *
  56  * If username argument is NULL, an anonymous connection will be established.
  57  * Otherwise, an authenticated connection will be established.
  58  */
  59 static int
  60 srvsvc_open(char *server, char *domain, char *username, mlsvc_handle_t *handle)
  61 {


 333                             cib1->coni1_netname ?
 334                             (char *)cib1->coni1_netname : "(null)");
 335                         smb_tracef("srvsvc coni1_nopens=%u",
 336                             cib1->coni1_num_opens);
 337                         smb_tracef("srvsvc coni1_time=%u", cib1->coni1_time);
 338                         smb_tracef("srvsvc coni1_num_users=%u",
 339                             cib1->coni1_num_users);
 340                 }
 341                 break;
 342 
 343         default:
 344                 smb_tracef("srvsvc: unknown level");
 345                 break;
 346         }
 347 
 348         srvsvc_close(&handle);
 349         return (0);
 350 }
 351 
 352 /*
 353  * Compare the time here with the remote time on the server
 354  * and report clock skew.
 355  */
 356 void
 357 srvsvc_timecheck(char *server, char *domain)

 358 {
 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;
 366 
 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         }
 371 
 372         tnow = time(NULL);

 373 
 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;
 378 
 379         if (tdiff != 0) {
 380                 (void) strlcpy(hostname, "localhost", MAXHOSTNAMELEN);
 381                 (void) gethostname(hostname, MAXHOSTNAMELEN);

 382 
 383                 priority = (tdiff > 2) ? LOG_NOTICE : LOG_DEBUG;
 384                 syslog(priority, "DC [%s] clock skew detected: %u minutes",
 385                     server, tdiff);
 386 
 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));
 391         }

























 392 }
 393 
 394 /*
 395  * Synchronize the local system clock with the domain controller.
 396  */
 397 void
 398 srvsvc_timesync(void)
 399 {
 400         smb_domainex_t di;
 401         struct timeval tv;
 402         struct tm tm;
 403         time_t tsecs;
 404 
 405         if (!smb_domain_getinfo(&di))
 406                 return;
 407 
 408         if (srvsvc_net_remote_tod(di.d_dci.dc_name, di.d_primary.di_nbname,
 409             &tv, &tm) != 0)
 410                 return;
 411 


 508          */
 509         tod = arg.bufptr;
 510 
 511         if (tv) {
 512                 tv->tv_sec = tod->tod_elapsedt;
 513                 tv->tv_usec = tod->tod_msecs;
 514         }
 515 
 516         if (tm) {
 517                 tm->tm_sec = tod->tod_secs;
 518                 tm->tm_min = tod->tod_mins;
 519                 tm->tm_hour = tod->tod_hours;
 520                 tm->tm_mday = tod->tod_day;
 521                 tm->tm_mon = tod->tod_month - 1;
 522                 tm->tm_year = tod->tod_year - 1900;
 523                 tm->tm_wday = tod->tod_weekday;
 524         }
 525 
 526         srvsvc_close(&handle);
 527         return (0);




































 528 }