~zulcss/ubuntu/lucid/likewise-open/likewise-open-sru

« back to all changes in this revision

Viewing changes to domainjoin/libdomainjoin/src/djdaemonmgr.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:
27
27
#include "ctstrutils.h"
28
28
#include "djauthinfo.h"
29
29
 
 
30
// aka: CENTERROR_LICENSE_INCORRECT
 
31
static DWORD GPAGENT_LICENSE_ERROR = 0x00002001;
 
32
 
 
33
// CENTERROR_LICENSE_EXPIRED
 
34
static DWORD GPAGENT_LICENSE_EXPIRED_ERROR = 0x00002002;
 
35
 
30
36
#define GCE(x) GOTO_CLEANUP_ON_CENTERROR((x))
31
37
 
32
38
static QueryResult QueryStopDaemons(const JoinProcessOptions *options, LWException **exc)
156
162
void DJRestartIfRunning(PCSTR daemon, LWException **exc)
157
163
{
158
164
    BOOLEAN running;
159
 
    PSTR initPath = NULL;
160
 
    PSTR daemonPath = NULL;
161
 
    CENTERROR ceError;
162
 
 
163
 
    LW_CLEANUP_CTERR(exc, CTFindFileInPath(daemon, "/etc/init.d:/etc/rc.d/init.d", &initPath));
164
 
    DJ_LOG_INFO("Found '%s' at '%s'", daemon, initPath);
165
 
 
166
 
    LW_TRY(exc, DJGetDaemonStatus(initPath, &running, &LW_EXC));
 
165
    LWException *inner = NULL;
 
166
 
 
167
    DJGetDaemonStatus(daemon, &running, &inner);
 
168
    if(!LW_IS_OK(inner) && inner->code == CENTERROR_DOMAINJOIN_MISSING_DAEMON)
 
169
    {
 
170
        //The daemon isn't installed
 
171
        LW_HANDLE(&inner);
 
172
        running = FALSE;
 
173
    }
 
174
    LW_CLEANUP(exc, inner);
167
175
    if(!running)
168
 
    {
169
 
        //The nscd init script on Solaris does not support the query option,
170
 
        //so it looks like the daemon is never running. So we'll run a ps
171
 
        //command and HUP the daemon if it is running
172
 
 
173
 
        pid_t daemonPid;
174
 
        LW_CLEANUP_CTERR(exc, CTFindFileInPath(daemon, "/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin", &daemonPath));
175
 
        ceError = CTGetPidOfCmdLine(NULL, daemonPath, NULL, 0, &daemonPid, NULL);
176
 
        if(ceError == CENTERROR_NO_SUCH_PROCESS || ceError == CENTERROR_NOT_IMPLEMENTED)
177
 
        {
178
 
            //Nope, couldn't find the daemon running
179
 
            goto cleanup;
180
 
        }
181
 
        LW_CLEANUP_CTERR(exc, ceError);
182
 
 
183
 
        DJ_LOG_INFO("Sending HUP to '%s' binary, pid '%d'.", daemonPath, daemonPid);
184
 
 
185
 
        LW_CLEANUP_CTERR(exc, CTSendSignal(daemonPid, SIGHUP));
186
176
        goto cleanup;
187
 
    }
188
 
 
189
 
    DJ_LOG_INFO("Restarting '%s'", initPath);
190
 
    LW_TRY(exc, DJStartStopDaemon(initPath, FALSE, NULL, &LW_EXC));
191
 
    LW_TRY(exc, DJStartStopDaemon(initPath, TRUE, NULL, &LW_EXC));
192
 
 
193
 
cleanup:
194
 
    CT_SAFE_FREE_STRING(initPath);
195
 
    CT_SAFE_FREE_STRING(daemonPath);
 
177
 
 
178
    DJ_LOG_INFO("Restarting '%s'", daemon);
 
179
    LW_TRY(exc, DJStartStopDaemon(daemon, FALSE, NULL, &LW_EXC));
 
180
    DJ_LOG_INFO("Starting '%s'", daemon);
 
181
    LW_TRY(exc, DJStartStopDaemon(daemon, TRUE, NULL, &LW_EXC));
 
182
 
 
183
cleanup:
 
184
    LW_HANDLE(&inner);
 
185
}
 
186
 
 
187
void
 
188
DJManageDaemons(
 
189
    PSTR pszDomainName,
 
190
    BOOLEAN bStart,
 
191
    LWException **exc
 
192
    )
 
