~ubuntu-branches/ubuntu/precise/dnprogs/precise

« back to all changes in this revision

Viewing changes to dnlogin/found.c

  • Committer: Bazaar Package Importer
  • Author(s): Patrick Caulfield
  • Date: 2006-05-17 10:09:35 UTC
  • Revision ID: james.westby@ubuntu.com-20060517100935-2k2hwljsxvo9n5bi
Tags: 2.37.1
Add Spanish debconf translation.
Closes: #367286

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/******************************************************************************
2
 
    (c) 2002      P.J. Caulfield          patrick@debian.org
 
2
    (c) 2002-2006      P.J. Caulfield          patrick@debian.org
3
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
34
34
 
35
35
/* Foundation services messages */
36
36
#define FOUND_MSG_BIND        1
37
 
#define FOUND_MSG_UNBIND      3
 
37
#define FOUND_MSG_UNBIND      2
38
38
#define FOUND_MSG_BINDACCEPT  4
39
39
#define FOUND_MSG_ENTERMODE   5
40
40
#define FOUND_MSG_EXITMODE    6
126
126
        struct msghdr msg;
127
127
        struct common_header header;
128
128
 
129
 
        if (debug & 1) fprintf(stderr, "FOUND: sending %d bytes\n", len);
130
 
        if (debug & 8)
 
129
        DEBUG_FOUND("sending %d bytes\n", len);
 
130
        if (debug & DEBUG_FLAG_FOUND2)
131
131
        {
132
132
                int i;
133
 
 
 
133
                DEBUG_FOUND2("sending: ");
134
134
                for (i=0; i<len; i++)
135
 
                        fprintf(stderr, "%02x  ", (char)buf[i]);
136
 
                fprintf(stderr, "\n\n");
 
135
                        DEBUGLOG(DEBUG_FLAG_FOUND2, "%02x  ", (char)buf[i]);
 
136
                DEBUGLOG(DEBUG_FLAG_FOUND2, "\n\n");
137
137
        }
138
138
 
139
139
 
153
153
        header.pad = 0;
154
154
        header.len = dn_htons(len);
155
155
 
156
 
        if (debug & 1)
157
 
                fprintf(stderr, "FOUND: sending common message %d bytes:\n", len);
 
156
        DEBUG_FOUND("sending common message %d bytes:\n", len);
158
157
 
159
158
        return sendmsg(sockfd, &msg, MSG_EOR);
160
159
}
163
162
{
164
163
        int len;
165
164
        char inbuf[1024];
166
 
        int ptr = 0;
167
165
 
168
166
        if ( (len=dnet_recv(sockfd, inbuf, sizeof(inbuf), MSG_EOR|MSG_DONTWAIT|MSG_NOSIGNAL)) <= 0)
 
167
 
169
168
        {
170
 
                if (len == -1 && errno == EAGAIN)
 
169
                if (len == -1 && (errno == EAGAIN || errno == ESPIPE))
171
170
                        return 0;
172
171
                /* Remote end shut down */
173
172
                if (len == 0)
180
179
                return -1;
181
180
        }
182
181
 
183
 
        if (debug & 1)
184
 
                fprintf(stderr, "FOUND: got message %d bytes:\n", len);
185
 
        if (debug & 8)
 
182
        DEBUG_FOUND("got message %d bytes:\n", len);
 
183
        if (debug & DEBUG_FLAG_FOUND2)
186
184
        {
187
185
                int i;
188
186
 
 
187
                DEBUG_FOUND2("read: ");
189
188
                for (i=0; i<len; i++)
190
 
                        fprintf(stderr, "%02x  ", (char)inbuf[i]);
191
 
                fprintf(stderr, "\n\n");
 
189
                        DEBUGLOG(DEBUG_FLAG_FOUND2,  "%02x  ", (char)inbuf[i]);
 
190
                DEBUGLOG(DEBUG_FLAG_FOUND2, "\n\n");
192
191
        }
193
192
 
194
193
 
196
195
        switch (inbuf[0])
197
196
        {
198
197
        case FOUND_MSG_BIND:
199
 
                if (debug & 1)
200
 
                        fprintf(stderr, "FOUND: connected to %s host\n", hosttype[inbuf[4]-1]);
 
198
                DEBUG_FOUND("connected to %s host\n", hosttype[inbuf[4]-1]);
201
199
                return send_bindaccept();
202
200
 
203
201
        case FOUND_MSG_UNBIND:
204
 
                if (debug & 1)
205
 
                        fprintf(stderr, "FOUND: Unbind from host. reason = %d\n", inbuf[1]);
 
202
                DEBUG_FOUND("Unbind from host. reason = %d\n", inbuf[1]);
206
203
                return -1;
207
204
 
208
205
        case FOUND_MSG_ENTERMODE:
209
206
        {
210
207
                char nomode_msg[] = {0x8};
211
 
                if (debug)
212
 
                        fprintf(stderr, "FOUND: Request to enter mode = %d\n", inbuf[1]);
 
208
                DEBUG_FOUND("Request to enter mode = %d\n", inbuf[1]);
213
209
                write(sockfd, nomode_msg, sizeof(nomode_msg));
214
210
                return 0;
215
211
        }
222
218
                {
223
219
                        int msglen = inbuf[ptr] | inbuf[ptr+1]<<8;
224
220
 
225
 
                        if (debug&1)
226
 
                                fprintf(stderr, "FOUND: commondata: %d bytes\n",msglen);
 
221
                        DEBUG_FOUND("commondata: %d bytes\n",msglen);
227
222
 
228
223
                        ptr += 2;
229
224
                        terminal_processor(inbuf+ptr, msglen);
232
227
        }
233
228
        break;
234
229
 
235
 
        case 2: /* Reserved */
 
230
        case 3: /* Reserved */
236
231
                break;
237
232
 
238
233
        default:
247
242
{
248
243
        struct nodeent *np;
249
244
        struct sockaddr_dn sockaddr;
 
245
        struct accessdata_dn accessdata;
 
246
        char *local_user;
250
247
 
251
248
        if ( (np=getnodebyname(node)) == NULL)
252
249
        {
261
258
                return -1;
262
259
        }
263
260
 
 
261
        /* Send the logged in userID for niceness sake */
 
262
        memset(&accessdata, 0, sizeof(accessdata));
 
263
        local_user = cuserid(NULL);
 
264
        if (!local_user || local_user == (char *)0xffffffff)
 
265
                local_user = getenv("LOGNAME");
 
266
 
 
267
        if (!local_user) local_user = getenv("USER");
 
268
        if (local_user)
 
269
        {
 
270
                strcpy((char *)accessdata.acc_acc, local_user);
 
271
                accessdata.acc_accl = strlen((char *)accessdata.acc_acc);
 
272
                setsockopt(sockfd, DNPROTO_NSP, SO_CONACCESS, &accessdata,
 
273
                           sizeof(accessdata));
 
274
        }
 
275
 
264
276
        sockaddr.sdn_family = AF_DECnet;
265
277
        sockaddr.sdn_flags = 0x00;
266
278
        sockaddr.sdn_objnum = object;