Debian Codegraph @

src/ioperm-0.4-patched/admin/install.c

raw
1 /*
2 * $Id: install.c,v 1.5 2003/01/23 15:16:35 telka Exp $
3 *
4 * Copyright (C) 2002 ETC s.r.o.
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version 2
9 * of the License, or (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
19 * 02111-1307, USA.
20 *
21 * Written by Marcel Telka <[email protected]>, 2002.
22 *
23 */
24
25 #include <windows.h>
26 #include <stdio.h>
27
28 #ifdef __CYGWIN__
29 #include <sys/cygwin.h>
30 #endif
31
32 #ifdef __MINGW32__
33 #include <io.h>
34 #endif
35
36 void
37 start( int verb, const char *fnc )
38 {
39 if (verb)
40 printf( "%-20s", fnc );
41 }
42
43 void
44 err( int verb, const char *fnc )
45 {
46 if (verb)
47 printf( "failed\n" );
48 else
49 fprintf( stderr, "%s function call failed.\n", fnc );
50 }
51
52 void
53 ok( int verb )
54 {
55 if (verb)
56 printf( "ok\n" );
57 }
58
59 int
60 install( int verb )
61 {
62 SC_HANDLE scm;
63 SC_HANDLE svc;
64 char drv_path[MAX_PATH];
65
66 if (verb)
67 printf( "Installing ioperm.sys...\n" );
68
69 start( verb, "OpenSCManager" );
70 scm = OpenSCManager( NULL, NULL, SC_MANAGER_ALL_ACCESS );
71 if (scm == NULL) {
72 err( verb, "OpenSCManager" );
73 return 0;
74 }
75 ok( verb );
76
77 #ifdef __CYGWIN__
78 cygwin_conv_to_full_win32_path( PREFIX "/bin/ioperm.sys", drv_path );
79 if(access(drv_path,F_OK)!=0)
80 #endif
81 { /* cygwin is not installed */
82 if(getcwd(drv_path,sizeof(drv_path))==NULL)
83 {
84 return 0;
85 }
86 strcat(drv_path,"/ioperm.sys");
87 }
88
89 start( verb, "CreateService" );
90 svc = CreateService( scm, TEXT("ioperm"), TEXT("ioperm support for Cygwin driver"), SERVICE_ALL_ACCESS,
91 SERVICE_KERNEL_DRIVER, SERVICE_AUTO_START, SERVICE_ERROR_NORMAL, drv_path, NULL, NULL,
92 NULL, NULL, NULL );
93 if (svc == NULL) {
94 if (GetLastError() != ERROR_SERVICE_EXISTS)
95 err( verb, "CreateService" );
96 else {
97 if (verb)
98 printf( "failed\n" );
99 printf( "ioperm.sys is already installed.\n" );
100 start( verb, "OpenService" );
101 svc = OpenService( scm, TEXT("ioperm"), SERVICE_ALL_ACCESS );
102 if (!svc)
103 err( verb, "OpenService" );
104 }
105
106 if (svc == NULL) {
107 CloseServiceHandle( scm );
108 return 0;
109 }
110 }
111 ok( verb );
112
113 start( verb, "StartService" );
114 if (!StartService( svc, 0, NULL )) {
115 if (GetLastError() != ERROR_SERVICE_ALREADY_RUNNING)
116 err( verb, "StartService" );
117 else {
118 if (verb)
119 printf( "failed\n" );
120 printf( "ioperm.sys is already running.\n" );
121 }
122 } else
123 ok( verb );
124
125 CloseServiceHandle( svc );
126 CloseServiceHandle( scm );
127
128 return 1;
129 }