193
{
 
194
    PSTR pszDomainNameAllUpper = NULL;
 
195
    BOOLEAN bFileExists = TRUE;
 
196
    FILE* fp = NULL;
 
197
    PSTR pszErrFilePath = "/var/cache/centeris/grouppolicy/gpagentd.err";
 
198
    CHAR szBuf[256+1];
 
199
    DWORD dwGPErrCode = 0;
 
200
    LWException *innerExc = NULL;
 
201
    int daemonCount;
 
202
    int i;
 
203
 
 
204
#define PWGRD "/etc/rc.config.d/pwgr"
 
205
    LW_CLEANUP_CTERR(exc, CTCheckFileExists(PWGRD, &bFileExists));
 
206
    if(bFileExists)
 
207
    {
 
208
        //Shutdown pwgr (a nscd-like daemon) on HP-UX because it only handles
 
209
        //usernames up to 8 characters in length.
 
210
        LW_TRY(exc, DJStartStopDaemon("pwgr", FALSE, NULL, &LW_EXC));
 
211
        LW_CLEANUP_CTERR(exc, CTRunSedOnFile(PWGRD, PWGRD, FALSE, "s/=1/=0/"));
 
212
    }
 
213
 
 
214
    //Figure out how many daemons there are
 
215
    for(daemonCount = 0; daemonList[daemonCount].primaryName != NULL; daemonCount++);
 
216
 
 
217
    if(bStart)
 
218
    {
 
219
        CHAR szStartPriority[32];
 
220
        CHAR szStopPriority[32];
 
221
 
 
222
        //Start the daemons in ascending order
 
223
        for(i = 0; i < daemonCount; i++)
 
224
        {
 
225
            sprintf(szStartPriority, "%d", daemonList[i].startPriority);
 
226
            sprintf(szStopPriority,  "%d", daemonList[i].stopPriority);
 
227
 
 
228
            DJManageDaemon(daemonList[i].primaryName,
 
229
                             bStart,
 
230
                             NULL,
 
231
                             szStartPriority,
 
232
                             szStopPriority,
 
233
                             &innerExc);
 
234
 
 
235
            //Try the alternate daemon name if there is one
 
236
            if (!LW_IS_OK(innerExc) &&
 
237
                    innerExc->code == CENTERROR_DOMAINJOIN_MISSING_DAEMON &&
 
238
                    daemonList[i].alternativeName != NULL)
 
239
            {
 
240
                LW_HANDLE(&innerExc);
 
241
                DJManageDaemon(daemonList[i].alternativeName,
 
242
                                 bStart,
 
243
                                 NULL,
 
244
                                 szStartPriority,
 
245
                                 szStopPriority,
 
246
                                 &innerExc);
 
247
            }
 
248
            if (!LW_IS_OK(innerExc) &&
 
249
                    innerExc->code == CENTERROR_DOMAINJOIN_MISSING_DAEMON &&
 
250
                    !daemonList[i].required)
 
251
            {
 
252
                LW_HANDLE(&innerExc);
 
253
            }
 
254
            if (LW_IS_OK(innerExc) && !strcmp(daemonList[i].primaryName, "centeris.com-gpagentd"))
 
255
            {
 
256
                LW_CLEANUP_CTERR(exc, CTCheckFileExists(pszErrFilePath, &bFileExists));
 
257
 
 
258
                if (bFileExists) {
 
259
 
 
260
                    LW_HANDLE(&innerExc);
 
261
                    fp = fopen(pszErrFilePath, "r");
 
262
                    if (fp != NULL) {
 
263
 
 
264
                        if (fgets(szBuf, 256, fp) != NULL) {
 
265
 
 
266
                            CTStripWhitespace(szBuf);
 
267
 
 
268
                            dwGPErrCode = atoi(szBuf);
 
269
 
 
270
                            if (dwGPErrCode == GPAGENT_LICENSE_ERROR ||
 
271
                                dwGPErrCode == GPAGENT_LICENSE_EXPIRED_ERROR) {
 
272
 
 
273
                                LW_RAISE(exc, CENTERROR_DOMAINJOIN_LICENSE_ERROR);
 
274
                                goto cleanup;
 
275
 
 
276
                            }
 
277
                        }
 
278
 
 
279
                    } else {
 
280
 
 
281
                        DJ_LOG_ERROR("Failed to open file [%s]", pszErrFilePath);
 
282
 
 
283
                    }
 
284
                }
 
285
            }
 
286
            LW_CLEANUP(exc, innerExc);
 
287
        }
 
288
    }
 
289
    else
 
290
    {
 
291
        CHAR szStartPriority[32];
 
292
        CHAR szStopPriority[32];
 
293
 
 
294
        //Stop the daemons in descending order
 
295
        for(i = daemonCount - 1; i >= 0; i--)
 
296
        {
 
297
            sprintf(szStartPriority, "%d", daemonList[i].startPriority);
 
298
            sprintf(szStopPriority,  "%d", daemonList[i].stopPriority);
 
299
 
 
300
            DJManageDaemon(daemonList[i].primaryName,
 
301
                             bStart,
 
302
                             NULL,
 
303
                             szStartPriority,
 
304
                             szStopPriority,
 
305
                             &innerExc);
 
306
 
 
307
            //Try the alternate daemon name if there is one
 
308
            if (!LW_IS_OK(innerExc) &&
 
309
                    innerExc->code == CENTERROR_DOMAINJOIN_MISSING_DAEMON &&
 
310
                    daemonList[i].alternativeName != NULL)
 
311
            {
 
312
                LW_HANDLE(&innerExc);
 
313
                DJManageDaemon(daemonList[i].alternativeName,
 
314
                                 bStart,
 
315
                                 NULL,
 
316
                                 szStartPriority,
 
317
                                 szStopPriority,
 
318
                                 &innerExc);
 
319
            }
 
320
            if (!LW_IS_OK(innerExc) &&
 
321
                    innerExc->code == CENTERROR_DOMAINJOIN_MISSING_DAEMON &&
 
322
                    !daemonList[i].required)
 
323
            {
 
324
                LW_HANDLE(&innerExc);
 
325
            }
 
326
            LW_CLEANUP(exc, innerExc);
 
327
        }
 
328
    }
 
329
 
 
330
cleanup:
 
331
    CTSafeCloseFile(&fp);
 
332
 
 
333
    if (pszDomainNameAllUpper)
 
334
        CTFreeString(pszDomainNameAllUpper);
 
335
 
 
336
    LW_HANDLE(&innerExc);
196
337
}