~ubuntu-branches/ubuntu/utopic/gridengine/utopic

« back to all changes in this revision

Viewing changes to source/daemons/qmaster/sge_c_gdi.c

  • Committer: Bazaar Package Importer
  • Author(s): Mark Hymers
  • Date: 2008-06-25 22:36:13 UTC
  • Revision ID: james.westby@ubuntu.com-20080625223613-tvd9xlhuoct9kyhm
Tags: upstream-6.2~beta2
ImportĀ upstreamĀ versionĀ 6.2~beta2

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*___INFO__MARK_BEGIN__*/
 
2
/*************************************************************************
 
3
 * 
 
4
 *  The Contents of this file are made available subject to the terms of
 
5
 *  the Sun Industry Standards Source License Version 1.2
 
6
 * 
 
7
 *  Sun Microsystems Inc., March, 2001
 
8
 * 
 
9
 * 
 
10
 *  Sun Industry Standards Source License Version 1.2
 
11
 *  =================================================
 
12
 *  The contents of this file are subject to the Sun Industry Standards
 
13
 *  Source License Version 1.2 (the "License"); You may not use this file
 
14
 *  except in compliance with the License. You may obtain a copy of the
 
15
 *  License at http://gridengine.sunsource.net/Gridengine_SISSL_license.html
 
16
 * 
 
17
 *  Software provided under this License is provided on an "AS IS" basis,
 
18
 *  WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
 
19
 *  WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS,
 
20
 *  MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING.
 
21
 *  See the License for the specific provisions governing your rights and
 
22
 *  obligations concerning the Software.
 
23
 * 
 
24
 *   The Initial Developer of the Original Code is: Sun Microsystems, Inc.
 
25
 * 
 
26
 *   Copyright: 2001 by Sun Microsystems, Inc.
 
27
 * 
 
28
 *   All Rights Reserved.
 
29
 * 
 
30
 ************************************************************************/
 
31
/*___INFO__MARK_END__*/
 
32
 
 
33
#include <string.h>
 
34
#include <stdlib.h>
 
35
#include <errno.h>
 
36
 
 
37
#include "sge_all_listsL.h"
 
38
#include "cull.h"
 
39
#include "sge.h"
 
40
#include "sge_order.h"
 
41
#include "sge_follow.h"
 
42
#include "sge_c_gdi.h"
 
43
#include "sge_host.h"
 
44
#include "sge_host_qmaster.h"
 
45
#include "sge_job_qmaster.h"
 
46
#include "sge_userset_qmaster.h"
 
47
#include "sge_calendar_qmaster.h"
 
48
#include "sge_manop_qmaster.h"
 
49
#include "sge_centry_qmaster.h"
 
50
#include "sge_cqueue_qmaster.h"
 
51
#include "sge_pe_qmaster.h"
 
52
#include "sge_resource_quota_qmaster.h"
 
53
#include "sge_resource_quota.h"
 
54
#include "sge_conf.h"
 
55
#include "configuration_qmaster.h"
 
56
#include "sge_event_master.h"
 
57
#include "sched_conf_qmaster.h"
 
58
#include "sge_userprj_qmaster.h"
 
59
#include "sge_ckpt_qmaster.h"
 
60
#include "sge_hgroup_qmaster.h"
 
61
#include "sge_sharetree_qmaster.h"
 
62
#include "sge_cuser_qmaster.h"
 
63
#include "sge_feature.h"
 
64
#include "sge_qmod_qmaster.h"
 
65
#include "sge_prog.h"
 
66
#include "sgermon.h"
 
67
#include "sge_log.h"
 
68
#include "sge_qmaster_threads.h"
 
69
#include "sge_time.h"  
 
70
#include "version.h"  
 
71
#include "sge_security.h"  
 
72
#include "sge_answer.h"
 
73
#include "sge_pe.h"
 
74
#include "sge_ckpt.h"
 
75
#include "sge_qinstance.h"
 
76
#include "sge_userprj.h"
 
77
#include "sge_job.h"
 
78
#include "sge_userset.h"
 
79
#include "sge_manop.h"
 
80
#include "sge_calendar.h"
 
81
#include "sge_sharetree.h"
 
82
#include "sge_hgroup.h"
 
83
#include "sge_cuser.h"
 
84
#include "sge_centry.h"
 
85
#include "sge_cqueue.h"
 
86
#include "sge_lock.h"
 
87
#include "sge_advance_reservation_qmaster.h"
 
88
#include "sge_sched_process_events.h"
 
89
#include "sge_thread_scheduler.h"
 
90
#include "sge_thread_jvm.h"
 
91
 
 
92
#include "uti/sge_bootstrap.h"
 
93
 
 
94
#include "gdi/sge_gdi_packet_pb_cull.h"
 
95
#include "gdi/sge_gdi_packet.h"
 
96
 
 
97
#include "sgeobj/sge_event.h"
 
98
#include "sgeobj/sge_utility.h"
 
99
 
 
100
#include "msg_common.h"
 
101
#include "msg_qmaster.h"
 
102
 
 
103
static void
 
104
sge_c_gdi_get(gdi_object_t *ao, sge_gdi_packet_class_t *packet, sge_gdi_task_class_t *task, monitoring_t *monitor);
 
105
 
 
106
static void
 
107
sge_c_gdi_add(sge_gdi_ctx_class_t *ctx, sge_gdi_packet_class_t *packet, sge_gdi_task_class_t *task,
 
108
              gdi_object_t *ao, int sub_command, monitoring_t *monitor); 
 
109
 
 
110
static void sge_c_gdi_del(sge_gdi_ctx_class_t *ctx,
 
111
                          sge_gdi_packet_class_t *packet, sge_gdi_task_class_t *task,
 
112
                          int sub_command, 
 
113
                          monitoring_t *monitor);
 
114
 
 
115
static void sge_c_gdi_mod(sge_gdi_ctx_class_t *ctx, gdi_object_t *ao, 
 
116
                          sge_gdi_packet_class_t *packet, sge_gdi_task_class_t *task,
 
117
                          int sub_command, 
 
118
                          monitoring_t *monitor);
 
119
 
 
120
static void sge_c_gdi_copy(sge_gdi_ctx_class_t *ctx, gdi_object_t *ao,  
 
121
                           sge_gdi_packet_class_t *packet, sge_gdi_task_class_t *task, int sub_command, 
 
122
                           monitoring_t *monitor);
 
123
 
 
124
static void sge_c_gdi_trigger(sge_gdi_ctx_class_t *ctx,  
 
125
                              sge_gdi_packet_class_t *packet, sge_gdi_task_class_t *task,
 
126
                              monitoring_t *monitor);
 
127
 
 
128
static void sge_c_gdi_permcheck(sge_gdi_packet_class_t *packet, sge_gdi_task_class_t *task,
 
129
                                monitoring_t *monitor);
 
130
 
 
131
static void sge_gdi_do_permcheck(sge_gdi_packet_class_t *packet, sge_gdi_task_class_t *task);
 
132
 
 
133
static void sge_c_gdi_replace(sge_gdi_ctx_class_t *ctx, gdi_object_t *ao, 
 
134
                              sge_gdi_packet_class_t *packet, sge_gdi_task_class_t *task,
 
135
                              int sub_command, monitoring_t *monitor);
 
136
 
 
137
 
 
138
static void 
 
139
sge_gdi_shutdown_event_client(sge_gdi_ctx_class_t *ctx, sge_gdi_packet_class_t *packet, 
 
140
                              sge_gdi_task_class_t *task, monitoring_t *monitor, 
 
141
                              object_description *object_base);
 
142
 
 
143
static void 
 
144
sge_gdi_tigger_thread_state_transition(sge_gdi_ctx_class_t *ctx, 
 
145
                                       sge_gdi_packet_class_t *packet, 
 
146
                                       sge_gdi_task_class_t *task, 
 
147
                                       monitoring_t *monitor);
 
148
 
 
149
static int  get_client_id(lListElem*, int*);
 
150
 
 
151
static void
 
152
trigger_scheduler_monitoring(sge_gdi_packet_class_t *packet, sge_gdi_task_class_t *task,
 
153
                             monitoring_t *monitor);
 
154
 
 
155
static int sge_chck_mod_perm_user(lList **alpp, u_long32 target, char *user, monitoring_t *monitor);
 
156
static int sge_chck_mod_perm_host(lList **alpp, u_long32 target, char *host, 
 
157
                                  char *commproc, int mod, lListElem *ep, 
 
158
                                  monitoring_t *monitor, object_description *object_base);
 
159
 
 
160
static bool
 
161
sge_task_check_get_perm_host(sge_gdi_packet_class_t *packet, sge_gdi_task_class_t *task,
 
162
                             monitoring_t *monitor, object_description *object_base);
 
163
 
 
164
 
 
165
static int schedd_mod(sge_gdi_ctx_class_t *ctx, 
 
166
                      lList **alpp, lListElem *modp, lListElem *ep, int add, 
 
167
                      const char *ruser, const char *rhost, gdi_object_t *object, 
 
168
                      int sub_command, monitoring_t *monitor );
 
169
 
 
170
/*
 
171
 * Prevent these functions made inline by compiler. This is 
 
172
 * necessary for Solaris 10 dtrace pid provider to work.
 
173
 */
 
174
#ifdef SOLARIS
 
175
#pragma no_inline(sge_c_gdi_permcheck, sge_c_gdi_trigger, sge_c_gdi_copy, sge_c_gdi_get, sge_c_gdi_del, sge_c_gdi_mod, sge_c_gdi_add, sge_c_gdi_copy)
 
176
#endif
 
177
 
 
178
/* ------------------------------ generic gdi objects --------------------- */
 
179
/* *INDENT-OFF* */
 
180
static gdi_object_t gdi_object[] = {
 
181
   { SGE_CALENDAR_LIST,     CAL_name,  CAL_Type,  "calendar",                SGE_TYPE_CALENDAR,        calendar_mod, calendar_spool, calendar_update_queue_states },
 
182
   { SGE_EVENT_LIST,        0,         NULL,      "event",                   SGE_TYPE_NONE,            NULL,         NULL,           NULL },
 
183
   { SGE_ADMINHOST_LIST,    AH_name,   AH_Type,   "adminhost",               SGE_TYPE_ADMINHOST,       host_mod,     host_spool,     host_success },
 
184
   { SGE_SUBMITHOST_LIST,   SH_name,   SH_Type,   "submithost",              SGE_TYPE_SUBMITHOST,      host_mod,     host_spool,     host_success },
 
185
   { SGE_EXECHOST_LIST,     EH_name,   EH_Type,   "exechost",                SGE_TYPE_EXECHOST,        host_mod,     host_spool,     host_success },
 
186
   { SGE_CQUEUE_LIST,       CQ_name,   CQ_Type,   "cluster queue",           SGE_TYPE_CQUEUE,          cqueue_mod,   cqueue_spool,   cqueue_success },
 
187
   { SGE_JOB_LIST,          0,         NULL,      "job",                     SGE_TYPE_JOB,             NULL,         NULL,           NULL },
 
188
   { SGE_CENTRY_LIST,       CE_name,   CE_Type,   "complex entry",           SGE_TYPE_CENTRY,          centry_mod,   centry_spool,   centry_success },
 
189
   { SGE_ORDER_LIST,        0,         NULL,      "order",                   SGE_TYPE_NONE,            NULL,         NULL,           NULL },
 
190
   { SGE_MASTER_EVENT,      0,         NULL,      "master event",            SGE_TYPE_NONE,            NULL,         NULL,           NULL },
 
191
   { SGE_MANAGER_LIST,      0,         NULL,      "manager",                 SGE_TYPE_MANAGER,         NULL,         NULL,           NULL },
 
192
   { SGE_OPERATOR_LIST,     0,         NULL,      "operator",                SGE_TYPE_OPERATOR,        NULL,         NULL,           NULL },
 
193
   { SGE_PE_LIST,           PE_name,   PE_Type,   "parallel environment",    SGE_TYPE_PE,              pe_mod,       pe_spool,       pe_success },
 
194
   { SGE_CONFIG_LIST,       0,         NULL,      "configuration",           SGE_TYPE_NONE,            NULL,         NULL,           NULL },
 
195
   { SGE_SC_LIST,           0,         NULL,      "scheduler configuration", SGE_TYPE_NONE,            schedd_mod,   NULL,           NULL },
 
196
   { SGE_USER_LIST,         UU_name,   UU_Type,   "user",                    SGE_TYPE_USER,            userprj_mod,  userprj_spool,  userprj_success },
 
197
   { SGE_USERSET_LIST,      US_name,   US_Type,   "userset",                 SGE_TYPE_USERSET,         userset_mod,  userset_spool,  userset_success },
 
198
   { SGE_PROJECT_LIST,      PR_name,   PR_Type,   "project",                 SGE_TYPE_PROJECT,         userprj_mod,  userprj_spool,  userprj_success },
 
199
   { SGE_SHARETREE_LIST,    0,         NULL,      "sharetree",               SGE_TYPE_SHARETREE,       NULL,         NULL,           NULL },
 
200
   { SGE_CKPT_LIST,         CK_name,   CK_Type,   "checkpoint interface",    SGE_TYPE_CKPT,            ckpt_mod,     ckpt_spool,     ckpt_success },
 
201
   { SGE_JOB_SCHEDD_INFO_LIST,   0,    NULL,      "schedd info",             SGE_TYPE_JOB_SCHEDD_INFO, NULL,         NULL,           NULL },
 
202
   { SGE_ZOMBIE_LIST,       0,         NULL,      "job zombie list",         SGE_TYPE_ZOMBIE,          NULL,         NULL,           NULL },
 
203
   { SGE_RQS_LIST,          RQS_name,  RQS_Type,  "resource quota set",      SGE_TYPE_RQS,             rqs_mod,      rqs_spool,      rqs_success },
 
204
#ifndef __SGE_NO_USERMAPPING__
 
205
   { SGE_USER_MAPPING_LIST, CU_name,   CU_Type,   "user mapping entry",      SGE_TYPE_CUSER,           cuser_mod,    cuser_spool,    cuser_success },
 
206
#endif
 
207
   { SGE_HGROUP_LIST,       HGRP_name, HGRP_Type, "host group",              SGE_TYPE_HGROUP,          hgroup_mod,   hgroup_spool,   hgroup_success },
 
208
   { SGE_AR_LIST,           AR_id,     AR_Type,   "advance reservation",     SGE_TYPE_AR,              ar_mod,       ar_spool,       ar_success },
 
209
   { SGE_DUMMY_LIST,        0,         NULL,      "general request",         SGE_TYPE_NONE,            NULL,         NULL,           NULL },
 
210
   { 0,                     0,         NULL,      NULL,                      SGE_TYPE_NONE,            NULL,         NULL,           NULL }
 
211
};
 
