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

« back to all changes in this revision

Viewing changes to source/libs/sgeobj/sge_cuser.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 <stdlib.h>
 
34
 
 
35
#include "sge_string.h"
 
36
#include "sgermon.h"
 
37
#include "sge_log.h"
 
38
#include "cull_list.h"
 
39
#include "sge_answer.h"
 
40
#include "sge_str.h"
 
41
#include "sge_hostname.h"
 
42
#include "commlib.h"
 
43
#include "sge_hgroup.h"
 
44
#include "sge_href.h"
 
45
#include "sge_attr.h"
 
46
#include "sge_cuser.h"
 
47
#include "sge_object.h"
 
48
 
 
49
#include "msg_common.h"
 
50
#include "msg_sgeobjlib.h"
 
51
 
 
52
#define CUSER_LAYER TOP_LAYER
 
53
 
 
54
#ifndef __SGE_NO_USERMAPPING__
 
55
 
 
56
/* EB: ADOC: add comments */
 
57
 
 
58
lListElem *
 
59
cuser_create(lList **answer_list, const char *cluster_user, lList *remote_user)
 
60
{
 
61
   lListElem *ret = NULL;
 
62
 
 
63
   DENTER(CUSER_LAYER, "cuser_create");
 
64
   if (cluster_user != NULL) {
 
65
      ret = lCreateElem(CU_Type);
 
66
 
 
67
      if (ret != NULL) {
 
68
         lSetString(ret, CU_name, cluster_user);
 
69
         lSetList(ret, CU_ruser_list, remote_user);
 
70
      } else {
 
71
         SGE_ADD_MSG_ID(sprintf(SGE_EVENT, 
 
72
                                MSG_MEM_MEMORYALLOCFAILED_S, SGE_FUNC));
 
73
         answer_list_add(answer_list, SGE_EVENT,
 
74
                         STATUS_EMALLOC, ANSWER_QUALITY_ERROR);
 
75
      }
 
76
   }
 
77
   DEXIT;
 
78
   return ret;
 
79
}
 
80
 
 
81
/*
 
82
const char **remote_user   pointer to NULL pointer
 
83
                           don't free this pointer
 
84
*/
 
85
bool
 
86
cuser_get_remote_user(const lListElem *this_elem, lList **answer_list,
 
87
                      const char *hostname, const char **remote_user) 
 
88
{
 
89
   bool ret = true;
 
90
   
 
91
   DENTER(CUSER_LAYER, "cuser_get_remote_user");
 
92
 
 
93
   if (this_elem != NULL && hostname != NULL && remote_user != NULL) {
 
94
      lList *attr_list = NULL; 
 
95
   
 
96
      attr_list = lGetList(this_elem, CU_ruser_list);
 
97
      if (attr_list != NULL) {
 
98
         bool is_ambiguous = false;
 
99
         const char *matching_host_or_group = NULL;
 
100
         const char *matching_group = NULL;
 
101
 
 
102
         ret &= str_attr_list_find_value(attr_list, answer_list,
 
103
                                         hostname, remote_user, 
 
104
                                         &matching_host_or_group,
 
105
                                         &matching_group,
 
106
                                         &is_ambiguous); 
 
107
      } else {
 
108
         SGE_ADD_MSG_ID(sprintf(SGE_EVENT, 
 
109
                                MSG_CUSER_NOREMOTE_USER_S, "remote_user"));
 
110
         answer_list_add(answer_list, SGE_EVENT,
 
111
                         STATUS_ERROR1, ANSWER_QUALITY_ERROR);
 
112
         ret = false;
 
113
      }
 
114
   } else {
 
115
      SGE_ADD_MSG_ID(sprintf(SGE_EVENT, MSG_INAVLID_PARAMETER_IN_S, SGE_FUNC));
 
116
      answer_list_add(answer_list, SGE_EVENT,
 
117
                      STATUS_ERROR1, ANSWER_QUALITY_ERROR);
 
118
      ret = false;
 
119
   }  
 
120
   DEXIT;
 
121
   return ret;
 
122
}
 
