~ubuntu-branches/ubuntu/warty/dnprogs/warty

« back to all changes in this revision

Viewing changes to dnetd/task_server.c

  • Committer: Bazaar Package Importer
  • Author(s): Patrick Caulfield
  • Date: 2004-05-30 10:13:57 UTC
  • Revision ID: james.westby@ubuntu.com-20040530101357-1geqhhh0teccu0cm
Tags: 2.27
* Fix signal handling in sethost so it doesn't die with an embarrassing
  "Alarm clock" message.
* Add dependancy on modutils. Closes: #251508

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/******************************************************************************
2
 
    (c) 1999 P.J. Caulfield               patrick@tykepenguin.cix.co.uk
3
 
    
 
2
    (c) 1999-2002 P.J. Caulfield               patrick@tykepenguin.cix.co.uk
 
3
 
4
4
    This program is free software; you can redistribute it and/or modify
5
5
    it under the terms of the GNU General Public License as published by
6
6
    the Free Software Foundation; either version 2 of the License, or
70
70
        close(newsock);
71
71
        return; // Don't do object numbers !
72
72
    }
73
 
    
 
73
 
74
74
// Convert the name to lower case
75
75
    for (i=0; i<strlen(name); i++)
76
76
    {
77
77
        if (isupper(name[i])) name[i] = tolower(name[i]);
78
78
    }
79
79
 
80
 
    
 
80
 
81
81
    if (verbosity) DNETLOG((LOG_INFO, "got connection for %s\n", name));
82
 
    
 
82
 
 
83
    // Reject anything starting / or containing .. as
 
84
    // a security problem
 
85
    if (name[0] == '/' ||
 
86
        strstr(name, ".."))
 
87
    {
 
88
        DNETLOG((LOG_WARNING, "Rejecting %s as a security risk", name));
 
89
        dnet_reject(newsock, DNSTAT_OBJECT, NULL, 0);
 
90
        return;
 
91
    }
 
92
 
 
93
 
83
94
    // Look for the file.
84
95
    //
85
96
    // a) in the home directory (if not secure)
146
157
        exit(-1);
147
158
    }
148
159
#else
149
 
    
 
160
 
150
161
    for (c='p'; c <= 'z'; c++)
151
162
    {
152
163
        line = ptyname;
153
164
        line[strlen("/dev/pty")] = c;
154
165
        line[strlen("/dev/ptyC")] = '0';
155
166
        if (stat(line,&stb) < 0)
156
 
            break; 
 
167
            break;
157
168
        for (i=0; i < 16; i++)
158
169
        {
159
170
            line[strlen("/dev/ptyC")]= "0123456789abcdef"[i];
160
 
            if ( (pty=open(line,O_RDWR)) > 0)   
 
171
            if ( (pty=open(line,O_RDWR)) > 0)
161
172
            {
162
173
                gotpty = 1;
163
174
                break;
166
177
        if (gotpty) break;
167
178
    }
168
179
 
169
 
    if (!gotpty) 
 
180
    if (!gotpty)
170
181
    {
171
182
        DNETLOG((LOG_ERR, "No ptys available for connection"));
172
183
        return;
173
184
    }
174
 
    
 
185
 
175
186
 
176
187
    line[strlen("/dev/")] = 't';
177
 
    if ( (t=open(line,O_RDWR)) < 0) 
 
188
    if ( (t=open(line,O_RDWR)) < 0)
178
189
    {
179
190
        DNETLOG((LOG_ERR, "Error connecting to physical terminal: %m"));
180
191
        return;
181
192
    }
182
193
#endif
183
 
    
 
194
 
184
195
    if ( ( pid=fork() ) < 0)
185
196
    {
186
197
        DNETLOG((LOG_ERR, "Error forking"));
187
198
        return;
188
199
    }
189
 
    
 
200
 
190
201
    if (pid)  // Parent
191
202
    {
192
203
        close(t); // close slave
195
206
        copy(pty, newsock, pid);
196
207
        return ;
197
208
    }
198
 
    
 
209
 
199
210
    setsid();
200
 
    
 
211
 
201
212
    close(pty); close(newsock);
202
213
    if (t != 0) dup2 (t,0);
203
214
    if (t != 1) dup2 (t,1);
204
215
    if (t != 2) dup2 (t,2);
205
 
    
 
216
 
206
217
    if (t > 2) close(t);
207
 
    
 
218
 
208
219
    putenv("TERM=vt100");
209
220
    execve(name, argv, env);
210
221
    DNETLOG((LOG_ERR, "Error executing command"));
218
229
    int status, pid;
219
230
 
220
231
    // Make sure we reap all children
221
 
    do 
222
 
    { 
223
 
        pid = waitpid(-1, &status, WNOHANG); 
 
232
    do
 
233
    {
 
234
        pid = waitpid(-1, &status, WNOHANG);
224
235
    }
225
236
    while (pid > 0);
226
237
}
244
255
    siga.sa_mask  = ss;
245
256
    siga.sa_flags = SA_NOCLDSTOP;
246
257
    sigaction(SIGCHLD, &siga, NULL);
247
 
    
 
258
 
248
259
    for (;;)
249
260
    {
250
261
        FD_ZERO(&rdfs);
251
262
        FD_SET(pty,&rdfs);
252
263
        FD_SET(sock,&rdfs);
253
 
        
 
264
 
254
265
        if (select(FD_SETSIZE,&rdfs,NULL,NULL,NULL) > 0)
255
266
        {
256
267
            if (FD_ISSET(pty,&rdfs))