212
/* *INDENT-ON* */
 
213
 
 
214
void sge_clean_lists(void) 
 
215
{
 
216
   int i = 0;
 
217
 
 
218
   for(;gdi_object[i].target != 0 ; i++) {
 
219
      if (gdi_object[i].list_type != SGE_TYPE_NONE) {
 
220
         lList **master_list = object_type_get_master_list(gdi_object[i].list_type); 
 
221
   /*          fprintf(stderr, "---> freeing list %s, it has %d elems\n", gdi_object[i].object_name, lGetNumberOfElem(*master_list)); */
 
222
         lFreeList(master_list);
 
223
      }   
 
224
   }
 
225
   
 
226
}
 
227
 
 
228
#if 1 
 
229
 
 
230
/* EB: TODO: CLEANUP: should be replaced with sge_gdi_packet_verify_version() */
 
231
 
 
232
/*
 
233
 * MT-NOTE: verify_request_version() is MT safe
 
234
 */
 
235
int verify_request_version(lList **alpp, u_long32 version, char *host, char *commproc, int id)
 
236
{
 
237
   char *client_version = NULL;
 
238
   dstring ds;
 
239
   char buffer[256];
 
240
   const vdict_t *vp, *vdict = GRM_GDI_VERSION_ARRAY;
 
241
 
 
242
   DENTER(TOP_LAYER, "verify_request_version");
 
243
 
 
244
   if (version == GRM_GDI_VERSION) {
 
245
      DRETURN(0);
 
246
   }
 
247
 
 
248
   for (vp = &vdict[0]; vp->version; vp++) {
 
249
      if (version == vp->version) {
 
250
         client_version = vp->release;
 
251
         break;
 
252
      }
 
253
   }
 
254
 
 
255
   sge_dstring_init(&ds, buffer, sizeof(buffer));
 
256
 
 
257
   if (client_version) {
 
258
      WARNING((SGE_EVENT, MSG_GDI_WRONG_GDI_SSISS,
 
259
         host, commproc, id, client_version, feature_get_product_name(FS_VERSION, &ds)));
 
260
   } else {
 
261
      WARNING((SGE_EVENT, MSG_GDI_WRONG_GDI_SSIUS,
 
262
         host, commproc, id, sge_u32c(version), feature_get_product_name(FS_VERSION, &ds)));
 
263
   }
 
264
   answer_list_add(alpp, SGE_EVENT, STATUS_EVERSION, ANSWER_QUALITY_ERROR);
 
265
 
 
266
   DRETURN(1);
 
267
}
 
268
#endif
 
269
 
 
270
/* ------------------------------------------------------------ */
 
271
void 
 
272
sge_c_gdi(sge_gdi_ctx_class_t *ctx, sge_gdi_packet_class_t *packet, 
 
273
          sge_gdi_task_class_t *task, lList **answer_list, monitoring_t *monitor) 
 
274
{
 
275
   const char *target_name = NULL;
 
276
   const char *operation_name = NULL;
 
277
   int sub_command = 0;
 
278
   gdi_object_t *ao;
 
279
   sge_pack_buffer *pb = &(packet->pb);
 
280
 
 
281
   DENTER(TOP_LAYER, "sge_c_gdi");
 
282
 
 
283
   ao = get_gdi_object(task->target);
 
284
   if (ao != NULL) {
 
285
      target_name = ao->object_name;
 
286
   }
 
287
   if (ao == NULL || target_name == NULL) {
 
288
      target_name = MSG_UNKNOWN_OBJECT;
 
289
   }
 
290
 
 
291
   sub_command = SGE_GDI_GET_SUBCOMMAND(task->command);
 
292
   task->command = SGE_GDI_GET_OPERATION(task->command);
 
293
   operation_name = sge_gdi_task_get_operation_name(task);
 
294
 
 
295
   DPRINTF(("GDI %s %s (%s/%s/%d) (%s/%d/%s/%d)\n", 
 
296
            operation_name, target_name, packet->host, packet->commproc, 
 
297
            (int)task->id, packet->user, (int)packet->uid, packet->group, (int)packet->gid));
 
298
 
 
299
   switch (task->command) {
 
300
      case SGE_GDI_GET:
 
301
         MONITOR_GDI_GET(monitor);
 
302
         sge_c_gdi_get(ao, packet, task, monitor);
 
303
         sge_gdi_packet_pack_task(packet, task, answer_list, pb);
 
304
         break;
 
305
      case SGE_GDI_ADD:
 
306
         MONITOR_GDI_ADD(monitor);
 
307
         sge_c_gdi_add(ctx, packet, task, ao, sub_command, monitor);
 
308
         sge_gdi_packet_pack_task(packet, task, answer_list, pb);
 
309
         break;
 
310
      case SGE_GDI_DEL:
 
311
         MONITOR_GDI_DEL(monitor);
 
312
         sge_c_gdi_del(ctx, packet, task, sub_command, monitor);
 
313
         sge_gdi_packet_pack_task(packet, task, answer_list, pb);
 
314
         break;
 
315
      case SGE_GDI_MOD:
 
316
         MONITOR_GDI_MOD(monitor);
 
317
         sge_c_gdi_mod(ctx, ao, packet, task, sub_command, monitor);
 
318
         sge_gdi_packet_pack_task(packet, task, answer_list, pb);
 
319
         break;
 
320
      case SGE_GDI_COPY:
 
321
         MONITOR_GDI_CP(monitor);
 
322
         sge_c_gdi_copy(ctx, ao, packet, task, sub_command, monitor);
 
323
         sge_gdi_packet_pack_task(packet, task, answer_list, pb);
 
324
         break;
 
325
      case SGE_GDI_TRIGGER:
 
326
         MONITOR_GDI_TRIG(monitor);
 
327
         sge_c_gdi_trigger(ctx, packet, task, monitor);
 
328
         sge_gdi_packet_pack_task(packet, task, answer_list, pb);
 
329
         break;
 
330
      case SGE_GDI_PERMCHECK:
 
331
         MONITOR_GDI_PERM(monitor);
 
332
         sge_c_gdi_permcheck(packet, task, monitor);
 
333
         sge_gdi_packet_pack_task(packet, task, answer_list, pb);
 
334
         break;
 
335
      case SGE_GDI_REPLACE:
 
336
         MONITOR_GDI_REPLACE(monitor);
 
337
         sge_c_gdi_replace(ctx, ao, packet, task, sub_command, monitor);
 
338
         sge_gdi_packet_pack_task(packet, task, answer_list, pb);
 
339
         break;
 
340
      default:
 
341
         SGE_ADD_MSG_ID(sprintf(SGE_EVENT, MSG_SGETEXT_UNKNOWNOP));
 
342
         answer_list_add(&(task->answer_list), SGE_EVENT, STATUS_ENOIMP, 
 
343
                         ANSWER_QUALITY_ERROR);
 
344
         sge_gdi_packet_pack_task(packet, task, answer_list, pb);
 
345
         break;
 
346
   }
 
347
 
 
348
   DRETURN_VOID;
 
349
}
 
350
 
 
351
static void 
 
352
sge_c_gdi_get(gdi_object_t *ao, sge_gdi_packet_class_t *packet, sge_gdi_task_class_t *task, monitoring_t *monitor)
 