123
 
 
124
bool
 
125
cuser_is_hgroup_referenced(const lListElem *this_elem,
 
126
                              const lListElem *hgroup)
 
127
{
 
128
   bool ret = false;
 
129
   
 
130
   DENTER(CUSER_LAYER, "cuser_is_hgroup_referenced");
 
131
   if (this_elem != NULL && hgroup != NULL) {
 
132
      const char *name = lGetHost(hgroup, HGRP_name);
 
133
      lList *attr_list = lGetList(this_elem, CU_ruser_list);
 
134
      lListElem *attr = str_attr_list_locate(attr_list, name);
 
135
 
 
136
      if (attr != NULL) {
 
137
         ret = true;
 
138
      }
 
139
   }
 
140
   DEXIT;
 
141
   return ret;
 
142
}
 
143
 
 
144
bool
 
145
cuser_list_find_hgroup_references(const lList *this_list,
 
146
                                     lList **answer_list,
 
147
                                     const lListElem *hgroup, 
 
148
                                     lList **string_list) 
 
149
{
 
150
   bool ret = true;
 
151
   lListElem *cuser;
 
152
 
 
153
   DENTER(CUSER_LAYER, "cuser_find_hgroup_references");
 
154
   if (this_list != NULL && hgroup != NULL && string_list != NULL) {
 
155
      for_each(cuser, this_list) {
 
156
         if (cuser_is_hgroup_referenced(cuser, hgroup)) {
 
157
            const char *name = lGetString(cuser, CU_name);
 
158
 
 
159
            lAddElemStr(string_list, ST_name, name, ST_Type);
 
160
         } 
 
161
      }
 
162
   }
 
163
   DEXIT;
 
164
   return ret;
 
165
}
 
166
 
 
167
lList **
 
168
cuser_list_get_master_list(void) 
 
169
{
 
170
    /* depending on the setting, we want to return the local thread setting and
 
171
       not the global master list. The object_type_get_master_list_mt knows, which
 
172
       one to get */
 
173
    return object_type_get_master_list(SGE_TYPE_CUSER);
 
174
}
 
175
 
 
176
lListElem *
 
177
cuser_list_locate(const lList *this_list, const char *cluster_user)
 
178
{
 
179
   lListElem *ret = NULL;
 
180
 
 
181
   DENTER(CUSER_LAYER, "cuser_list_locate");
 
182
   if (this_list != NULL && cluster_user != NULL) {
 
183
      ret = lGetElemStr(this_list, CU_name, cluster_user);
 
184
   }
 
185
   DEXIT;
 
186
   return ret;
 
187
}
 
188
 
 
189
bool
 
190
cuser_list_map_user(const lList *this_list, lList **answer_list,
 
191
                    const char *cluster_user, const char *hostname, 
 
192
                    const char **remote_user)
 
193
{
 
194
   bool ret = true;
 
195
 
 
196
   DENTER(CUSER_LAYER, "cuser_list_map_user");
 
197
   if (cluster_user != NULL && hostname != NULL && remote_user != NULL) {
 
198
      lListElem *cuser = cuser_list_locate(this_list, cluster_user); 
 
199
 
 
200
      if (cuser != NULL) {
 
201
         ret &= cuser_get_remote_user(cuser, answer_list, 
 
202
                                      hostname, remote_user); 
 
203
      } else {
 
204
         /* No user mapping entry defined for this object */
 
205
         *remote_user = cluster_user;
 
206
      }
 
207
   } else {
 
208
      SGE_ADD_MSG_ID(sprintf(SGE_EVENT, MSG_INAVLID_PARAMETER_IN_S, SGE_FUNC));
 
209
      answer_list_add(answer_list, SGE_EVENT,
 
210
                      STATUS_ERROR1, ANSWER_QUALITY_ERROR);
 
211
      ret = false;
 
212
   } 
 
213
   DEXIT;
 
214
   return ret;
 
215
}
 
216
 
 
217
#endif