OpenCores
URL https://opencores.org/ocsvn/openrisc/openrisc/trunk

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [rtos/] [rtems/] [c/] [src/] [librpc/] [src/] [rpc/] [netname.c] - Blame information for rev 583

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 30 unneback
/*
2
 * Sun RPC is a product of Sun Microsystems, Inc. and is provided for
3
 * unrestricted use provided that this legend is included on all tape
4
 * media and as a part of the software program in whole or part.  Users
5
 * may copy or modify Sun RPC without charge, but are not authorized
6
 * to license or distribute it to anyone else except as part of a product or
7
 * program developed by the user or with the express written consent of
8
 * Sun Microsystems, Inc.
9
 *
10
 * SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE
11
 * WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR
12
 * PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE.
13
 *
14
 * Sun RPC is provided with no support and without any obligation on the
15
 * part of Sun Microsystems, Inc. to assist in its use, correction,
16
 * modification or enhancement.
17
 *
18
 * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE
19
 * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC
20
 * OR ANY PART THEREOF.
21
 *
22
 * In no event will Sun Microsystems, Inc. be liable for any lost revenue
23
 * or profits or other special, indirect and consequential damages, even if
24
 * Sun has been advised of the possibility of such damages.
25
 *
26
 * Sun Microsystems, Inc.
27
 * 2550 Garcia Avenue
28
 * Mountain View, California  94043
29
 */
30
#if !defined(lint) && defined(SCCSIDS)
31
static char sccsid[] = "@(#)netname.c 1.8 91/03/11 Copyr 1986 Sun Micro";
32
#endif
33
 
34
/*
35
 * netname utility routines
36
 * convert from unix names to network names and vice-versa
37
 * This module is operating system dependent!
38
 * What we define here will work with any unix system that has adopted
39
 * the sun NIS domain architecture.
40
 */
41
 
42
#include <sys/param.h>
43
#include <rpc/rpc.h>
44
#include <rpc/rpc_com.h>
45
#ifdef YP
46
#include <rpcsvc/yp_prot.h>
47
#include <rpcsvc/ypclnt.h>
48
#endif
49
#include <ctype.h>
50
#include <stdlib.h>
51
#include <unistd.h>
52
#include <string.h>
53
#include <stdio.h>
54
 
55
#ifndef MAXHOSTNAMELEN
56
#define MAXHOSTNAMELEN 256
57
#endif
58
#ifndef NGROUPS
59
#define NGROUPS 16
60
#endif
61
 
62
static char *OPSYS = "unix";
63
 
64
/*
65
 * Figure out my fully qualified network name
66
 */
67
int
68
getnetname(name)
69
        char name[MAXNETNAMELEN+1];
70
{
71
        uid_t uid;
72
 
73
        uid = geteuid();
74
        if (uid == 0) {
75
                return (host2netname(name, (char *) NULL, (char *) NULL));
76
        } else {
77
                return (user2netname(name, uid, (char *) NULL));
78
        }
79
}
80
 
81
 
82
/*
83
 * Convert unix cred to network-name
84
 */
85
int
86
user2netname(netname, uid, domain)
87
        char netname[MAXNETNAMELEN + 1];
88
        uid_t uid;
89
        char *domain;
90
{
91
        char *dfltdom;
92
 
93
#define MAXIPRINT       (11)    /* max length of printed integer */
94
 
95
        if (domain == NULL) {
96
                if (_rpc_get_default_domain(&dfltdom) != 0) {
97
                        return (0);
98
                }
99
                domain = dfltdom;
100
        }
101
        if (strlen(domain) + 1 + MAXIPRINT > MAXNETNAMELEN) {
102
                return (0);
103
        }
104
        (void) sprintf(netname, "%s.%ld@%s", OPSYS, (u_long)uid, domain);
105
        return (1);
106
}
107
 
108
 
109
/*
110
 * Convert host to network-name
111
 */
112
int
113
host2netname(netname, host, domain)
114
        char netname[MAXNETNAMELEN + 1];
115
        char *host;
116
        char *domain;
117
{
118
        char *dfltdom;
119
        char hostname[MAXHOSTNAMELEN+1];
120
 
121
        if (domain == NULL) {
122
                if (_rpc_get_default_domain(&dfltdom) != 0) {
123
                        return (0);
124
                }
125
                domain = dfltdom;
126
        }
127
        if (host == NULL) {
128
                (void) gethostname(hostname, sizeof(hostname));
129
                host = hostname;
130
        }
131
        if (strlen(domain) + 1 + strlen(host) > MAXNETNAMELEN) {
132
                return (0);
133
        }
134
        (void) sprintf(netname, "%s.%s@%s", OPSYS, host, domain);
135
        return (1);
136
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.