353
{
 
354
   object_description *object_base = object_type_get_object_description();
 
355
 
 
356
   DENTER(TOP_LAYER, "sge_c_gdi_get");
 
357
 
 
358
   /* Whatever client sent with this get request - we don't need it */
 
359
   lFreeList(&(task->data_list));
 
360
 
 
361
   if (!sge_task_check_get_perm_host(packet, task, monitor, object_base)) {
 
362
      DEXIT;
 
363
      return;
 
364
   }
 
365
 
 
366
   switch (task->target) {
 
367
#ifdef QHOST_TEST
 
368
      case SGE_QHOST:
 
369
         sprintf(SGE_EVENT, "SGE_QHOST\n");
 
370
         answer_list_add(&(task->answer_list), SGE_EVENT, STATUS_OK, ANSWER_QUALITY_INFO);
 
371
         task->do_select_pack_simultaneous = false;
 
372
         DEXIT;
 
373
         return;
 
374
#endif
 
375
      case SGE_EVENT_LIST:
 
376
         task->data_list = sge_select_event_clients("", task->condition, task->enumeration);
 
377
         task->do_select_pack_simultaneous = false;
 
378
         sprintf(SGE_EVENT, MSG_GDI_OKNL);
 
379
         answer_list_add(&(task->answer_list), SGE_EVENT, STATUS_OK, ANSWER_QUALITY_END);
 
380
         DEXIT;
 
381
         return;
 
382
      case SGE_CONFIG_LIST: {
 
383
#if 0 /* EB: TODO PACKING */
 
384
         do_gdi_get_config_list(request, answer, before, after);
 
385
#else
 
386
         lList *conf = NULL;
 
387
 
 
388
         conf = sge_get_configuration();
 
389
 
 
390
         task->data_list = lSelectHashPack("", conf, task->condition, task->enumeration, false, NULL);
 
391
         task->do_select_pack_simultaneous = false;
 
392
         sprintf(SGE_EVENT, MSG_GDI_OKNL);
 
393
         answer_list_add(&(task->answer_list), SGE_EVENT, STATUS_OK, ANSWER_QUALITY_END);
 
394
         lFreeList(&conf);
 
395
      }
 
396
#endif
 
397
         DEXIT;
 
398
         return;
 
399
      case SGE_SC_LIST: /* TODO EB: move this into the scheduler configuration, 
 
400
                                    and pack the list right away */
 
401
      {
 
402
         lList *conf = NULL;
 
403
 
 
404
         conf = sconf_get_config_list();
 
405
         task->data_list = lSelectHashPack("", conf, task->condition, task->enumeration, false, NULL);
 
406
         task->do_select_pack_simultaneous = false;
 
407
         sprintf(SGE_EVENT, MSG_GDI_OKNL);
 
408
         answer_list_add(&(task->answer_list), SGE_EVENT, STATUS_OK, ANSWER_QUALITY_END);
 
409
         lFreeList(&conf);
 
410
      }
 
411
         DEXIT;
 
412
         return;
 
413
      default:
 
414
 
 
415
         /* 
 
416
          * Issue 1365
 
417
          * If the scheduler is not available the information in the job info
 
418
          * messages are outdated. In this case we have to reject the request.
 
419
          */
 
420
         if (task->target == SGE_JOB_SCHEDD_INFO_LIST &&
 
421
             !sge_has_event_client(EV_ID_SCHEDD) ) {
 
422
            answer_list_add(&(task->answer_list),MSG_SGETEXT_JOBINFOMESSAGESOUTDATED, 
 
423
                            STATUS_ESEMANTIC, ANSWER_QUALITY_ERROR);
 
424
         } else if (ao == NULL || ao->list_type == SGE_TYPE_NONE) {
 
425
            SGE_ADD_MSG_ID(sprintf(SGE_EVENT, MSG_SGETEXT_OPNOIMPFORTARGET));
 
426
            answer_list_add(&(task->answer_list), SGE_EVENT, STATUS_ENOIMP, ANSWER_QUALITY_ERROR);
 
427
         } else {
 
428
            lList *data_source = *object_type_get_master_list(ao->list_type);
 
429
 
 
430
            if (packet->is_intern_request) {
 
431
               /* intern requests need no pb so it is not necessary to postpone the operation */
 
432
               task->data_list = lSelectHashPack("", data_source, task->condition,
 
433
                                 task->enumeration, false, NULL);
 
434
               task->do_select_pack_simultaneous = false;
 
435
 
 
436
               /* 
 
437
                * DIRTY HACK: The "ok" message should be removed from the answer list
 
438
                * 05/21/2007 qualitiy was ANSWER_QUALITY_INFO but this results in "ok"
 
439
                * messages on qconf side 
 
440
                */
 
441
               sprintf(SGE_EVENT, MSG_GDI_OKNL);
 
442
               answer_list_add(&(task->answer_list), SGE_EVENT, STATUS_OK, ANSWER_QUALITY_END);
 
443
 
 
444
            } else {
 
445
               /* lSelect will be postponed till packing */
 
446
               task->data_list = data_source; 
 
447
               task->do_select_pack_simultaneous = true;
 
448
   
 
449
               /*
 
450
                * answer list creation is also done during packing!!!!
 
451
                */
 
452
            }
 
453
         }
 
454
 
 
455
   }
 
456
   DRETURN_VOID;
 
457
}
 
458
 
 
459
/*
 
460
 * MT-NOTE: sge_c_gdi_add() is MT safe
 
461
 */
 
462
static void 
 
463
sge_c_gdi_add(sge_gdi_ctx_class_t *ctx, sge_gdi_packet_class_t *packet, sge_gdi_task_class_t *task,
 
464
              gdi_object_t *ao, int sub_command, monitoring_t *monitor) 
 
465
{
 
466
   lListElem *ep;
 
467
   lList *ticket_orders = NULL;
 
468
   object_description *object_base = object_type_get_object_description();
 
469
 
 
470
   DENTER(TOP_LAYER, "sge_c_gdi_add");
 
471
 
 
472
   if (!packet->host || !packet->user || !packet->commproc) {
 
473
      CRITICAL((SGE_EVENT, MSG_SGETEXT_NULLPTRPASSED_S, SGE_FUNC));
 
474
      answer_list_add(&(task->answer_list), SGE_EVENT, STATUS_EUNKNOWN, ANSWER_QUALITY_ERROR);
 
475
      DEXIT;
 
476
      return;
 
477
   }
 
478
 
 
479
   /* check permissions of host and user */
 
480
   if ((!sge_chck_mod_perm_user(&(task->answer_list), task->target, packet->user, monitor)) &&
 
481
       (!sge_chck_mod_perm_host(&(task->answer_list), task->target, packet->host, 
 
482
                                packet->commproc, 0, NULL, monitor, object_base))) {
 
483
 
 
484
      if (task->target == SGE_EVENT_LIST) {
 
485
         lListElem *next;
 
486
 
 
487
         next = lFirst(task->data_list);
 
488
         while ((ep = next) != NULL) {/* is thread save. the global lock is used, when needed */
 
489
            next = lNext(ep);
 
490
   
 
491
            /* fill address infos from request into event client that must be added */
 
492
            lSetHost(ep, EV_host, packet->host);
 
493
            lSetString(ep, EV_commproc, packet->commproc);
 
494
            lSetUlong(ep, EV_commid, packet->commproc_id);
 
495
 
 
496
            /* fill in authentication infos from request */
 
497
            lSetUlong(ep, EV_uid, packet->uid);
 
498
            if (!event_client_verify(ep, &(task->answer_list), true)) {
 
499
               ERROR((SGE_EVENT, MSG_QMASTER_INVALIDEVENTCLIENT_SSS,
 
500
                      packet->user, packet->commproc, packet->host));
 
501
            } else {
 
502
               mconf_set_max_dynamic_event_clients(sge_set_max_dynamic_event_clients(mconf_get_max_dynamic_event_clients()));
 
503
               
 
504
               sge_add_event_client(ep, &(task->answer_list), 
 
505
                                    (sub_command & SGE_GDI_RETURN_NEW_VERSION) ? &(task->data_list) : NULL, 
 
506
                                    packet->user, packet->host, (event_client_update_func_t)NULL, monitor);
 
507
            }
 
508
         }
 
509
      } else if (task->target == SGE_JOB_LIST) {
 
510
         lListElem *next;
 
511
         
 
512
         next = lFirst(task->data_list);
 
513
         while ((ep = next) != NULL) { /* is thread save. the global lock is used, when needed */
 
514
            next = lNext(ep);
 
515
                                                   /* fill address infos from request into event client that must be added */
 
516
            if (!job_verify_submitted_job(ep, &(task->answer_list))) {
 
517
               ERROR((SGE_EVENT, MSG_QMASTER_INVALIDJOBSUBMISSION_SSS,
 
518
                      packet->user, packet->commproc, packet->host));
 
519
            } else {
 
520
               /* submit needs to know user and group */
 
521
               sge_gdi_add_job(ctx, 
 
522
                               ep, &(task->answer_list), 
 
523
                               (sub_command & SGE_GDI_RETURN_NEW_VERSION) ? 
 
524
                               &(task->data_list) : NULL, 
 
525
                               packet->user, packet->host, packet->uid, packet->gid, packet->group, 
 
526
                               packet, task, monitor);
 
527
            }
 
528
         }
 
529
      } else if (task->target == SGE_SC_LIST ) {
 
530
         lListElem *next;
 
531
 
 
532
         next = lFirst(task->data_list);
 
533
         while ((ep = next) != NULL) {
 
534
            next = lNext(ep);
 
535
 
 
536
            sge_mod_sched_configuration(ctx, ep, &(task->answer_list), packet->user, packet->host);
 
537
         }
 
538
      } else {
 
539
         bool is_scheduler_resync = false;
 
540
         lList *tmp_list = NULL;
 
541
         lListElem *next;         
 
542
 
 
543
         if (task->target == SGE_ORDER_LIST) {
 
544
             sge_set_commit_required(); 
 
545
         }
 
546
   
 
547
         next = lFirst(task->data_list);
 
548
         while ((ep = next) != NULL) {
 
549
            next = lNext(ep);
 
550
 
 
551
            /* add each element */
 
552
            switch (task->target) {
 
553
 
 
554
               case SGE_ORDER_LIST:
 
555
                 switch (sge_follow_order(ctx, ep, &(task->answer_list), packet->user, packet->host, 
 
556
                                          &ticket_orders, monitor, object_base)) {
 
557
                    case STATUS_OK :
 
558
                    case  0 : /* everything went fine */
 
559
                       break;
 
560
                    case -2 : is_scheduler_resync = true;
 
561
                    case -1 :
 
562
                    case -3 :
 
563
                              /* stop the order processing */
 
564
                              WARNING((SGE_EVENT, "Skipping remaining %d orders", lGetNumberOfRemainingElem(ep)));
 
565
                              next = NULL;
 
566
                       break;
 
567
                       
 
568
                    default :  DPRINTF(("--> FAILED: unexpected state from in the order processing <--\n"));
 
569
                       break;        
 
570
                  }
 
571
                  break;
 
572
               case SGE_MANAGER_LIST:
 
573
               case SGE_OPERATOR_LIST:
 
574
                  sge_add_manop(ctx, ep, &(task->answer_list), packet->user, packet->host, task->target);
 
575
                  break;
 
576
 
 
577
               case SGE_SHARETREE_LIST:
 
578
                  sge_add_sharetree(ctx, ep, object_base[SGE_TYPE_SHARETREE].list, &(task->answer_list), packet->user, packet->host);
 
579
                  break;
 
580
 
 
581
               default:
 
582
                  if (!ao) {
 
583
                     SGE_ADD_MSG_ID( sprintf(SGE_EVENT, MSG_SGETEXT_OPNOIMPFORTARGET));
 
584
                     answer_list_add(&(task->answer_list), SGE_EVENT, STATUS_ENOIMP, ANSWER_QUALITY_ERROR);
 
585
                     break;
 
586
                  } 
 
587
                  
 
588
                  if (task->target==SGE_EXECHOST_LIST && !strcmp(prognames[EXECD], packet->commproc)) {
 
589
                     bool is_restart;
 
590
 
 
591
                         /*
 
592
                                * Evaluate subcommand.
 
593
                                */
 
594
                     if (sub_command == SGE_GDI_EXECD_RESTART) {
 
595
                        is_restart = true;
 
596
                     } else {
 
597
                                    is_restart = false;
 
598
                               }
 
599
                     sge_execd_startedup(ctx, ep, &(task->answer_list), packet->user, 
 
600
                                         packet->host, task->target,
 
601
                                                             monitor, is_restart);
 
602
                  } else {
 
603
                     sge_gdi_add_mod_generic(ctx, &(task->answer_list), ep, 1, ao, packet->user, packet->host, sub_command, &tmp_list, monitor);
 
604
                  }
 
605
                  break;
 
606
            }
 
607
         } /* while loop */
 
608
 
 
609
         if (task->target == SGE_ORDER_LIST) {
 
610
            sge_commit();
 
611
            sge_set_next_spooling_time();
 
612
            answer_list_add(&(task->answer_list), "OK\n", STATUS_OK, ANSWER_QUALITY_INFO);
 
613
         }
 
614
 
 
615
         if (is_scheduler_resync) {
 
616
            sge_resync_schedd(monitor); /* ask for a total update */
 
617
         }
 
618
 
 
619
         /*
 
620
         ** tmp_list contains the changed AR element, set in ar_success
 
621
         */
 
622
         if (SGE_GDI_IS_SUBCOMMAND_SET(sub_command, SGE_GDI_RETURN_NEW_VERSION)) {
 
623
            lFreeList(&(task->data_list));
 
624
            task->data_list = tmp_list;
 
625
            tmp_list = NULL;
 
626
         }
 
627
 
 
628
         lFreeList(&tmp_list);
 
629
      }
 
630
   }
 
631
   
 
632
   if (ticket_orders != NULL) {
 
633
      if (mconf_get_reprioritize() == 1) {
 
634
         distribute_ticket_orders(ctx, ticket_orders, monitor, object_base);
 
635
      } else {
 
636
         /* tickets not needed at execd's if no repriorization is done */
 
637
         DPRINTF(("NO TICKET DELIVERY\n"));
 
638
      } 
 
639
 
 
640
      lFreeList(&ticket_orders);
 
641
   }
 
642
 
 
643
   DRETURN_VOID;
 
644
}
 
645
 
 
646
/*
 
647
 * MT-NOTE: sge_c_gdi-del() is MT safe
 
648
 */
 
649
void 
 
650
sge_c_gdi_del(sge_gdi_ctx_class_t *ctx,
 
651
              sge_gdi_packet_class_t *packet, sge_gdi_task_class_t *task, 
 
652
              int sub_command,  
 
653
              monitoring_t *monitor)
 
