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

« back to all changes in this revision

Viewing changes to source/daemons/qmaster/sge_manop_qmaster.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
#include <stdio.h>
 
33
#include <string.h>
 
34
 
 
35
#include "commlib.h"
 
36
#include "cull.h"
 
37
#include "sgermon.h"
 
38
#include "sge_manop_qmaster.h"
 
39
#include "sge_event_master.h"
 
40
#include "sge_log.h"
 
41
#include "sge_uidgid.h"
 
42
#include "sge_answer.h"
 
43
#include "sge_manop.h"
 
44
 
 
45
#include "sge_persistence_qmaster.h"
 
46
#include "spool/sge_spooling.h"
 
47
 
 
48
#include "msg_common.h"
 
49
#include "msg_qmaster.h"
 
50
 
 
51
/* ------------------------------------------------------------
 
52
 
 
53
   sge_add_manop() - adds an manop list to the global manager/operator
 
54
                     list
 
55
 
 
56
   if the invoking process is the qmaster 
 
57
   the added manop list is spooled in the MANAGER_FILE/OPERATOR_FILE
 
58
 
 
59
*/
 
60
int sge_add_manop(
 
61
sge_gdi_ctx_class_t *ctx,
 
62
lListElem *ep,
 
63
lList **alpp,
 
64
char *ruser,
 
65
char *rhost,
 
66
u_long32 target  /* may be SGE_MANAGER_LIST or SGE_OPERATOR_LIST */
 
67
) {
 
68
   const char *manop_name;
 
69
   const char *object_name;
 
70
   lList **lpp = NULL;
 
71
   lListElem *added;
 
72
   int pos;
 
73
   int key;
 
74
   lDescr *descr = NULL;
 
75
   ev_event eve = sgeE_EVENTSIZE; 
 
76
 
 
77
   DENTER(TOP_LAYER, "sge_add_manop");
 
78
 
 
79
   if ( !ep || !ruser || !rhost ) {
 
80
      CRITICAL((SGE_EVENT, MSG_SGETEXT_NULLPTRPASSED_S, SGE_FUNC));
 
81
      answer_list_add(alpp, SGE_EVENT, STATUS_EUNKNOWN, ANSWER_QUALITY_ERROR);
 
82
      DEXIT;
 
83
      return STATUS_EUNKNOWN;
 
84
   }
 
85
 
 
86
   switch (target) {
 
87
   case SGE_MANAGER_LIST:
 
88
      lpp = object_type_get_master_list(SGE_TYPE_MANAGER);
 
89
      object_name = MSG_OBJ_MANAGER;
 
90
      key = UM_name;
 
91
      descr = UM_Type;
 
92
      eve = sgeE_MANAGER_ADD;
 
93
      break;
 
94
   case SGE_OPERATOR_LIST:
 
95
      lpp = object_type_get_master_list(SGE_TYPE_OPERATOR);
 
96
      object_name = MSG_OBJ_OPERATOR;
 
97
      key = UO_name;
 
98
      descr = UO_Type;
 
99
      eve = sgeE_OPERATOR_ADD;
 
100
      break;
 
101
   default :
 
102
      DPRINTF(("unknown target passed to %s\n", SGE_FUNC));
 
103
      DEXIT;
 
104
      return STATUS_EUNKNOWN;
 
105
   }
 
106
 
 
107
   /* ep is no acl element, if ep has no UM_name/UO_name */
 
108
   if ((pos = lGetPosViaElem(ep, key, SGE_NO_ABORT)) < 0) {
 
109
      CRITICAL((SGE_EVENT, MSG_SGETEXT_MISSINGCULLFIELD_SS,
 
110
            lNm2Str(key), SGE_FUNC));
 
111
      answer_list_add(alpp, SGE_EVENT, STATUS_EUNKNOWN, ANSWER_QUALITY_ERROR);
 
112
      DEXIT;
 
113
      return STATUS_EUNKNOWN;
 
114
   }
 
115
 
 
116
   manop_name = lGetPosString(ep, pos);
 
117
   if (!manop_name) {
 
118
      CRITICAL((SGE_EVENT, MSG_SGETEXT_NULLPTRPASSED_S, SGE_FUNC));
 
119
      answer_list_add(alpp, SGE_EVENT, STATUS_EUNKNOWN, ANSWER_QUALITY_ERROR);
 
120
      DEXIT;
 
121
      return STATUS_EUNKNOWN;
 
122
   }
 
123
 
 
124
   if (lGetElemStr(*lpp, key, manop_name)) {
 
125
      ERROR((SGE_EVENT, MSG_SGETEXT_ALREADYEXISTS_SS, object_name, manop_name));
 
126
      answer_list_add(alpp, SGE_EVENT, STATUS_EEXIST, ANSWER_QUALITY_ERROR);
 
127
      DEXIT;
 
128
      return STATUS_EEXIST;
 
129
   }
 
130
 
 
131
   /* update in interal lists */
 
132
   added = lAddElemStr(lpp, key, manop_name, descr);
 
133
 
 
134
   /* update on file */
 
135
   if(!sge_event_spool(ctx, alpp, 0, eve, 
 
136
                       0, 0, manop_name, NULL, NULL,
 
137
                       added, NULL, NULL, true, true)) {
 
138
      ERROR((SGE_EVENT, MSG_CANTSPOOL_SS, object_name, manop_name));
 
139
      answer_list_add(alpp, SGE_EVENT, STATUS_EDISK, ANSWER_QUALITY_ERROR);
 
140
   
 
141
      /* remove element from list */
 
142
      lRemoveElem(*lpp, &added);
 
143
 
 
144
      DEXIT;
 
145
      return STATUS_EDISK;
 
146
   }
 
147
 
 
148
   INFO((SGE_EVENT, MSG_SGETEXT_ADDEDTOLIST_SSSS,
 
149
            ruser, rhost, manop_name, object_name));
 
150
   answer_list_add(alpp, SGE_EVENT, STATUS_OK, ANSWER_QUALITY_INFO);
 
151
   DEXIT;
 
152
   return STATUS_OK;
 
153
}
 
