~ubuntu-branches/ubuntu/oneiric/likewise-open/oneiric

« back to all changes in this revision

Viewing changes to samba/source/utils/net_ads.c

  • Committer: Bazaar Package Importer
  • Author(s): Rick Clark
  • Date: 2008-08-27 08:56:20 UTC
  • mfrom: (1.1.2 upstream)
  • Revision ID: james.westby@ubuntu.com-20080827085620-5q0f58b9qtog9myq
Tags: 4.1.0.2956-0ubuntu1
* missing-likewise-logo.diff: removed
* fixed copyright notice
* updated Standards-Version to 3.8.0
* removed path from command in prerm
* removed stop in S runlevel

Show diffs side-by-side

added added

removed removed

Lines of Context:
1639
1639
        d_printf("                      NB: osName and osVer must be specified together for either to take effect.\n");
1640
1640
        d_printf("                          Also, the operatingSystemService attribute is also set when along with\n");
1641
1641
        d_printf("                          the two other attributes.\n");
 
1642
        d_printf("   notimesync         Do not sync the time on join.\n");
1642
1643
 
1643
1644
        return -1;
1644
1645
}
1692
1693
        struct sockaddr_storage dcss;
1693
1694
        const char *os_name = NULL;
1694
1695
        const char *os_version = NULL;
1695
 
 
1696
 
        nt_status = check_ads_config();
1697
 
        if (!NT_STATUS_IS_OK(nt_status)) {
1698
 
                d_fprintf(stderr, "Invalid configuration.  Exiting....\n");
1699
 
                goto fail;
1700
 
        }
1701
 
 
1702
 
        /* setup the server affinity cache */
1703
 
 
1704
 
        get_dc_name( lp_workgroup(), lp_realm(), dc_name, &dcss );
1705
 
 
1706
 
        /* set the time before attempting authentication */
1707
 
 
1708
 
        status = ads_startup_nobind( True, &ads );
1709
 
        if ( !ADS_ERR_OK(status) ) {            
1710
 
                d_fprintf( stderr, "Failed to contact DC when trying to synchronize local system clock!\n");
1711
 
                if ((status.error_type == ENUM_ADS_ERROR_NT) &&
1712
 
                        NT_STATUS_EQUAL(status.err.nt_status,
1713
 
                        NT_STATUS_NO_LOGON_SERVERS))
1714
 
                {
1715
 
                        d_fprintf( stderr, "None of the domain controllers listed in DNS could be contacted, or there are no DCs listed in DNS.\n");
1716
 
                }
1717
 
                ads_destroy( &ads );
1718
 
                goto fail;
1719
 
        }
1720
 
 
1721
 
        server_time = cli_servertime( dc_name, &dcss, NULL );
1722
 
        if ( server_time != 0 ) {
1723
 
                char *cmd = NULL;
1724
 
                int sys_result;
1725
 
                
1726
 
#if defined(HPUX)
1727
 
                sys_result = stime((const)&server_time);
1728
 
#else
1729
 
                asprintf(&cmd, "/bin/date %s", systime(server_time));
1730
 
                if ( cmd ) {
1731
 
                        sys_result = system (cmd);
1732
 
                        SAFE_FREE( cmd );
1733
 
                }
1734
 
#endif
1735
 
                if (sys_result != 0 ) {
1736
 
                        d_fprintf( stderr, "Failed to synchronize local machine clock to "
1737
 
                                   "domain controller (%s)\n", \
1738
 
                                   ads->config.ldap_server_name );
1739
 
                        /* try to go ahead and join anyways */
1740
 
                }
1741
 
        }
1742
 
        ads_destroy( &ads );
1743
 
        ads = NULL;     
1744
 
        
1745
 
        /* now begin the real join process */
1746
 
 
1747
 
        status = ads_startup(True, &ads);
1748
 
        if (!ADS_ERR_OK(status)) {
1749
 
                DEBUG(1, ("error on ads_startup: %s\n", ads_errstr(status)));
1750
 
                nt_status = ads_ntstatus(status);
1751
 
                goto fail;
1752
 
        }
1753
 
 
1754
 
        if (strcmp(ads->config.realm, lp_realm()) != 0) {
1755
 
                d_fprintf(stderr, "realm of remote server (%s) and realm in %s "
1756
 
                        "(%s) DO NOT match.  Aborting join\n",
1757
 
                        ads->config.realm, get_dyn_CONFIGFILE(), lp_realm());
1758
 
                nt_status = NT_STATUS_INVALID_PARAMETER;
1759
 
                goto fail;
1760
 
        }