654
{
 
655
   lListElem *ep;
 
656
   object_description *object_base = object_type_get_object_description();
 
657
 
 
658
   DENTER(GDI_LAYER, "sge_c_gdi_del");
 
659
 
 
660
   if (sge_chck_mod_perm_user(&(task->answer_list), task->target, packet->user, monitor)) {
 
661
      DRETURN_VOID;
 
662
   }
 
663
   
 
664
   if (sge_chck_mod_perm_host(&(task->answer_list), task->target, packet->host, 
 
665
                              packet->commproc, 0, NULL, monitor, object_base)) {
 
666
      DRETURN_VOID;
 
667
   }
 
668
   
 
669
   if (task->data_list == NULL) { 
 
670
      /* delete whole list */
 
671
 
 
672
      switch (task->target)
 
673
      {
 
674
         case SGE_SHARETREE_LIST:
 
675
            sge_del_sharetree(ctx, object_base[SGE_TYPE_SHARETREE].list, &(task->answer_list), 
 
676
                              packet->user, packet->host);
 
677
            break;
 
678
         default:
 
679
            SGE_ADD_MSG_ID( sprintf(SGE_EVENT, MSG_SGETEXT_OPNOIMPFORTARGET));
 
680
            answer_list_add(&(task->answer_list), SGE_EVENT, STATUS_ENOIMP, ANSWER_QUALITY_ERROR);
 
681
            break;
 
682
      }
 
683
   } else {
 
684
      sge_set_commit_required();
 
685
 
 
686
      for_each (ep, task->data_list) {
 
687
         /* try to remove the element */
 
688
         switch (task->target)
 
689
         {
 
690
            case SGE_ADMINHOST_LIST:
 
691
            case SGE_SUBMITHOST_LIST:
 
692
            case SGE_EXECHOST_LIST:
 
693
               sge_del_host(ctx, ep, &(task->answer_list), packet->user, packet->host, task->target, *object_base[SGE_TYPE_HGROUP].list);
 
694
               break;
 
695
 
 
696
            case SGE_CQUEUE_LIST:
 
697
               cqueue_del(ctx, ep, &(task->answer_list), packet->user, packet->host);
 
698
               break;
 
699
 
 
700
            case SGE_JOB_LIST:
 
701
               sge_gdi_del_job(ctx, ep, &(task->answer_list), packet->user, packet->host, sub_command, monitor);
 
702
               break;
 
703
 
 
704
            case SGE_CENTRY_LIST:
 
705
               sge_del_centry(ctx, ep, &(task->answer_list), packet->user, packet->host);
 
706
               break;
 
707
 
 
708
            case SGE_PE_LIST:
 
709
               sge_del_pe(ctx, ep, &(task->answer_list), packet->user, packet->host); 
 
710
               break;
 
711
 
 
712
            case SGE_MANAGER_LIST:
 
713
            case SGE_OPERATOR_LIST:
 
714
               sge_del_manop(ctx, ep, &(task->answer_list), packet->user, packet->host, task->target);
 
715
               break;
 
716
 
 
717
            case SGE_CONFIG_LIST:
 
718
               sge_del_configuration(ctx, ep, &(task->answer_list), packet->user, packet->host);
 
719
               break;
 
720
 
 
721
            case SGE_USER_LIST:
 
722
               sge_del_userprj(ctx, ep, &(task->answer_list), object_base[SGE_TYPE_USER].list, packet->user, packet->host, 1);
 
723
               break;
 
724
 
 
725
            case SGE_USERSET_LIST:
 
726
               sge_del_userset(ctx, ep, &(task->answer_list), object_base[SGE_TYPE_USERSET].list, packet->user, packet->host);
 
727
               break;
 
728
 
 
729
            case SGE_PROJECT_LIST:
 
730
               sge_del_userprj(ctx, ep, &(task->answer_list), object_base[SGE_TYPE_PROJECT].list, packet->user, packet->host, 0);
 
731
               break;
 
732
 
 
733
            case SGE_RQS_LIST:
 
734
               rqs_del(ctx, ep, &(task->answer_list), object_base[SGE_TYPE_RQS].list, packet->user, packet->host);
 
735
               break;
 
736
 
 
737
            case SGE_CKPT_LIST:
 
738
               sge_del_ckpt(ctx, ep, &(task->answer_list), packet->user, packet->host); 
 
739
               break;
 
740
 
 
741
            case SGE_CALENDAR_LIST:
 
742
               sge_del_calendar(ctx, ep, &(task->answer_list), packet->user, packet->host);
 
743
               break;
 
744
#ifndef __SGE_NO_USERMAPPING__
 
745
            case SGE_USER_MAPPING_LIST:
 
746
               cuser_del(ctx, ep, &(task->answer_list), packet->user, packet->host);
 
747
               break;
 
748
#endif
 
749
            case SGE_HGROUP_LIST:
 
750
               hgroup_del(ctx, ep, &(task->answer_list), packet->user, packet->host);
 
751
               break;
 
752
            case SGE_AR_LIST:
 
753
               ar_del(ctx, ep, &(task->answer_list), object_base[SGE_TYPE_AR].list, packet->user, packet->host, monitor);
 
754
               break;
 
755
            default:
 
756
               SGE_ADD_MSG_ID( sprintf(SGE_EVENT, MSG_SGETEXT_OPNOIMPFORTARGET));
 
757
               answer_list_add(&(task->answer_list), SGE_EVENT, STATUS_ENOIMP, ANSWER_QUALITY_ERROR);
 
758
               break;
 
759
         } /* switch target */
 
760
           
 
761
      } /* for_each element */
 
762
 
 
763
      sge_commit();
 
764
   }
 
765
 
 
766
   DEXIT;
 
767
   return;
 
768
}
 
769
 
 
770
/* 
 
771
 * MT-NOTE: sge_c_gdi_copy() is MT safe
 
772
 */
 
773
static void sge_c_gdi_copy(sge_gdi_ctx_class_t *ctx, gdi_object_t *ao,                                      
 
774
                           sge_gdi_packet_class_t *packet, sge_gdi_task_class_t *task, int sub_command,
 
775
                           monitoring_t *monitor)
 
776
{
 
777
   lListElem *ep = NULL;
 
778
   object_description *object_base = object_type_get_object_description();
 
779
 
 
780
   DENTER(TOP_LAYER, "sge_c_gdi_copy");
 
781
 
 
782
   if (!packet->host || !packet->user || !packet->commproc) {
 
783
      CRITICAL((SGE_EVENT, MSG_SGETEXT_NULLPTRPASSED_S, SGE_FUNC));
 
784
      answer_list_add(&(task->answer_list), SGE_EVENT, STATUS_EUNKNOWN, ANSWER_QUALITY_ERROR);
 
785
      DEXIT;
 
786
      return;
 
787
   }
 
788
 
 
789
   if (sge_chck_mod_perm_user(&(task->answer_list), task->target, packet->user, monitor)) {
 
790
      DEXIT;
 
791
      return;
 
792
   }
 
793
 
 
794
   if (sge_chck_mod_perm_host(&(task->answer_list), task->target, packet->host, 
 
795
                              packet->commproc, 0, NULL, monitor, object_base)) {
 
796
      DEXIT;
 
797
      return;
 
798
   }
 
799
   
 
800
   for_each (ep, task->data_list) {
 
801
      switch (task->target)
 
802
      {
 
803
         case SGE_JOB_LIST:
 
804
            /* gdi_copy_job uses the global lock internal */
 
805
            sge_gdi_copy_job(ctx, ep, &(task->answer_list), 
 
806
                             (sub_command & SGE_GDI_RETURN_NEW_VERSION) ? &(task->answer_list) : NULL, 
 
807
                             packet->user, packet->host, packet->uid, packet->gid, packet->group, packet, task, monitor);
 
808
            break;
 
809
 
 
810
         default:
 
811
            SGE_ADD_MSG_ID( sprintf(SGE_EVENT, MSG_SGETEXT_OPNOIMPFORTARGET));
 
812
            answer_list_add(&(task->answer_list), SGE_EVENT, STATUS_ENOIMP, ANSWER_QUALITY_ERROR);
 
813
            break;
 
814
      }
 
815
   }
 
816
 
 
817
   DEXIT;
 
818
   return;
 
819
}
 
820
 
 
821
/* ------------------------------------------------------------ */
 
822
 
 
823
static void sge_gdi_do_permcheck(sge_gdi_packet_class_t *packet, sge_gdi_task_class_t *task)
 
824
 
825
   lList *lp = NULL;
 
826
   lListElem *ep = NULL;
 
827
 
 
828
   DENTER(GDI_LAYER, "sge_gdi_do_permcheck");
 
829
 
 
830
 
 
831
   DPRINTF(("User: %s\n", packet->user ));
 
832
 
 
833
   if (task->answer_list == NULL) { 
 
834
      const char *mapped_user = NULL;
 
835
      const char* requested_host = NULL;
 
836
      bool did_mapping = false;
 
837
 
 
838
      lUlong value;
 
839
      /* create PERM_Type list for answer structure*/
 
840
      lp = lCreateList("permissions", PERM_Type);
 
841
      ep = lCreateElem(PERM_Type);
 
842
      lAppendElem(lp,ep);
 
843
 
 
844
      /* set sge username */ 
 
845
      lSetString(ep, PERM_sge_username, packet->user);
 
846
 
 
847
      /* set requested host name */
 
848
      if (task->data_list == NULL) {
 
849
         requested_host = packet->host;
 
850
      } else {
 
851
         lList*     tmp_lp = NULL;
 
852
         lListElem* tmp_ep = NULL;
 
853
     
 
854
         tmp_lp = task->data_list;
 
855
         tmp_ep = tmp_lp->first;
 
856
         requested_host = lGetHost(tmp_ep, PERM_req_host);
 
857
#ifndef __SGE_NO_USERMAPPING__
 
858
         cuser_list_map_user(*(cuser_list_get_master_list()), NULL,
 
859
                             packet->user, requested_host, &mapped_user); 
 
860
         did_mapping = true;
 
861
#endif
 
862
      }
 
863
 
 
864
      if (requested_host != NULL) {
 
865
         lSetHost(ep, PERM_req_host, requested_host);  
 
866
      }   
 
867
 
 
868
      if (did_mapping && strcmp(mapped_user, packet->user)) {
 
869
         DPRINTF(("execution mapping: user %s mapped to %s on host %s\n",
 
870
                  packet->user, mapped_user, requested_host));
 
871
 
 
872
         lSetString(ep, PERM_req_username, mapped_user);
 
873
      } else { 
 
874
         lSetString(ep, PERM_req_username, "");
 
875
      }
 
876
    
 
877
 
 
878
      /* check for manager permission */
 
879
      value = 0;
 
880
      if (manop_is_manager(packet->user)) {
 
881
         value = 1; 
 
882
      }   
 
883
      lSetUlong(ep, PERM_manager, value);
 
884
 
 
885
      /* check for operator permission */
 
886
      value = 0;
 
887
      if (manop_is_operator(packet->user)) {
 
888
         value = 1; 
 
889
      }   
 
890
      lSetUlong(ep, PERM_operator, value);
 
891
      if ((task->condition != NULL) && (task->enumeration != NULL)) {
 
892
         task->data_list = lSelect("", lp, task->condition, task->enumeration);
 
893
         lFreeList(&lp); 
 
894
      } else {
 
895
         task->data_list = lp;
 
896
      }
 
897
   }
 
898
 
 
899
  sprintf(SGE_EVENT, MSG_GDI_OKNL);
 
900
  answer_list_add(&(task->answer_list), SGE_EVENT, STATUS_OK, ANSWER_QUALITY_END); 
 
901
  DEXIT;
 
902
  return;
 
903
}
 
904
 
 
905
/*
 
906
 * MT-NOTE: sge_c_gdi_permcheck() is MT safe
 
907
 */
 
908
static void 
 
909
sge_c_gdi_permcheck(sge_gdi_packet_class_t *packet, sge_gdi_task_class_t *task, 
 
910
                    monitoring_t *monitor)
 
911
{
 
912
   DENTER(GDI_LAYER, "sge_c_gdi_permcheck");
 
913
   switch (task->target) {
 
914
      case SGE_DUMMY_LIST:
 
915
         sge_gdi_do_permcheck(packet, task);
 
916
         break;
 
917
      default:
 
918
         WARNING((SGE_EVENT, MSG_SGETEXT_OPNOIMPFORTARGET));
 
919
         answer_list_add(&(task->answer_list), SGE_EVENT, STATUS_ENOIMP, ANSWER_QUALITY_ERROR); 
 
920
   }
 
921
   DRETURN_VOID;
 
922
}
 
