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

« back to all changes in this revision

Viewing changes to source/security/gss/write_cred.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 <stdio.h>
 
34
#include <unistd.h>
 
35
#include <stdlib.h>
 
36
#include <string.h>
 
37
#include <ctype.h>
 
38
#include <sys/types.h>
 
39
#include <sys/socket.h>
 
40
#include <netinet/in.h>
 
41
#include <netdb.h>
 
42
#include <errno.h>
 
43
#include <sys/stat.h>
 
44
#include <sys/param.h>
 
45
#include <fcntl.h>
 
46
#include <pwd.h>
 
47
#ifdef KERBEROS
 
48
#include <gssapi/gssapi_generic.h>
 
49
#else
 
50
#include <gssapi.h>
 
51
#endif
 
52
#include "sge_gsslib.h"
 
53
#include "msg_gss.h"
 
54
/* #include "sge_language.h" */
 
55
 
 
56
void
 
57
usage(char *progname)
 
58
{
 
59
   char *p;
 
60
   p = (NULL == (p = strrchr(progname,'/'))) ? progname : p+1;
 
61
   fprintf(stderr, MSG_GSS_WRITECRED_USAGE_S , p);
 
62
   fprintf(stderr, "\n");
 
63
   exit(1);
 
64
}
 
65
 
 
66
 
 
67
int
 
68
main(int argc, char **argv)
 
69
{
 
70
   gss_buffer_desc client_cred;
 
71
   int cc=0;
 
72
   int fd=1;
 
73
   char lenbuf[GSSLIB_INTSIZE];
 
74
 
 
75
 
 
76
   if (argc > 1) {
 
77
      fd = SGE_OPEN3(argv[1], O_WRONLY|O_CREAT, 0700);
 
78
      if (fd < 0) {
 
79
         fprintf(stderr, MSG_GSS_COULDNOTOPENXY_SS , argv[1], strerror(errno));
 
80
    fprintf(stderr, "\n");
 
81
         exit(1);
 
82
      }
 
83
   }
 
84
     
 
85
 
 
86
   /*
 
87
    * read client credentials buffer from stdin
 
88
    */
 
89
 
 
90
   fprintf(stderr, "%s\n", MSG_GSS_READINGCREDENTIALLENGTH);
 
91
 
 
92
   if (read(0, lenbuf, sizeof(lenbuf)) != sizeof(lenbuf)) {
 
93
      fprintf(stderr, "%s\n", MSG_GSS_FAILEDREADINGCREDENTIALLENGTHFROMSTDIN);
 
94
      return 3;
 
95
   }
 
96
   client_cred.length = gsslib_unpackint(lenbuf);             
 
97
 
 
98
   fprintf(stderr, MSG_GSS_READLENGTHOFX_I, (int)client_cred.length);
 
99
   fprintf(stderr, "\n");
 
100
 
 
101
   if ((client_cred.value = (char *)malloc(client_cred.length)) == 0) {
 
102
      fprintf(stderr, MSG_GSS_COULDNOTALLOCATEXBYTESFORCREDENTIALS_I,
 
103
              (int)client_cred.length);
 
104
      fprintf(stderr, "\n");
 
105
      return 3;
 
106
   }
 
107
 
 
108
   if (read(0, client_cred.value, client_cred.length) != client_cred.length) {
 
109
      fprintf(stderr, "%s\n", MSG_GSS_FAILEDREADINGCREDENTIALLENGTHFROMSTDIN);
 
110
      return 3;
 
111
   }
 
112
 
 
113
   fprintf(stderr, MSG_GSS_READXBYTES_I, (int)client_cred.length);
 
114
   fprintf(stderr, "\n");
 
115
 
 
116
   /*
 
117
    * write credentials to stdout
 
118
    */                                                        
 
119
                                                              
 
120
   if (client_cred.length) {                                         
 
121
      gsslib_packint(client_cred.length, lenbuf);
 
122
      write(fd, lenbuf, sizeof(lenbuf));                      
 
123
      write(fd, client_cred.value, client_cred.length);                      
 
124
      fprintf(stderr, MSG_GSS_WROTEXBYTES_I , (int)client_cred.length);
 
125
      fprintf(stderr, "\n");
 
126
   } else {                                                   
 
127
      fprintf(stderr, MSG_GSS_WRITECREDNOCREDENTIALSFOUND);      
 
128
      fprintf(stderr, "\n");
 
129
      cc = 1;                                                 
 
130
   }                                                          
 
131
  
 
132
   return cc;
 
133
}
 
134