1/*$Header: /p/tcsh/cvsroot/tcsh/win32/bogus.c,v 1.9 2008/10/11 12:47:39 christos Exp $*/
2/*-
3 * Copyright (c) 1980, 1991 The Regents of the University of California.
4 * All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:
9 * 1. Redistributions of source code must retain the above copyright
10 *    notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 *    notice, this list of conditions and the following disclaimer in the
13 *    documentation and/or other materials provided with the distribution.
14 * 3. Neither the name of the University nor the names of its contributors
15 *    may be used to endorse or promote products derived from this software
16 *    without specific prior written permission.
17 *
18 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
19 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21 * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
22 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
24 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
26 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
27 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
28 * SUCH DAMAGE.
29 */
30
31/*
32 * bogus.c: various routines that are really silly
33 * -amol
34 *
35 */
36#include "ntport.h"
37#include "sh.h"
38
39static struct passwd pass_bogus;
40static char username[20];
41static char homedir[MAX_PATH + 1];/*FIXBUF*/
42static char *this_shell="tcsh";
43
44static char dummy[2]={0,0};
45
46gid_t getuid(void) {
47	return 0;
48}
49gid_t getgid(void) {
50	return 0;
51}
52gid_t geteuid(void) {
53	return 0;
54}
55gid_t getegid(void) {
56	return 0;
57}
58#undef free
59struct passwd * getpwnam(const char *name) {
60
61	char *ptr;
62	DWORD size =20;
63	size_t esize = 0;
64
65	if (pass_bogus.pw_name == NULL) {
66		GetUserName(username,&size);
67		if (_dupenv_s(&ptr,&esize,"HOME") == 0){
68			StringCbCopy(homedir,sizeof(homedir),ptr);
69			pass_bogus.pw_dir = &homedir[0];
70			free(ptr);
71		}
72		pass_bogus.pw_name = &username[0];
73		pass_bogus.pw_shell = this_shell;
74
75
76		pass_bogus.pw_passwd= &dummy[0];
77		pass_bogus.pw_gecos=&dummy[0];
78		pass_bogus.pw_passwd= &dummy[0];
79
80	}
81	if (_stricmp(username,name) )
82		return NULL;
83	return &pass_bogus;
84}
85struct passwd * getpwuid(uid_t myuid) {
86
87	char *ptr;
88	DWORD size =20;
89	size_t esize = 0;
90
91	UNREFERENCED_PARAMETER(myuid);
92	if (pass_bogus.pw_name == NULL) {
93		GetUserName(username,&size);
94		if (_dupenv_s(&ptr,&esize,"HOME") == 0){
95			StringCbCopy(homedir,sizeof(homedir),ptr);
96			pass_bogus.pw_dir = &homedir[0];
97			free(ptr);
98		}
99		pass_bogus.pw_name = &username[0];
100		pass_bogus.pw_shell = this_shell;
101
102
103		pass_bogus.pw_passwd= &dummy[0];
104		pass_bogus.pw_gecos=&dummy[0];
105		pass_bogus.pw_passwd= &dummy[0];
106
107	}
108	return &pass_bogus;
109}
110struct group * getgrnam(char *name) {
111	UNREFERENCED_PARAMETER(name);
112	return NULL;
113}
114struct group * getgrgid(gid_t mygid) {
115	UNREFERENCED_PARAMETER(mygid);
116	return NULL;
117}
118char * ttyname(int fd) {
119
120	if (isatty(fd)) return "/dev/tty";
121	return NULL;
122}
123int times(struct tms * ignore) {
124	FILETIME c,e,kernel,user;
125
126	ignore->tms_utime=0;
127	ignore->tms_stime=0;
128	ignore->tms_cutime=0;
129	ignore->tms_cstime=0;
130	if (!GetProcessTimes(GetCurrentProcess(),
131				&c,
132				&e,
133				&kernel,
134				&user) )
135		return -1;
136
137	if (kernel.dwHighDateTime){
138		return GetTickCount();
139	}
140	//
141	// Units of 10ms. I *think* this is right. -amol 6/2/97
142	ignore->tms_stime = kernel.dwLowDateTime / 1000 /100;
143	ignore->tms_utime = user.dwLowDateTime / 1000 /100;
144
145	return GetTickCount();
146}
147int tty_getty(int fd, void*ignore) {
148	UNREFERENCED_PARAMETER(fd);
149	UNREFERENCED_PARAMETER(ignore);
150	return 0;
151}
152int tty_setty(int fd, void*ignore) {
153	UNREFERENCED_PARAMETER(fd);
154	UNREFERENCED_PARAMETER(ignore);
155	return 0;
156}
157int tty_geteightbit(void *ignore) {
158	UNREFERENCED_PARAMETER(ignore);
159	return 1;
160}
161	void
162dosetty(Char **v, struct command *t)
163{
164	UNREFERENCED_PARAMETER(v);
165	UNREFERENCED_PARAMETER(t);
166	xprintf("setty not supported in NT\n");
167}
168
169