923
 
 
924
void sge_c_gdi_replace(sge_gdi_ctx_class_t *ctx, gdi_object_t *ao, 
 
925
                       sge_gdi_packet_class_t *packet, sge_gdi_task_class_t *task,
 
926
                       int sub_command, monitoring_t *monitor)
 
927
{
 
928
   lList *tmp_list = NULL;
 
929
   lListElem *ep = NULL;
 
930
   object_description *object_base = object_type_get_object_description();
 
931
 
 
932
   DENTER(GDI_LAYER, "sge_c_gdi_replace");
 
933
 
 
934
   if (sge_chck_mod_perm_user(&(task->answer_list), task->target, packet->user, monitor)) {
 
935
      DRETURN_VOID;
 
936
   }
 
937
 
 
938
   if (sge_chck_mod_perm_host(&(task->answer_list), task->target, packet->host, 
 
939
                              packet->commproc, 0, NULL, monitor, object_base)) {
 
940
      DRETURN_VOID;
 
941
   }
 
942
 
 
943
   switch (task->target)
 
944
   {
 
945
      case SGE_RQS_LIST:
 
946
         {
 
947
            if (rqs_replace_request_verify(&(task->answer_list), task->data_list) != true) {
 
948
               DRETURN_VOID;
 
949
            }
 
950
            /* delete all currently defined rule sets */
 
951
            ep = lFirst(*object_base[SGE_TYPE_RQS].list);
 
952
            while (ep != NULL) {
 
953
               rqs_del(ctx, ep, &(task->answer_list), object_base[SGE_TYPE_RQS].list, packet->user, packet->host);
 
954
               ep = lFirst(*object_base[SGE_TYPE_RQS].list);
 
955
            }
 
956
 
 
957
            for_each(ep, task->data_list) {
 
958
               sge_gdi_add_mod_generic(ctx, &(task->answer_list), ep, 1, ao, packet->user, packet->host, SGE_GDI_SET_ALL, &tmp_list, monitor);
 
959
            }
 
960
            lFreeList(&tmp_list);
 
961
         }
 
962
         break;
 
963
      default:      
 
964
         SGE_ADD_MSG_ID(sprintf(SGE_EVENT, MSG_SGETEXT_OPNOIMPFORTARGET));
 
965
         answer_list_add(&(task->answer_list), SGE_EVENT, STATUS_ENOIMP, ANSWER_QUALITY_ERROR);
 
966
         break;
 
967
   }
 
968
   DRETURN_VOID;
 
969
}
 
970
 
 
971
/*
 
972
 * MT-NOTE: sge_c_gdi_trigger() is MT safe
 
973
 */
 
974
static void 
 
975
sge_c_gdi_trigger(sge_gdi_ctx_class_t *ctx, sge_gdi_packet_class_t *packet, 
 
976
                  sge_gdi_task_class_t *task, monitoring_t *monitor)
 
977
{
 
978
   u_long32 target = task->target;
 
979
   object_description *object_base = object_type_get_object_description();
 
980
   
 
981
   DENTER(GDI_LAYER, "sge_c_gdi_trigger");
 
982
 
 
983
   switch (target) {
 
984
      case SGE_EXECHOST_LIST: /* kill execd */
 
985
      case SGE_MASTER_EVENT:  /* kill master */
 
986
      case SGE_SC_LIST:       /* trigger scheduler monitoring */
 
987
            if (!host_list_locate(*object_base[SGE_TYPE_ADMINHOST].list, packet->host)) {
 
988
               ERROR((SGE_EVENT, MSG_SGETEXT_NOADMINHOST_S, packet->host));
 
989
               answer_list_add(&(task->answer_list), SGE_EVENT, STATUS_EDENIED2HOST, ANSWER_QUALITY_ERROR);
 
990
               SGE_UNLOCK(LOCK_GLOBAL, LOCK_WRITE);
 
991
               DEXIT;
 
992
               return;
 
993
            }
 
994
      
 
995
            if (SGE_EXECHOST_LIST == target) {
 
996
               sge_gdi_kill_exechost(ctx, packet, task);
 
997
            }
 
998
     
 
999
            if (SGE_SC_LIST == target) {
 
1000
               trigger_scheduler_monitoring(packet, task, monitor);
 
1001
            } else if (target == SGE_MASTER_EVENT) {
 
1002
               sge_gdi_kill_master(packet, task);
 
1003
            }
 
1004
         break;
 
1005
 
 
1006
       case SGE_CQUEUE_LIST:
 
1007
       case SGE_JOB_LIST:
 
1008
            sge_set_commit_required();
 
1009
            sge_gdi_qmod(ctx, packet, task, monitor);
 
1010
            sge_commit();
 
1011
         break; 
 
1012
 
 
1013
       case SGE_EVENT_LIST:
 
1014
            /* kill scheduler or event client */
 
1015
            sge_gdi_shutdown_event_client(ctx, packet, task, monitor, object_base);
 
1016
            answer_list_log(&(task->answer_list), false, true);
 
1017
         break;
 
1018
       case SGE_DUMMY_LIST:
 
1019
            sge_gdi_tigger_thread_state_transition(ctx, packet, task, monitor);
 
1020
            answer_list_log(&(task->answer_list), false, true);
 
1021
         break;
 
1022
       default:
 
1023
            /* permissions should be checked in the functions. Here we don't
 
1024
               know what is to do, so we don't know what permissions we need */
 
1025
            WARNING((SGE_EVENT, MSG_SGETEXT_OPNOIMPFORTARGET));
 
1026
            answer_list_add(&(task->answer_list), SGE_EVENT, STATUS_ENOIMP, ANSWER_QUALITY_ERROR);
 
1027
         break;
 
1028
   }
 
1029
 
 
1030
   DEXIT;
 
1031
   return;
 
1032
}
 
1033
 
 
1034
static void 
 
1035
sge_gdi_tigger_thread_state_transition(sge_gdi_ctx_class_t *ctx, 
 
1036
                                       sge_gdi_packet_class_t *packet, 
 
1037
                                       sge_gdi_task_class_t *task, 
 
1038
                                       monitoring_t *monitor)
 