154
 
 
155
/* ------------------------------------------------------------
 
156
 
 
157
   sge_del_manop() - deletes an access list from the global acl_list
 
158
 
 
159
*/
 
160
int sge_del_manop(
 
161
sge_gdi_ctx_class_t *ctx,
 
162
lListElem *ep,
 
163
lList **alpp,
 
164
char *ruser,
 
165
char *rhost,
 
166
u_long32 target  /* may be SGE_MANAGER_LIST or SGE_OPERATOR_LIST */
 
167
) {
 
168
   lListElem *found;
 
169
   int pos;
 
170
   const char *manop_name;
 
171
   const char *object_name;
 
172
   lList **lpp = NULL;
 
173
   int key = NoName;
 
174
   ev_event eve = sgeE_EVENTSIZE; 
 
175
 
 
176
 
 
177
   DENTER(TOP_LAYER, "sge_del_manop");
 
178
 
 
179
   if ( !ep || !ruser || !rhost ) {
 
180
      CRITICAL((SGE_EVENT, MSG_SGETEXT_NULLPTRPASSED_S, SGE_FUNC));
 
181
      answer_list_add(alpp, SGE_EVENT, STATUS_EUNKNOWN, ANSWER_QUALITY_ERROR);
 
182
      DEXIT;
 
183
      return STATUS_EUNKNOWN;
 
184
   }
 
185
 
 
186
   switch (target) {
 
187
   case SGE_MANAGER_LIST:
 
188
      lpp = object_type_get_master_list(SGE_TYPE_MANAGER);
 
189
      object_name = MSG_OBJ_MANAGER;
 
190
      key = UM_name;
 
191
      eve = sgeE_MANAGER_DEL;
 
192
      break;
 
193
   case SGE_OPERATOR_LIST:
 
194
      lpp = object_type_get_master_list(SGE_TYPE_OPERATOR);
 
195
      object_name = MSG_OBJ_OPERATOR;
 
196
      key = UO_name;
 
197
      eve = sgeE_OPERATOR_DEL;
 
198
      break;
 
199
   default :
 
200
      DPRINTF(("unknown target passed to %s\n", SGE_FUNC));
 
201
      DEXIT;
 
202
      return STATUS_EUNKNOWN;
 
203
   }
 
204
 
 
205
   /* ep is no manop element, if ep has no UM_name/UO_name */
 
206
   if ((pos = lGetPosViaElem(ep, key, SGE_NO_ABORT)) < 0) {
 
207
      CRITICAL((SGE_EVENT, MSG_SGETEXT_MISSINGCULLFIELD_SS,
 
208
            lNm2Str(key), SGE_FUNC));
 
209
      answer_list_add(alpp, SGE_EVENT, STATUS_EUNKNOWN, ANSWER_QUALITY_ERROR);
 
210
      DEXIT;
 
211
      return STATUS_EUNKNOWN;
 
212
   }
 
213
 
 
214
   manop_name = lGetPosString(ep, pos);
 
215
   if (!manop_name) {
 
216
      CRITICAL((SGE_EVENT, MSG_SGETEXT_NULLPTRPASSED_S, SGE_FUNC));
 
217
      answer_list_add(alpp, SGE_EVENT, STATUS_EUNKNOWN, ANSWER_QUALITY_ERROR);
 
218
      DEXIT;
 
219
      return STATUS_EUNKNOWN;
 
220
   }
 
221
 
 
222
   /* prevent removing of root from man/op-list */
 
223
   if (!strcmp(manop_name, "root")) {
 
224
      ERROR((SGE_EVENT, MSG_SGETEXT_MAY_NOT_REMOVE_USER_FROM_LIST_SS, "root", object_name));  
 
225
      answer_list_add(alpp, SGE_EVENT, STATUS_EEXIST, ANSWER_QUALITY_ERROR);
 
226
      DEXIT;
 
227
      return STATUS_EEXIST;
 
228
   }
 
229
 
 
230
   found = lGetElemStr(*lpp, key, manop_name);
 
231
   if (!found) {
 
232
      ERROR((SGE_EVENT, MSG_SGETEXT_DOESNOTEXIST_SS, object_name, manop_name));
 
233
      answer_list_add(alpp, SGE_EVENT, STATUS_EEXIST, ANSWER_QUALITY_ERROR);
 
234
      DEXIT;
 
235
      return STATUS_EEXIST;
 
236
   }
 
237
   
 
238
   lDechainElem(*lpp, found);
 
239
 
 
240
   /* update on file */
 
241
   if (!sge_event_spool(ctx, alpp, 0, eve,
 
242
                        0, 0, manop_name, NULL, NULL,
 
243
                        NULL, NULL, NULL, true, true)) {
 
244
      ERROR((SGE_EVENT, MSG_CANTSPOOL_SS, object_name, manop_name));
 
245
      answer_list_add(alpp, SGE_EVENT, STATUS_EDISK, ANSWER_QUALITY_ERROR);
 
246
   
 
247
      /* chain in again */
 
248
      lAppendElem(*lpp, found);
 
249
 
 
250
      DEXIT;
 
251
      return STATUS_EDISK;
 
252
   }
 
253
   lFreeElem(&found);
 
254
 
 
255
   INFO((SGE_EVENT, MSG_SGETEXT_REMOVEDFROMLIST_SSSS,
 
256
            ruser, rhost, manop_name, object_name));
 
257
   answer_list_add(alpp, SGE_EVENT, STATUS_OK, ANSWER_QUALITY_INFO);
 
258
   DEXIT;
 
259
   return STATUS_OK;
 
260
}
 
261