LCOV - code coverage report
Current view: top level - libreoffice/framework/source/fwi/helper - networkdomain.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 0 20 0.0 %
Date: 2012-12-27 Functions: 0 3 0.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2             : /*
       3             :  * This file is part of the LibreOffice project.
       4             :  *
       5             :  * This Source Code Form is subject to the terms of the Mozilla Public
       6             :  * License, v. 2.0. If a copy of the MPL was not distributed with this
       7             :  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
       8             :  *
       9             :  * This file incorporates work covered by the following license notice:
      10             :  *
      11             :  *   Licensed to the Apache Software Foundation (ASF) under one or more
      12             :  *   contributor license agreements. See the NOTICE file distributed
      13             :  *   with this work for additional information regarding copyright
      14             :  *   ownership. The ASF licenses this file to you under the Apache
      15             :  *   License, Version 2.0 (the "License"); you may not use this file
      16             :  *   except in compliance with the License. You may obtain a copy of
      17             :  *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
      18             :  */
      19             : 
      20             : #include <helper/networkdomain.hxx>
      21             : 
      22             : #ifdef WNT
      23             : //_________________________________________________________________________________________________________________
      24             : //  Windows
      25             : //_________________________________________________________________________________________________________________
      26             : 
      27             : #define UNICODE
      28             : #if defined _MSC_VER
      29             : #pragma warning(push, 1)
      30             : #endif
      31             : #include <windows.h>
      32             : #if defined _MSC_VER
      33             : #pragma warning(pop)
      34             : #endif
      35             : 
      36             : static DWORD WINAPI GetUserDomainW_NT( LPWSTR lpBuffer, DWORD nSize )
      37             : {
      38             :     return GetEnvironmentVariable( TEXT("USERDOMAIN"), lpBuffer, nSize );
      39             : }
      40             : 
      41             : static rtl::OUString GetUserDomain()
      42             : {
      43             :     sal_Unicode aBuffer[256];
      44             :     DWORD   nResult;
      45             : 
      46             :     nResult = GetUserDomainW_NT( reinterpret_cast<LPWSTR>(aBuffer), sizeof( aBuffer ) );
      47             : 
      48             :     if ( nResult > 0 )
      49             :         return rtl::OUString( aBuffer );
      50             :     else
      51             :         return rtl::OUString();
      52             : }
      53             : 
      54             : //_________________________________________________________________________________________________________________
      55             : //  Windows
      56             : //_________________________________________________________________________________________________________________
      57             : 
      58             : namespace framework
      59             : {
      60             : 
      61             : rtl::OUString NetworkDomain::GetYPDomainName()
      62             : {
      63             :     return ::rtl::OUString();
      64             : }
      65             : 
      66             : rtl::OUString NetworkDomain::GetNTDomainName()
      67             : {
      68             :     return GetUserDomain();
      69             : }
      70             : 
      71             : }
      72             : 
      73             : #elif defined( UNIX )
      74             : 
      75             : #include <rtl/ustring.h>
      76             : #include <stdlib.h>
      77             : #include <errno.h>
      78             : #include <osl/thread.h>
      79             : 
      80             : //_________________________________________________________________________________________________________________
      81             : //  Unix
      82             : //_________________________________________________________________________________________________________________
      83             : 
      84             : #if defined( SOLARIS )
      85             : 
      86             : //_________________________________________________________________________________________________________________
      87             : //  Solaris
      88             : //_________________________________________________________________________________________________________________
      89             : 
      90             : #include <sys/systeminfo.h>
      91             : #include <sal/alloca.h>
      92             : 
      93             : static rtl_uString *getDomainName()
      94             : {
      95             :     /* Initialize and assume failure */
      96             :     rtl_uString *ustrDomainName = NULL;
      97             : 
      98             :     char    szBuffer[256];
      99             : 
     100             :     long    nCopied = sizeof(szBuffer);
     101             :     char    *pBuffer = szBuffer;
     102             :     long    nBufSize;
     103             : 
     104             :     do
     105             :     {
     106             :         nBufSize = nCopied;
     107             :         nCopied = sysinfo( SI_SRPC_DOMAIN, pBuffer, nBufSize );
     108             : 
     109             :         /*  If nCopied is greater than buffersize we need to allocate
     110             :             a buffer with suitable size */
     111             : 
     112             :         if ( nCopied > nBufSize )
     113             :             pBuffer = (char *)alloca( nCopied );
     114             : 
     115             :     } while ( nCopied > nBufSize );
     116             : 
     117             :     if ( -1 != nCopied  )
     118             :     {
     119             :         rtl_string2UString(
     120             :             &ustrDomainName,
     121             :             pBuffer,
     122             :             nCopied - 1,
     123             :             osl_getThreadTextEncoding(),
     124             :             OSTRING_TO_OUSTRING_CVTFLAGS );
     125             :     }
     126             : 
     127             :     return ustrDomainName;
     128             : }
     129             : 
     130             : #elif defined( LINUX ) /* endif SOLARIS */
     131             : 
     132             : //_________________________________________________________________________________________________________________
     133             : //  Linux
     134             : //_________________________________________________________________________________________________________________
     135             : 
     136             : #include <unistd.h>
     137             : #include <string.h>
     138             : 
     139           0 : static rtl_uString *getDomainName()
     140             : {
     141             :     /* Initialize and assume failure */
     142           0 :     rtl_uString *ustrDomainName = NULL;
     143             : 
     144             :     char    *pBuffer;
     145             :     int     result;
     146           0 :     size_t  nBufSize = 0;
     147             : 
     148           0 :     do
     149             :     {
     150           0 :         nBufSize += 256; /* Increase buffer size by steps of 256 bytes */
     151           0 :         pBuffer = (char *)alloca( nBufSize );
     152           0 :         result = getdomainname( pBuffer, nBufSize );
     153             :         /* If buffersize in not large enough -1 is returned and errno
     154             :         is set to EINVAL. This only applies to libc. With glibc the name
     155             :         is truncated. */
     156           0 :     } while ( -1 == result && EINVAL == errno );
     157             : 
     158           0 :     if ( 0 == result )
     159             :     {
     160             :         rtl_string2UString(
     161             :             &ustrDomainName,
     162             :             pBuffer,
     163           0 :             strlen( pBuffer ),
     164           0 :             osl_getThreadTextEncoding(),
     165           0 :             OSTRING_TO_OUSTRING_CVTFLAGS );
     166             :     }
     167             : 
     168           0 :     return ustrDomainName;
     169             : }
     170             : 
     171             : #else /* LINUX */
     172             : 
     173             : //_________________________________________________________________________________________________________________
     174             : //  Other Unix
     175             : //_________________________________________________________________________________________________________________
     176             : 
     177             : static rtl_uString *getDomainName()
     178             : {
     179             :     return NULL;
     180             : }
     181             : 
     182             : #endif
     183             : 
     184             : //_________________________________________________________________________________________________________________
     185             : //  Unix
     186             : //_________________________________________________________________________________________________________________
     187             : 
     188             : namespace framework
     189             : {
     190             : 
     191           0 : rtl::OUString NetworkDomain::GetYPDomainName()
     192             : {
     193           0 :     rtl_uString* pResult = getDomainName();
     194           0 :     if ( pResult )
     195           0 :         return rtl::OUString( pResult );
     196             :     else
     197           0 :         return rtl::OUString();
     198             : }
     199             : 
     200           0 : rtl::OUString NetworkDomain::GetNTDomainName()
     201             : {
     202           0 :     return ::rtl::OUString();
     203             : }
     204             : 
     205             : }
     206             : 
     207             : #else /* UNIX */
     208             : 
     209             : //_________________________________________________________________________________________________________________
     210             : //  Other operating systems (non-Windows and non-Unix)
     211             : //_________________________________________________________________________________________________________________
     212             : 
     213             : namespace framework
     214             : {
     215             : 
     216             : rtl::OUString NetworkDomain::GetYPDomainName()
     217             : {
     218             :     return rtl::OUString();
     219             : }
     220             : 
     221             : rtl::OUString NetworkDomain::GetNTDomainName()
     222             : {
     223             :     return rtl::OUString();
     224             : }
     225             : 
     226             : }
     227             : 
     228             : #endif
     229             : 
     230             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10