~kirkland/eucalyptus/label-metadata

« back to all changes in this revision

Viewing changes to util/pwcb.c

  • Committer: graziano obertelli
  • Date: 2009-01-07 03:32:35 UTC
  • Revision ID: graziano@cs.ucsb.edu-20090107033235-oxhuexp18v8hg0pw
Tags: 1.4
from CVS

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Licensed to the Apache Software Foundation (ASF) under one or more
 
3
 * contributor license agreements.  See the NOTICE file distributed with
 
4
 * this work for additional information regarding copyright ownership.
 
5
 * The ASF licenses this file to You under the Apache License, Version 2.0
 
6
 * (the "License"); you may not use this file except in compliance with
 
7
 * the License.  You may obtain a copy of the License at
 
8
 *
 
9
 *      http://www.apache.org/licenses/LICENSE-2.0
 
10
 *
 
11
 * Unless required by applicable law or agreed to in writing, software
 
12
 * distributed under the License is distributed on an "AS IS" BASIS,
 
13
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 
14
 * See the License for the specific language governing permissions and
 
15
 * limitations under the License.
 
16
 */
 
17
 
 
18
#include <stdio.h>
 
19
#include <stdlib.h>
 
20
 
 
21
 
 
22
#include <axis2_defines.h>
 
23
#include <axutil_error.h>
 
24
#include <axutil_env.h>
 
25
#include <axutil_utils.h>
 
26
#include <rampart_callback.h>
 
27
#include <axutil_string.h>
 
28
#include <axis2_svc_skeleton.h>
 
29
#include <axutil_string.h>
 
30
 
 
31
axis2_status_t AXIS2_CALL
 
32
my_free_function(rampart_callback_t *rcb,
 
33
        const axutil_env_t *env)
 
34
{
 
35
        AXIS2_FREE(env->allocator, rcb->ops);
 
36
        AXIS2_FREE(env->allocator, rcb);
 
37
    return AXIS2_SUCCESS;
 
38
}
 
39
 
 
40
axis2_char_t* AXIS2_CALL get_sample_password(rampart_callback_t *rcb, const axutil_env_t *env,  const axis2_char_t *username, void *param) {
 
41
  /*First set pf password are for sample usernames*/
 
42
  axis2_char_t * pw = NULL;
 
43
  char pwFile[1024];
 
44
  char pass[1024];
 
45
  char *euca_home;
 
46
  FILE *FH;
 
47
 
 
48
  euca_home = getenv("EUCALYPTUS");
 
49
  if (!euca_home) {
 
50
    snprintf(pwFile, 1024, "/var/eucalyptus/keys/pw");
 
51
  } else {
 
52
    snprintf(pwFile, 1024, "%s/var/eucalyptus/keys/pw", euca_home);
 
53
  }
 
54
 
 
55
  if (0 == axutil_strcmp(username, "CLUSTER") || 0 == axutil_strcmp(username, "CLOUD") || 0 == axutil_strcmp(username, "eucalyptus")) {
 
56
    FH = fopen(pwFile, "r");
 
57
    if (FH) {
 
58
      if (fgets(pass, 1024, FH)) {
 
59
        pw = malloc(sizeof(axis2_char_t) * strlen(pass) + 32);
 
60
        strcpy(pw, pass);
 
61
      }
 
62
      fclose(FH);
 
63
    }
 
64
  } else {
 
65
    
 
66
  }
 
67
  return pw;
 
68
};
 
69
 
 
70
 
 
71
/**
 
72
 * Following block distinguish the exposed part of the dll.
 
73
 */
 
74
AXIS2_EXPORT int
 
75
axis2_get_instance(rampart_callback_t **inst,
 
76
        const axutil_env_t *env)
 
77
{
 
78
    rampart_callback_t* rcb = NULL;
 
79
 
 
80
    rcb = AXIS2_MALLOC(env->allocator,
 
81
            sizeof(rampart_callback_t));
 
82
 
 
83
    rcb->ops = AXIS2_MALLOC(
 
84
                env->allocator, sizeof(rampart_callback_ops_t));
 
85
 
 
86
    /*assign function pointers*/
 
87
 
 
88
    rcb->ops->callback_password = get_sample_password;
 
89
    rcb->ops->free = my_free_function;
 
90
 
 
91
    *inst = rcb;
 
92
 
 
93
    if (!(*inst))
 
94
    {
 
95
        AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "[rampart][pwcb_sample] Cannot initialize the PWCB module");
 
96
        return AXIS2_FAILURE;
 
97
    }
 
98
 
 
99
    return AXIS2_SUCCESS;
 
100
}
 
101
 
 
102
AXIS2_EXPORT int
 
103
axis2_remove_instance(rampart_callback_t *inst,
 
104
        const axutil_env_t *env)
 
105
{
 
106
    axis2_status_t status = AXIS2_FAILURE;
 
107
    if (inst)
 
108
    {
 
109
        status = my_free_function(inst, env);
 
110
    }
 
111
    return status;
 
112
}
 
113