libinst.c 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  1. /** BEGIN COPYRIGHT BLOCK
  2. * This Program is free software; you can redistribute it and/or modify it under
  3. * the terms of the GNU General Public License as published by the Free Software
  4. * Foundation; version 2 of the License.
  5. *
  6. * This Program is distributed in the hope that it will be useful, but WITHOUT
  7. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  8. * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
  9. *
  10. * You should have received a copy of the GNU General Public License along with
  11. * this Program; if not, write to the Free Software Foundation, Inc., 59 Temple
  12. * Place, Suite 330, Boston, MA 02111-1307 USA.
  13. *
  14. * In addition, as a special exception, Red Hat, Inc. gives You the additional
  15. * right to link the code of this Program with code not covered under the GNU
  16. * General Public License ("Non-GPL Code") and to distribute linked combinations
  17. * including the two, subject to the limitations in this paragraph. Non-GPL Code
  18. * permitted under this exception must only link to the code of this Program
  19. * through those well defined interfaces identified in the file named EXCEPTION
  20. * found in the source code files (the "Approved Interfaces"). The files of
  21. * Non-GPL Code may instantiate templates or use macros or inline functions from
  22. * the Approved Interfaces without causing the resulting work to be covered by
  23. * the GNU General Public License. Only Red Hat, Inc. may make changes or
  24. * additions to the list of Approved Interfaces. You must obey the GNU General
  25. * Public License in all respects for all of the Program code and other code used
  26. * in conjunction with the Program except the Non-GPL Code covered by this
  27. * exception. If you modify this file, you may extend this exception to your
  28. * version of the file, but you are not obligated to do so. If you do not wish to
  29. * provide this exception without modification, you must delete this exception
  30. * statement from your version and license this file solely under the GPL without
  31. * exception.
  32. *
  33. *
  34. * Copyright (C) 2001 Sun Microsystems, Inc. Used by permission.
  35. * Copyright (C) 2005 Red Hat, Inc.
  36. * All rights reserved.
  37. * END COPYRIGHT BLOCK **/
  38. #include "libinst.h"
  39. #include <stdio.h>
  40. //--------------------------------------------------------------------------//
  41. // Use this instead of installer installer sdk stuff so window is hidden //
  42. //--------------------------------------------------------------------------//
  43. DWORD _LaunchAndWait(char *szCommandLine, DWORD dwTimeout)
  44. {
  45. PROCESS_INFORMATION pi;
  46. STARTUPINFO si;
  47. DWORD dwExitCode = 0;
  48. ZeroMemory(&pi, sizeof(pi));
  49. ZeroMemory(&si, sizeof(si));
  50. si.cb = sizeof(STARTUPINFO);
  51. si.dwFlags = STARTF_USESHOWWINDOW;
  52. // si.wShowWindow = SW_HIDE;
  53. // show for debuggin for now
  54. si.dwFlags = SW_SHOW;
  55. if(CreateProcess(NULL, szCommandLine, NULL, NULL, FALSE, 0, NULL, NULL, &si, &pi))
  56. {
  57. if(WaitForSingleObject(pi.hProcess, dwTimeout) == WAIT_OBJECT_0)
  58. GetExitCodeProcess(pi.hProcess, &dwExitCode);
  59. CloseHandle(pi.hThread);
  60. CloseHandle(pi.hProcess);
  61. }
  62. return(dwExitCode);
  63. }
  64. //////////////////////////////////////////////////////////////////////////////
  65. // WriteSummaryStringRC
  66. //
  67. // write summary info string using resource
  68. //
  69. // returns number of bytes written by wsprintf
  70. //
  71. int WriteSummaryStringRC(LPSTR psz, char *format, HINSTANCE hModule, UINT uStringID, char *value)
  72. {
  73. char szTempString[MAX_STR_SIZE]={0};
  74. int nReturn= 0;
  75. LoadString( hModule, uStringID, szTempString, MAX_STR_SIZE);
  76. if(value)
  77. {
  78. nReturn = wsprintf(psz, format, szTempString, value);
  79. }else{
  80. nReturn = wsprintf(psz, format, szTempString);
  81. }
  82. return nReturn;
  83. }
  84. //////////////////////////////////////////////////////////////////////////////
  85. // WriteSummaryStringRC
  86. //
  87. // write summary info integer using resource
  88. //
  89. // returns number of bytes written by wsprintf
  90. //
  91. int WriteSummaryIntRC(LPSTR psz, char *format, HINSTANCE hModule, UINT uStringID, int value)
  92. {
  93. char szTempString[MAX_STR_SIZE]={0};
  94. int nReturn = 0;
  95. LoadString( hModule, uStringID, szTempString, MAX_STR_SIZE);
  96. nReturn = wsprintf(psz, format, szTempString, value);
  97. return nReturn;
  98. }
  99. void
  100. DSGetHostName(char *hostname, int bufsiz)
  101. {
  102. char *setupHostname = setupGetHostName();
  103. if (setupHostname) {
  104. int len = strlen(setupHostname);
  105. if (len >= bufsiz)
  106. len = bufsiz - 1;
  107. strncpy(hostname, setupHostname, len);
  108. hostname[len] = 0;
  109. setupFree(setupHostname);
  110. } else {
  111. GetHostName(hostname, bufsiz);
  112. }
  113. }
  114. void
  115. DSGetDefaultSuffix(char *suffix, const char *hostname)
  116. {
  117. const char *SUF = "dc=";
  118. const int SUF_LEN = 3;
  119. char *sptr = suffix;
  120. const char *ptr = 0;
  121. if (!hostname) {
  122. sprintf(sptr, "%s%s", SUF, "unknown-suffix");
  123. return; /* bogus domain name */
  124. } else {
  125. ptr = strchr(hostname, '.'); /* skip to first . in hostname */
  126. if (!ptr) {
  127. sprintf(sptr, "%s%s", SUF, hostname);
  128. return; /* no domain name */
  129. }
  130. ptr++; /* skip to beginning of domain name */
  131. }
  132. *sptr = 0;
  133. strcat(sptr, SUF);
  134. sptr += SUF_LEN;
  135. for (; *ptr; ++ptr) {
  136. if (*ptr == '.') {
  137. strcat(sptr, ", ");
  138. sptr += 2;
  139. strcat(sptr, SUF);
  140. sptr += SUF_LEN;
  141. } else {
  142. *sptr++ = *ptr;
  143. }
  144. }
  145. *sptr = 0;
  146. return;
  147. }