1761
 
 
1762
 
        if (!(ctx = talloc_init("net_ads_join"))) {
1763
 
                d_fprintf(stderr, "Could not initialise talloc context.\n");
1764
 
                nt_status = NT_STATUS_NO_MEMORY;
1765
 
                goto fail;
1766
 
        }
 
1696
        bool notimesync = False;
1767
1697
 
1768
1698
        /* process additional command line args */
1769
1699
 
1793
1723
                                goto fail;
1794
1724
                        }
1795
1725
                }
 
1726
                else if ( !StrCaseCmp(argv[i], "notimesync") ) {
 
1727
                        notimesync = True;
 
1728
                }
1796
1729
                else {
1797
1730
                        d_fprintf(stderr, "Bad option: %s\n", argv[i]);
1798
1731
                        nt_status = NT_STATUS_INVALID_PARAMETER;
1800
1733
                }
1801
1734
        }
1802
1735
 
 
1736
        nt_status = check_ads_config();
 
1737
        if (!NT_STATUS_IS_OK(nt_status)) {
 
1738
                d_fprintf(stderr, "Invalid configuration.  Exiting....\n");
 
1739
                goto fail;
 
1740
        }
 
1741
 
 
1742
        /* setup the server affinity cache */
 
1743
 
 
1744
        get_dc_name( lp_workgroup(), lp_realm(), dc_name, &dcss );
 
1745
 
 
1746
        /* set the time before attempting authentication */
 
1747
 
 
1748
        if (!notimesync) {
 
1749
                status = ads_startup_nobind( True, &ads );
 
1750
                if ( !ADS_ERR_OK(status) ) {
 
1751
                        d_fprintf( stderr, "Failed to contact DC when trying to synchronize local system clock!\n");
 
1752
                        if ((status.error_type == ENUM_ADS_ERROR_NT) &&
 
1753
                            NT_STATUS_EQUAL(status.err.nt_status,
 
1754
                                            NT_STATUS_NO_LOGON_SERVERS))
 
1755
                        {
 
1756
                                d_fprintf( stderr, "None of the domain controllers listed in DNS could be contacted, or there are no DCs listed in DNS.\n");
 
1757
                        }
 
1758
                        ads_destroy( &ads );
 
1759
                        goto fail;
 
1760
                }
 
1761
 
 
1762
                server_time = cli_servertime( dc_name, &dcss, NULL );
 
1763
                if ( server_time != 0 ) {
 
1764
                        char *cmd = NULL;
 
1765
                        int sys_result;
 
1766
                
 
1767
#if defined(HPUX)
 
1768
                        sys_result = stime((const)&server_time);
 
1769
#else
 
1770
                        asprintf(&cmd, "/bin/date %s", systime(server_time));
 
1771
                        if ( cmd ) {
 
1772
                                sys_result = system (cmd);
 
1773
                                SAFE_FREE( cmd );
 
1774
                        }
 
1775
#endif
 
1776
                        if (sys_result != 0 ) {
 
1777
                                d_fprintf( stderr, "Failed to synchronize local machine clock to "
 
1778
                                           "domain controller (%s)\n", \
 
1779
                                           ads->config.ldap_server_name );
 
1780
                                /* try to go ahead and join anyways */
 
1781
                        }
 
1782
                }
 
1783
                ads_destroy( &ads );
 
1784
                ads = NULL;
 
1785
        }
 
1786
 
 
1787
        /* now begin the real join process */
 
1788
 
 
1789
        status = ads_startup(True, &ads);
 
1790
        if (!ADS_ERR_OK(status)) {
 
1791
                DEBUG(1, ("error on ads_startup: %s\n", ads_errstr(status)));
 
1792
                nt_status = ads_ntstatus(status);
 
1793
                goto fail;
 
1794
        }
 
1795
 
 
1796
        if (strcmp(ads->config.realm, lp_realm()) != 0) {
 
1797
                d_fprintf(stderr, "realm of remote server (%s) and realm in %s "
 
1798
                        "(%s) DO NOT match.  Aborting join\n",
 
1799
                        ads->config.realm, get_dyn_CONFIGFILE(), lp_realm());
 
1800
                nt_status = NT_STATUS_INVALID_PARAMETER;
 
1801
                goto fail;
 
1802
        }
 
1803
 
 
1804
        if (!(ctx = talloc_init("net_ads_join"))) {
 
1805
                d_fprintf(stderr, "Could not initialise talloc context.\n");
 
1806
                nt_status = NT_STATUS_NO_MEMORY;
 
1807
                goto fail;
 
1808
        }
 
1809
 
1803
1810
        /* If we were given an OU, try to create the machine in
1804
1811
           the OU account first and then do the normal RPC join */
1805
1812