1039
{
 
1040
   lListElem *elem = NULL; /* ID_Type */
 
1041
   lList **answer_list = &(task->answer_list);
 
1042
 
 
1043
   DENTER(TOP_LAYER, "sge_gdi_tigger_thread_state_transition");
 
1044
   for_each (elem, task->data_list) {
 
1045
      const char *name = lGetString(elem, ID_str);
 
1046
      sge_thread_state_transitions_t action = (sge_thread_state_transitions_t) lGetUlong(elem, ID_action);
 
1047
 
 
1048
      if (name != NULL) {
 
1049
         if (strcasecmp(name, threadnames[SCHEDD_THREAD]) == 0) {
 
1050
            if (action == SGE_THREAD_TRIGGER_START) {
 
1051
               sge_scheduler_initialize(ctx, answer_list);
 
1052
            } else if (action == SGE_THREAD_TRIGGER_STOP) {
 
1053
               sge_scheduler_terminate(ctx, answer_list);
 
1054
            } else {
 
1055
               ERROR((SGE_EVENT, MSG_TRIGGER_STATENOTSUPPORTED_DS, action, name));
 
1056
               answer_list_add(&(task->answer_list), SGE_EVENT, 
 
1057
                               STATUS_EEXIST, ANSWER_QUALITY_WARNING);
 
1058
            }
 
1059
#ifndef NO_JNI
 
1060
         } else if (strcasecmp(name, threadnames[JVM_THREAD]) == 0) {
 
1061
            if (action == SGE_THREAD_TRIGGER_START) {
 
1062
               sge_jvm_initialize(ctx, answer_list);
 
1063
            } else if (action == SGE_THREAD_TRIGGER_STOP) {
 
1064
               sge_jvm_terminate(ctx, answer_list);
 
1065
            } else {
 
1066
               ERROR((SGE_EVENT, MSG_TRIGGER_STATENOTSUPPORTED_DS, action, name));
 
1067
               answer_list_add(&(task->answer_list), SGE_EVENT, 
 
1068
                              STATUS_EEXIST, ANSWER_QUALITY_WARNING);
 
1069
            }
 
1070
#endif
 
1071
         } else {
 
1072
            ERROR((SGE_EVENT, MSG_TRIGGER_NOTSUPPORTED_S, name));
 
1073
            answer_list_add(&(task->answer_list), SGE_EVENT, 
 
1074
                            STATUS_EEXIST, ANSWER_QUALITY_WARNING);
 
1075
         }
 
1076
      } else {
 
1077
         ERROR((SGE_EVENT, MSG_TRIGGER_NOTSUPPORTED_S, ""));
 
1078
         answer_list_add(&(task->answer_list), SGE_EVENT, 
 
1079
                         STATUS_EEXIST, ANSWER_QUALITY_WARNING);
 
1080
      }
 
1081
   }
 
1082
   DRETURN_VOID;
 
1083
 
1084
 
 
1085
/****** qmaster/sge_c_gdi/sge_gdi_shutdown_event_client() **********************
 
1086
*  NAME
 
1087
*     sge_gdi_shutdown_event_client() -- shutdown event client 
 
1088
*
 
1089
*  SYNOPSIS
 
1090
*     static void
 
1091
*     sge_gdi_shutdown_event_client(sge_gdi_ctx_class_t *ctx, 
 
1092
*                                   sge_gdi_packet_class_t *packet, 
 
1093
*                                   sge_gdi_task_class_t *task, 
 
1094
*                                   monitoring_t *monitor, 
 
1095
*                                   object_description *object_base)
 
1096
*
 
1097
*  FUNCTION
 
1098
*     Shutdown event clients by client id. tasks data_list does contain a list of 
 
1099
*     client id's. This is a list of 'ID_Type' elements.
 
1100
*
 
1101
*  INPUTS
 
1102
*     sge_gdi_ctx_class_t *ctx - context
 
1103
*     sge_gdi_packet_class_t *packet - request packet 
 
1104
*     sge_gdi_task_class_t *task - request task 
 
1105
*     monitoring_t *monitor - the monitoring structure 
 
1106
*
 
1107
*  RESULT
 
1108
*     void - none 
 
1109
*
 
1110
*  NOTES
 
1111
*     MT-NOTE: sge_gdi_shutdown_event_client() is NOT MT safe. 
 
1112
*
 
1113
*******************************************************************************/
 
1114
static void 
 
1115
sge_gdi_shutdown_event_client(sge_gdi_ctx_class_t *ctx, sge_gdi_packet_class_t *packet, 
 
1116
                              sge_gdi_task_class_t *task, monitoring_t *monitor, 
 
1117
                              object_description *object_base)
 
1118
{
 
1119
   lListElem *elem = NULL; /* ID_Type */
 
1120
 
 
1121
   DENTER(TOP_LAYER, "sge_gdi_shutdown_event_client");
 
1122
 
 
1123
   for_each (elem, task->data_list) {
 
1124
      lList *local_alp = NULL;
 
1125
      int client_id = EV_ID_ANY;
 
1126
      int res = -1;
 
1127
 
 
1128
      if (get_client_id(elem, &client_id) != 0) {
 
1129
         answer_list_add(&(task->answer_list), SGE_EVENT, STATUS_EEXIST, ANSWER_QUALITY_ERROR);
 
1130
         continue;
 
1131
      }
 
1132
 
 
1133
      if (client_id == EV_ID_SCHEDD && 
 
1134
          !host_list_locate(*object_base[SGE_TYPE_ADMINHOST].list, packet->host)) {
 
1135
         ERROR((SGE_EVENT, MSG_SGETEXT_NOADMINHOST_S, packet->host));
 
1136
         answer_list_add(&(task->answer_list), SGE_EVENT, STATUS_EDENIED2HOST, ANSWER_QUALITY_ERROR);
 
1137
         continue;
 
1138
      } else if (!host_list_locate(*object_base[SGE_TYPE_SUBMITHOST].list, packet->host) 
 
1139
              && !host_list_locate(*object_base[SGE_TYPE_ADMINHOST].list, packet->host)) {
 
1140
         ERROR((SGE_EVENT, MSG_SGETEXT_NOSUBMITORADMINHOST_S, packet->host));
 
1141
         answer_list_add(&(task->answer_list), SGE_EVENT, STATUS_EDENIED2HOST, ANSWER_QUALITY_ERROR);
 
1142
         continue;
 
1143
      }
 
1144
 
 
1145
      /* thread shutdown */
 
1146
      if (client_id == EV_ID_SCHEDD) {
 
1147
         sge_scheduler_terminate(ctx, NULL);
 
1148
      }
 
1149
 
 
1150
      if (client_id == EV_ID_ANY) {
 
1151
         res = sge_shutdown_dynamic_event_clients(packet->user, &(local_alp), monitor);
 
1152
      } else {
 
1153
         res = sge_shutdown_event_client(client_id, packet->user, packet->uid, &(local_alp), monitor);
 
1154
      }
 
1155
     
 
1156
      if ((res == EINVAL) && (client_id == EV_ID_SCHEDD)) {
 
1157
         lFreeList(&local_alp); 
 
1158
         answer_list_add(&(task->answer_list), MSG_COM_NOSCHEDDREGMASTER, STATUS_EEXIST, ANSWER_QUALITY_WARNING);
 
1159
      }
 
1160
      else {
 
1161
         answer_list_append_list(&(task->answer_list), &local_alp);
 
1162
      }
 
1163
   }
 
1164
 
 
1165
   DEXIT;
 
1166
   return;
 
1167
} /* sge_gdi_shutdown_event_client() */
 
1168
 
 
1169
/****** qmaster/sge_c_gdi/get_client_id() **************************************
 
1170
*  NAME
 
1171
*     get_client_id() -- get client id from ID_Type element. 
 
1172
*
 
1173
*  SYNOPSIS
 
1174
*     static int get_client_id(lListElem *anElem, int *anID) 
 
1175
*
 
1176
*  FUNCTION
 
1177
*     Get client id from ID_Type element. The client id is converted to an
 
1178
*     integer and stored in 'anID'.
 
1179
*
 
1180
*  INPUTS
 
1181
*     lListElem *anElem - ID_Type element 
 
1182
*     int *anID         - will contain client id on return
 
1183
*
 
1184
*  RESULT
 
1185
*     EINVAL - failed to extract client id. 
 
1186
*     0      - otherwise
 
1187
*
 
1188
*  NOTES
 
1189
*     MT-NOTE: get_client_id() is MT safe. 
 
1190
*
 
1191
*     Using 'errno' to check for 'strtol' error situations is recommended
 
1192
*     by POSIX.
 
1193
*
 
1194
*******************************************************************************/
 
1195
static int get_client_id(lListElem *anElem, int *anID)
 
1196
{
 
1197
   const char *id = NULL;
 
1198
 
 
1199
   DENTER(TOP_LAYER, "get_client_id");
 
1200
 
 
1201
   if ((id = lGetString(anElem, ID_str)) == NULL)
 
1202
   {
 
1203
      DEXIT;
 
1204
      return EINVAL;
 
1205
   }
 
1206
 
 
1207
   errno = 0; /* errno is thread local */
 
1208
 
 
1209
   *anID = strtol(id, NULL, 0);
 
1210
 
 
1211
   if (errno != 0)
 
1212
   {
 
1213
      ERROR((SGE_EVENT, MSG_GDI_EVENTCLIENTIDFORMAT_S, id));
 
1214
      DEXIT;
 
1215
      return EINVAL;
 
1216
   }
 
1217
 
 
1218
   DEXIT;
 
1219
   return 0;
 
1220
} /* get_client_id() */
 
1221
 
 
1222
/****** qmaster/sge_c_gdi/trigger_scheduler_monitoring() ***********************
 
1223
*  NAME
 
1224
*     trigger_scheduler_monitoring() -- trigger scheduler monitoring 
 
1225
*
 
1226
*  SYNOPSIS
 
1227
*     static void 
 
1228
*     trigger_scheduler_monitoring(sge_gdi_packet_class_t *packet, sge_gdi_task_class_t *task,
 
1229
*                                  monitoring_t *monitor) 
 
1230
*
 
1231
*  FUNCTION
 
1232
*     Trigger scheduler monitoring.
 
1233
*
 
1234
*  INPUTS
 
1235
*     sge_gdi_packet_class_t *packet - request packet 
 
1236
*     sge_gdi_task_class_t *task - request task 
 
1237
*
 
1238
*  RESULT
 
1239
*     void - none
 
1240
*
 
1241
*  NOTES
 
1242
*     MT-NOTE: trigger_scheduler_monitoring() is MT safe, using global lock 
 
1243
*
 
1244
*  SEE ALSO
 
1245
*     qconf -tsm
 
1246
*
 
1247
*******************************************************************************/
 
1248
static void 
 
1249
trigger_scheduler_monitoring(sge_gdi_packet_class_t *packet, sge_gdi_task_class_t *task,
 
1250
                             monitoring_t *monitor) 
 
1251
{
 
1252
 
 
1253
   DENTER(GDI_LAYER, "trigger_scheduler_monitoring");
 
1254
 
 
1255
   if (!manop_is_manager(packet->user)) {
 
1256
      SGE_UNLOCK(LOCK_GLOBAL, LOCK_READ);
 
1257
      WARNING((SGE_EVENT, MSG_COM_NOSCHEDMONPERMS));
 
1258
      answer_list_add(&(task->answer_list), SGE_EVENT, STATUS_ENOMGR, ANSWER_QUALITY_WARNING);
 
1259
      DEXIT;
 
1260
      return;
 
1261
   }
 
1262
   if (!sge_add_event_for_client(EV_ID_SCHEDD, 0, sgeE_SCHEDDMONITOR, 0, 0, NULL, NULL, NULL, NULL)) {
 
1263
      WARNING((SGE_EVENT, MSG_COM_NOSCHEDDREGMASTER));
 
1264
      answer_list_add(&(task->answer_list), SGE_EVENT, STATUS_EEXIST, ANSWER_QUALITY_WARNING);
 
1265
      DEXIT;
 
1266
      return;
 
1267
   }
 
1268
 
 
1269
   INFO((SGE_EVENT, MSG_COM_SCHEDMON_SS, packet->user, packet->host));
 
1270
   answer_list_add(&(task->answer_list), SGE_EVENT, STATUS_OK, ANSWER_QUALITY_INFO);
 
1271
 
 
1272
   DEXIT;
 
1273
   return;
 
1274
} /* trigger_scheduler_monitoring() */
 
1275
 
 
1276
/*
 
1277
 * MT-NOTE: sge_c_gdi_mod() is MT safe
 
1278
 */
 
1279
void sge_c_gdi_mod(sge_gdi_ctx_class_t *ctx, gdi_object_t *ao,  
 
1280
                   sge_gdi_packet_class_t *packet, sge_gdi_task_class_t *task, int sub_command, 
 
1281
                   monitoring_t *monitor)
 
1282
{
 
1283
   lListElem *ep;
 
1284
   lList *tmp_list = NULL; 
 
1285
   bool is_locked = false;
 
1286
   object_description *object_base = object_type_get_object_description();
 
1287
      
 
1288
   DENTER(TOP_LAYER, "sge_c_gdi_mod");
 
1289
 
 
1290
   if (sge_chck_mod_perm_user(&(task->answer_list), task->target, packet->user, monitor)) {
 
1291
      DEXIT;
 
1292
      return;
 
1293
   }
 
1294
 
 
1295
   for_each (ep, task->data_list) {
 
1296
      if (sge_chck_mod_perm_host(&(task->answer_list), task->target, packet->host, 
 
1297
                                 packet->commproc, 1, ep, monitor, object_base)) {
 
1298
         continue;
 
1299
      }
 
1300
 
 
1301
      if (task->target == SGE_CONFIG_LIST) {
 
1302
         sge_mod_configuration(ctx, ep, &(task->answer_list), packet->user, packet->host);      
 
1303
      } else if (task->target == SGE_EVENT_LIST) {
 
1304
         /* fill address infos from request into event client that must be added */
 
1305
         lSetHost(ep, EV_host, packet->host);
 
1306
         lSetString(ep, EV_commproc, packet->commproc);
 
1307
         lSetUlong(ep, EV_commid, packet->id);
 
1308
 
 
1309
         /* fill in authentication infos from request */
 
1310
         lSetUlong(ep, EV_uid, packet->uid);
 
1311
         if (!event_client_verify(ep, &(task->answer_list), false)) {
 
1312
            ERROR((SGE_EVENT, MSG_QMASTER_INVALIDEVENTCLIENT_SSS,
 
1313
                   packet->user, packet->commproc, packet->host));
 
1314
         } else {
 
1315
            sge_mod_event_client(ep, &(task->answer_list), packet->user, packet->host);
 
1316
         }   
 
1317
      } else if (task->target == SGE_SC_LIST) {
 
1318
         sge_mod_sched_configuration(ctx, ep, &(task->answer_list), packet->user, packet->host);
 
1319
      } else {
 
1320
         if (!is_locked) {
 
1321
            sge_set_commit_required();
 
1322
            is_locked = true; 
 
1323
         }
 
1324
               
 
1325
         switch (task->target)
 
1326
         {
 
1327
            case SGE_JOB_LIST:
 
1328
               sge_gdi_mod_job(ctx, ep, &(task->answer_list), packet->user, packet->host, sub_command);
 
1329
               break;
 
1330
 
 
1331
            case SGE_SHARETREE_LIST:
 
1332
               sge_mod_sharetree(ctx, ep, object_base[SGE_TYPE_SHARETREE].list,
 
1333
                                 &(task->answer_list), packet->user, packet->host);
 
1334
               break;
 
1335
            default:
 
1336
               if (ao == NULL) {
 
1337
                  SGE_ADD_MSG_ID( sprintf(SGE_EVENT, MSG_SGETEXT_OPNOIMPFORTARGET));
 
1338
                  answer_list_add(&(task->answer_list), SGE_EVENT, STATUS_ENOIMP, ANSWER_QUALITY_ERROR);
 
1339
                  break;
 
1340
               }
 
1341
               sge_gdi_add_mod_generic(ctx, &(task->answer_list), ep, 0, ao, packet->user, packet->host, sub_command, &tmp_list, monitor);
 
1342
               break;
 
1343
         }
 
1344
      }
 
1345
   } /* for_each */
 
1346
 
 
1347
   if (is_locked) {
 
1348
      sge_commit();
 
1349
   }
 
1350
   
 
1351
   /* postprocessing for the list of requests */
 
1352
   if (lGetNumberOfElem(tmp_list) != 0) {
 
1353
      switch (task->target) {
 
1354
         case SGE_CENTRY_LIST:
 
1355
            DPRINTF(("rebuilding consumable debitation\n"));
 
1356
            centry_redebit_consumables(ctx, tmp_list);
 
1357
            break;
 
1358
      }
 
1359
   }
 
1360
 
 
1361
   lFreeList(&tmp_list);
 
1362
 
 
1363
   DEXIT;
 
1364
   return;
 
1365
}
 
1366
 
 
1367
/*
 
1368
 * MT-NOTE: sge_chck_mod_perm_user() is MT safe
 
1369
 */
 
1370
static int sge_chck_mod_perm_user(lList **alpp, u_long32 target, char *user, monitoring_t *monitor)
 
1371
{
 
1372
 
 
1373
   DENTER(TOP_LAYER, "sge_chck_mod_perm_user");
 
1374
 
 
1375
 
 
1376
   /* check permissions of user */
 
1377
   switch (target) {
 
1378
 
 
1379
   case SGE_ORDER_LIST:
 
1380
   case SGE_ADMINHOST_LIST:
 
1381
   case SGE_SUBMITHOST_LIST:
 
1382
   case SGE_EXECHOST_LIST:
 
1383
   case SGE_CQUEUE_LIST:
 
1384
   case SGE_CENTRY_LIST:
 
1385
   case SGE_OPERATOR_LIST:
 
1386
   case SGE_MANAGER_LIST:
 
1387
   case SGE_PE_LIST:
 
1388
   case SGE_CONFIG_LIST:
 
1389
   case SGE_SC_LIST:
 
1390
   case SGE_USER_LIST:
 
1391
   case SGE_PROJECT_LIST:
 
1392
   case SGE_SHARETREE_LIST:
 
1393
   case SGE_CKPT_LIST:
 
1394
   case SGE_CALENDAR_LIST:
 
1395
   case SGE_USER_MAPPING_LIST:
 
1396
   case SGE_HGROUP_LIST:
 
1397
   case SGE_RQS_LIST:
 
1398
      /* user must be a manager */
 
1399
      if (!manop_is_manager(user)) {
 
1400
         ERROR((SGE_EVENT, MSG_SGETEXT_MUSTBEMANAGER_S, user));
 
1401
         answer_list_add(alpp, SGE_EVENT, STATUS_ENOMGR, ANSWER_QUALITY_ERROR);
 
1402
         SGE_UNLOCK(LOCK_GLOBAL, LOCK_READ);
 
1403
         DEXIT;
 
1404
         return 1;
 
1405
      }
 
1406
      break;
 
1407
 
 
1408
   case SGE_USERSET_LIST:
 
1409
      /* user must be a operator */
 
1410
      if (!manop_is_operator(user)) {
 
1411
         ERROR((SGE_EVENT, MSG_SGETEXT_MUSTBEOPERATOR_S, user));
 
1412
         answer_list_add(alpp, SGE_EVENT, STATUS_ENOMGR, ANSWER_QUALITY_ERROR);
 
1413
         DEXIT;
 
1414
         return 1;
 
1415
      }
 
1416
      break;
 
1417
 
 
1418
   case SGE_JOB_LIST:
 
1419
 
 
1420
      /*
 
1421
         what checking could we do here ? 
 
1422
 
 
1423
         we had to check if there is a queue configured for scheduling
 
1424
         of jobs of this group/user. If there is no such queue we
 
1425
         had to deny submitting.
 
1426
 
 
1427
         Other checkings need to be done in stub functions.
 
1428
 
 
1429
      */
 
1430
      break;
 
1431
 
 
1432
   case SGE_EVENT_LIST:
 
1433
      /* 
 
1434
         an event client can be started by any user - it can only
 
1435
         read objects like SGE_GDI_GET
 
1436
         delete requires more info - is done in sge_gdi_kill_eventclient
 
1437
      */  
 
1438
      break;
 
1439
   case SGE_AR_LIST:
 
1440
      /* 
 
1441
         Advance reservation can be submitted by a manager or any user in the aruser access list.
 
1442
      */
 
1443
      if (!manop_is_manager(user) && !userset_is_ar_user(*userset_list_get_master_list(), user) ) {
 
1444
         ERROR((SGE_EVENT, MSG_SGETEXT_MUSTBEMANAGERORUSER_SS, user, AR_USERS));
 
1445
         answer_list_add(alpp, SGE_EVENT, STATUS_ENOMGR, ANSWER_QUALITY_ERROR);
 
1446
         DRETURN(1);
 
1447
      }
 
1448
      break;
 
1449
   default:
 
1450
      SGE_ADD_MSG_ID(sprintf(SGE_EVENT, MSG_SGETEXT_OPNOIMPFORTARGET));
 
1451
      answer_list_add(alpp, SGE_EVENT, STATUS_ENOIMP, ANSWER_QUALITY_ERROR);
 
1452
      DRETURN(1);
 
1453
   }
 
1454
 
 
1455
   DRETURN(0);
 
1456
}
 
1457
 
 
1458
 
 
1459
/*
 
1460
 * MT-NOTE: sge_chck_mod_perm_host() is MT safe
 
1461
 */
 
1462
static int sge_chck_mod_perm_host(lList **alpp, u_long32 target, char *host, 
 
1463
                                  char *commproc, int mod, lListElem *ep, 
 
1464
                                  monitoring_t *monitor, object_description *object_base)
 
1465
{
 
1466
   DENTER(TOP_LAYER, "sge_chck_mod_perm_host");
 
1467
 
 
1468
   /* check permissions of host */
 
1469
   switch (target) {
 
1470
 
 
1471
   case SGE_ORDER_LIST:
 
1472
   case SGE_ADMINHOST_LIST:
 
1473
   case SGE_OPERATOR_LIST:
 
1474
   case SGE_MANAGER_LIST:
 
1475
   case SGE_SUBMITHOST_LIST:
 
1476
   case SGE_CQUEUE_LIST:
 
1477
   case SGE_CENTRY_LIST:
 
1478
   case SGE_PE_LIST:
 
1479
   case SGE_CONFIG_LIST:
 
1480
   case SGE_SC_LIST:
 
1481
   case SGE_USER_LIST:
 
1482
   case SGE_USERSET_LIST:
 
1483
   case SGE_PROJECT_LIST:
 
1484
   case SGE_SHARETREE_LIST:
 
1485
   case SGE_CKPT_LIST:
 
1486
   case SGE_CALENDAR_LIST:
 
1487
   case SGE_USER_MAPPING_LIST:
 
1488
   case SGE_HGROUP_LIST:
 
1489
   case SGE_RQS_LIST:
 
1490
      
 
1491
      /* host must be SGE_ADMINHOST_LIST */
 
1492
      if (!host_list_locate(*object_base[SGE_TYPE_ADMINHOST].list, host)) {
 
1493
         ERROR((SGE_EVENT, MSG_SGETEXT_NOADMINHOST_S, host));
 
1494
         answer_list_add(alpp, SGE_EVENT, STATUS_EDENIED2HOST, ANSWER_QUALITY_ERROR);
 
1495
         DRETURN(1);
 
1496
      }
 
1497
      break;
 
1498
 
 
1499
   case SGE_EXECHOST_LIST:
 
1500
      
 
1501
      /* host must be either admin host or exec host and execd */
 
1502
 
 
1503
      if (!(host_list_locate(*object_base[SGE_TYPE_ADMINHOST].list, host) ||
 
1504
         (host_list_locate(*object_base[SGE_TYPE_EXECHOST].list, host) && !strcmp(commproc, prognames[EXECD])))) {
 
1505
         ERROR((SGE_EVENT, MSG_SGETEXT_NOADMINHOST_S, host));
 
1506
         answer_list_add(alpp, SGE_EVENT, STATUS_EDENIED2HOST, ANSWER_QUALITY_ERROR);
 
1507
         DRETURN(1);
 
1508
      }
 
1509
      break;
 
1510
 
 
1511
   case SGE_JOB_LIST:
 
1512
      /* 
 
1513
      ** check if override ticket change request, if yes we need
 
1514
      ** to be on an admin host and must not be on a submit host
 
1515
      */
 
1516
      if (mod && (lGetPosViaElem(ep, JB_override_tickets, SGE_NO_ABORT) >= 0)) {
 
1517
         /* host must be SGE_ADMINHOST_LIST */
 
1518
         if (!host_list_locate(*object_base[SGE_TYPE_ADMINHOST].list, host)) {
 
1519
            ERROR((SGE_EVENT, MSG_SGETEXT_NOADMINHOST_S, host));
 
1520
            answer_list_add(alpp, SGE_EVENT, STATUS_EDENIED2HOST, ANSWER_QUALITY_ERROR);
 
1521
            DRETURN(1);
 
1522
         }
 
1523
         break;
 
1524
      }    
 
1525
      /* host must be SGE_SUBMITHOST_LIST */
 
1526
      if (!host_list_locate(*object_base[SGE_TYPE_SUBMITHOST].list, host)) {
 
1527
         ERROR((SGE_EVENT, MSG_SGETEXT_NOSUBMITHOST_S, host));
 
1528
         answer_list_add(alpp, SGE_EVENT, STATUS_EDENIED2HOST, ANSWER_QUALITY_ERROR);
 
1529
         DRETURN(1);
 
1530
      }
 
1531
      break;
 
1532
 
 
1533
   case SGE_EVENT_LIST:
 
1534
      /* to start an event client or if an event client
 
1535
         performs modify requests on itself
 
1536
         it must be on a submit or an admin host 
 
1537
       */
 
1538
      if ( (!host_list_locate(*object_base[SGE_TYPE_SUBMITHOST].list, host)) 
 
1539
        && (!host_list_locate(*object_base[SGE_TYPE_ADMINHOST].list, host))) {
 
1540
        ERROR((SGE_EVENT, MSG_SGETEXT_NOSUBMITORADMINHOST_S, host));
 
1541
        answer_list_add(alpp, SGE_EVENT, STATUS_EDENIED2HOST, ANSWER_QUALITY_ERROR);
 
1542
        DRETURN(1);
 
1543
      }
 
1544
      break;
 
1545
   case SGE_AR_LIST:
 
1546
      /* host must be SGE_SUBMITHOST_LIST */
 
1547
      if (!host_list_locate(*object_base[SGE_TYPE_SUBMITHOST].list, host)) {
 
1548
         ERROR((SGE_EVENT, MSG_SGETEXT_NOSUBMITHOST_S, host));
 
1549
         answer_list_add(alpp, SGE_EVENT, STATUS_EDENIED2HOST, ANSWER_QUALITY_ERROR);
 
1550
         DRETURN(1);
 
1551
      }
 
1552
      break;
 
1553
   default:
 
1554
      SGE_ADD_MSG_ID(sprintf(SGE_EVENT, MSG_SGETEXT_OPNOIMPFORTARGET));
 
1555
      answer_list_add(alpp, SGE_EVENT, STATUS_ENOIMP, ANSWER_QUALITY_ERROR);
 
1556
      DRETURN(1);
 
1557
   }
 
1558
  
 
1559
   DRETURN(0);
 
1560
}
 
1561
 
 
1562
 
 
1563
/* EB: TODO: ST: skip execution of this function if it is internal GDI request */
 
1564
/* EB: TODO: ST: move usage of this code into listener in future */
 
1565
static bool 
 
1566
sge_task_check_get_perm_host(sge_gdi_packet_class_t *packet, sge_gdi_task_class_t *task, 
 
1567
                             monitoring_t *monitor, object_description *object_base)
 
1568
{
 
1569
   bool ret = true;
 
1570
   u_long32 target;
 
1571
   char *host = NULL;
 
1572
   
 
1573
   DENTER(TOP_LAYER, "sge_task_check_get_perm_host");
 
1574
 
 
1575
   target = task->target;
 
1576
   host = packet->host;
 
1577
 
 
1578
   /* check permissions of host */
 
1579
   switch (target) {
 
1580
   case SGE_ORDER_LIST:
 
1581
   case SGE_EVENT_LIST:
 
1582
   case SGE_ADMINHOST_LIST:
 
1583
   case SGE_OPERATOR_LIST:
 
1584
   case SGE_MANAGER_LIST:
 
1585
   case SGE_SUBMITHOST_LIST:
 
1586
   case SGE_CQUEUE_LIST:
 
1587
   case SGE_CENTRY_LIST:
 
1588
   case SGE_PE_LIST:
 
1589
   case SGE_SC_LIST:
 
1590
   case SGE_USER_LIST:
 
1591
   case SGE_USERSET_LIST:
 
1592
   case SGE_PROJECT_LIST:
 
1593
   case SGE_SHARETREE_LIST:
 
1594
   case SGE_CKPT_LIST:
 
1595
   case SGE_CALENDAR_LIST:
 
1596
   case SGE_USER_MAPPING_LIST:
 
1597
   case SGE_HGROUP_LIST:
 
1598
   case SGE_EXECHOST_LIST:
 
1599
   case SGE_JOB_LIST:
 
1600
   case SGE_ZOMBIE_LIST:
 
1601
   case SGE_JOB_SCHEDD_INFO_LIST:
 
1602
   case SGE_RQS_LIST:
 
1603
   case SGE_AR_LIST:
 
1604
      /* host must be admin or submit host */
 
1605
      if (!host_list_locate(*object_base[SGE_TYPE_ADMINHOST].list, host) &&
 
1606
          !host_list_locate(*object_base[SGE_TYPE_SUBMITHOST].list, host)) {
 
1607
         SGE_ADD_MSG_ID(sprintf(SGE_EVENT, MSG_SGETEXT_NOSUBMITORADMINHOST_S, host));
 
1608
         answer_list_add(&(task->answer_list), SGE_EVENT, STATUS_EDENIED2HOST, ANSWER_QUALITY_ERROR);
 
1609
         ret = false;
 
1610
      }
 
1611
      break;
 
1612
   case SGE_CONFIG_LIST:
 
1613
      /* host must be admin or submit host or exec host */
 
1614
      if (!host_list_locate(*object_base[SGE_TYPE_ADMINHOST].list, host) &&
 
1615
          !host_list_locate(*object_base[SGE_TYPE_SUBMITHOST].list, host) &&
 
1616
          !host_list_locate(*object_base[SGE_TYPE_EXECHOST].list, host)) {
 
1617
         SGE_ADD_MSG_ID(sprintf(SGE_EVENT, MSG_SGETEXT_NOSUBMITORADMINHOST_S, host));
 
1618
         answer_list_add(&(task->answer_list), SGE_EVENT, STATUS_EDENIED2HOST, ANSWER_QUALITY_ERROR);
 
1619
         ret = false;
 
1620
      }
 
1621
      break;
 
1622
   default:
 
1623
      SGE_ADD_MSG_ID(sprintf(SGE_EVENT, MSG_SGETEXT_OPNOIMPFORTARGET));
 
1624
      answer_list_add(&(task->answer_list), SGE_EVENT, STATUS_ENOIMP, ANSWER_QUALITY_ERROR);
 
1625
      ret = false;
 
1626
      return ret;
 
1627
   }
 
1628
 
 
1629
   DRETURN(ret);
 
1630
}
 
1631
 
 
1632
 
 
1633
/*
 
1634
   this is our strategy:
 
1635
 
 
1636
   do common checks and search old object
 
1637
   make a copy of the old object (this will become the new object)
 
1638
   modify new object using reduced object as instruction
 
1639
      on error: dispose new object
 
1640
   store new object to disc
 
1641
      on error: dispose new object
 
1642
   on success create events
 
1643
   replace old object by new queue
 
1644
*/
 
1645
int sge_gdi_add_mod_generic(
 
1646
sge_gdi_ctx_class_t *ctx,
 
1647
lList **alpp,
 
1648
lListElem *instructions, /* our instructions - a reduced object */
 
1649
int add,                 /* true in case of add */
 
1650
gdi_object_t *object, 
 
1651
const char *ruser,
 
1652
const char *rhost,
 
1653
int sub_command,
 
1654
lList **tmp_list,
 
1655
monitoring_t *monitor
 
1656
) {
 
1657
   int pos;
 
1658
   int dataType;
 
1659
   const char *name;
 
1660
   lList *tmp_alp = NULL;
 
1661
   lListElem *new_obj = NULL,
 
1662
             *old_obj;
 
1663
 
 
1664
   dstring buffer;
 
1665
   char ds_buffer[256];
 
1666
 
 
1667
   DENTER(TOP_LAYER, "sge_gdi_add_mod_generic");
 
1668
 
 
1669
   sge_dstring_init(&buffer, ds_buffer, sizeof(ds_buffer));
 
1670
 
 
1671
   /* DO COMMON CHECKS AND SEARCH OLD OBJECT */
 
1672
   if (!instructions || !object) {
 
1673
      CRITICAL((SGE_EVENT, MSG_SGETEXT_NULLPTRPASSED_S, SGE_FUNC));
 
1674
      answer_list_add(alpp, SGE_EVENT, STATUS_EUNKNOWN, ANSWER_QUALITY_ERROR);
 
1675
      DRETURN(STATUS_EUNKNOWN);
 
1676
   }
 
1677
 
 
1678
   /* ep is no element of this type, if ep doesn't contain the the primary key attribute */
 
1679
   if (lGetPosViaElem(instructions, object->key_nm, SGE_NO_ABORT) < 0)
 
1680
   {
 
1681
      CRITICAL((SGE_EVENT, MSG_SGETEXT_MISSINGCULLFIELD_SS, lNm2Str(object->key_nm), SGE_FUNC));
 
1682
      answer_list_add(alpp, SGE_EVENT, STATUS_EUNKNOWN, ANSWER_QUALITY_ERROR);
 
1683
      DRETURN(STATUS_EUNKNOWN);
 
1684
   }
 
1685
 
 
1686
   /* 
 
1687
    * resolve host name in case of objects with hostnames as key 
 
1688
    * before searching for the objects 
 
1689
    */
 
1690
   if ( object->key_nm == EH_name || 
 
1691
        object->key_nm == AH_name || 
 
1692
        object->key_nm == SH_name ) {
 
1693
      if (sge_resolve_host(instructions, object->key_nm) != CL_RETVAL_OK) {
 
1694
         const char *host = lGetHost(instructions, object->key_nm);    
 
1695
         ERROR((SGE_EVENT, MSG_SGETEXT_CANTRESOLVEHOST_S, host ? host : "NULL"));
 
1696
         answer_list_add(alpp, SGE_EVENT, STATUS_EUNKNOWN, ANSWER_QUALITY_ERROR);
 
1697
         DRETURN(STATUS_EUNKNOWN);
 
1698
      }
 
1699
   }
 
1700
 
 
1701
   /* get and verify the primary key */
 
1702
   pos = lGetPosViaElem(instructions,  object->key_nm, SGE_NO_ABORT);
 
1703
   dataType = lGetPosType(lGetElemDescr(instructions),pos);
 
1704
   if (dataType == lUlongT) {
 
1705
      u_long32 id = lGetUlong(instructions, object->key_nm);
 
1706
      sge_dstring_sprintf(&buffer, sge_u32, id);
 
1707
      name = sge_dstring_get_string(&buffer);
 
1708
 
 
1709
      old_obj = lGetElemUlong(*object_type_get_master_list(object->list_type), object->key_nm, id);
 
1710
   } else if (dataType == lHostT) {
 
1711
      name = lGetHost(instructions, object->key_nm); 
 
1712
      old_obj = lGetElemHost(*object_type_get_master_list(object->list_type), object->key_nm, name);
 
1713
      
 
1714
   } else {
 
1715
      name = lGetString(instructions, object->key_nm); 
 
1716
      old_obj = lGetElemStr(*object_type_get_master_list(object->list_type), object->key_nm, name);
 
1717
   }
 
1718
 
 
1719
   if (name == NULL) {
 
1720
      answer_list_add(alpp, MSG_OBJ_NAME_MISSING,
 
1721
                      STATUS_EEXIST, ANSWER_QUALITY_ERROR);
 
1722
      DRETURN(STATUS_EEXIST);
 
1723
   }
 
1724
 
 
1725
   /* prevent duplicates / modifying non existing objects */
 
1726
   if ((old_obj && add) ||
 
1727
      (!old_obj && !add)) {
 
1728
      ERROR((SGE_EVENT, add?
 
1729
            MSG_SGETEXT_ALREADYEXISTS_SS:MSG_SGETEXT_DOESNOTEXIST_SS, 
 
1730
            object->object_name, name));
 
1731
      answer_list_add(alpp, SGE_EVENT, STATUS_EEXIST, ANSWER_QUALITY_ERROR);
 
1732
      DRETURN(STATUS_EEXIST);
 
1733
   }
 
1734
 
 
1735
   /* create a new object (add case), or make a copy of the old object (mod case) */
 
1736
   if (!(new_obj = (add 
 
1737
         ? lCreateElem(object->type) 
 
1738
         : lCopyElem(old_obj)))) {
 
1739
      ERROR((SGE_EVENT, MSG_MEM_MALLOC));
 
1740
      answer_list_add(alpp, SGE_EVENT, STATUS_EEXIST, ANSWER_QUALITY_ERROR);
 
1741
      DRETURN(STATUS_EEXIST);
 
1742
   }
 
1743
 
 
1744
   /* modify the new object base on information in the request */
 
1745
   if (object->modifier(ctx, &tmp_alp, new_obj, instructions, add, ruser, rhost, 
 
1746
         object, sub_command, monitor) != 0) {
 
1747
      
 
1748
      if (alpp) {
 
1749
         /* ON ERROR: DISPOSE NEW OBJECT */
 
1750
         /* failure: just append last elem in tmp_alp
 
1751
            elements before may contain invalid success messages */
 
1752
         if (tmp_alp) {
 
1753
            if (!*alpp) {
 
1754
               *alpp = lCreateList("answer", AN_Type);
 
1755
            }
 
1756
 
 
1757
            if (object->type == AR_Type) {
 
1758
               lAppendList(*alpp, tmp_alp);
 
1759
               lFreeList(&tmp_alp);
 
1760
            } else {
 
1761
               lListElem *failure = lLast(tmp_alp);
 
1762
 
 
1763
               lDechainElem(tmp_alp, failure);
 
1764
               lAppendElem(*alpp, failure);
 
1765
               lFreeList(&tmp_alp);
 
1766
            }
 
1767
         }
 
1768
      }
 
1769
      lFreeElem(&new_obj);
 
1770
      DRETURN(STATUS_EUNKNOWN);
 
1771
   }  
 
1772
 
 
1773
 
 
1774
   /* write on file */
 
1775
   if (object->writer(ctx, alpp, new_obj, object)) {
 
1776
      lFreeElem(&new_obj);
 
1777
      lFreeList(&tmp_alp);
 
1778
      DRETURN(STATUS_EUNKNOWN);
 
1779
   }
 
1780
 
 
1781
   if (alpp != NULL) {
 
1782
      if (*alpp == NULL) {
 
1783
         *alpp = lCreateList("answer", AN_Type);
 
1784
      }
 
1785
   
 
1786
      /* copy tmp_alp to alpp */
 
1787
      lAppendList(*alpp, tmp_alp);
 
1788
   }
 
1789
   lFreeList(&tmp_alp);
 
1790
 
 
1791
   {
 
1792
      lList **master_list = NULL;
 
1793
 
 
1794
      master_list = object_type_get_master_list(object->list_type);
 
1795
         
 
1796
      /* chain out the old object */
 
1797
      if (old_obj) {
 
1798
         lDechainElem(*master_list, old_obj);
 
1799
      }
 
1800
 
 
1801
      /* ensure our global list exists */ 
 
1802
      if (*master_list == NULL ) {
 
1803
         *master_list = lCreateList(object->object_name, object->type);
 
1804
      }
 
1805
 
 
1806
      /* chain in new object */
 
1807
      lAppendElem(*master_list, new_obj);
 
1808
   }
 
1809
 
 
1810
   /* once we successfully added/modified the object, do final steps (on_success callback) */
 
1811
   if (object->on_success) {
 
1812
      object->on_success(ctx, new_obj, old_obj, object, tmp_list, monitor);
 
1813
   }
 
1814
 
 
1815
   lFreeElem(&old_obj);
 
1816
   
 
1817
   if (!SGE_GDI_IS_SUBCOMMAND_SET(sub_command, SGE_GDI_RETURN_NEW_VERSION)) {
 
1818
      INFO((SGE_EVENT, 
 
1819
         add?MSG_SGETEXT_ADDEDTOLIST_SSSS:
 
1820
             MSG_SGETEXT_MODIFIEDINLIST_SSSS, ruser, rhost, name, object->object_name));
 
1821
 
 
1822
      answer_list_add(alpp, SGE_EVENT, STATUS_OK, ANSWER_QUALITY_INFO);
 
1823
   }
 
1824
    
 
1825
   DRETURN(STATUS_OK);
 
1826
}
 
1827
 
 
1828
/*
 
1829
 * MT-NOTE: get_gdi_object() is MT safe
 
1830
 */
 
1831
gdi_object_t *get_gdi_object(u_long32 target)
 
1832
{
 
1833
   int i;
 
1834
 
 
1835
   DENTER(TOP_LAYER, "get_gdi_object");
 
1836
 
 
1837
   for (i=0; gdi_object[i].target; i++) {
 
1838
      if (target == gdi_object[i].target) {
 
1839
         DRETURN(&gdi_object[i]);
 
1840
      }
 
1841
   }
 
1842
 
 
1843
   DRETURN(NULL);
 
1844
}
 
1845
 
 
1846
static int schedd_mod(sge_gdi_ctx_class_t *ctx, lList **alpp, lListElem *modp,
 
1847
                      lListElem *ep, int add, const char *ruser,
 
1848
                      const char *rhost, gdi_object_t *object, int sub_command,
 
1849
                      monitoring_t *monitor) {
 
1850
   int ret;
 
1851
   DENTER(TOP_LAYER, "schedd_mod");
 
1852
 
 
1853
   ret = sconf_validate_config_(alpp) ? 0 : 1;
 
1854
   
 
1855
   DEXIT;
 
1856
   return ret;
 
1857
}
 
1858