📄 filingd.c
字号:
#ifndef lintstatic char *rcsid = "$Header: filingd.c,v 1.6 87/05/14 11:33:26 ed Exp $";#endif lint/* * Copyright (c) 1986, 1987 Xerox Corporation. *//* $Log: filingd.c,v $ * Revision 1.6 87/05/14 11:33:26 ed * Open: don't set cur_dir_handle unless directory is opened. * * Revision 1.5 87/05/05 14:46:31 ed * Don't close connection in continuance_expiration if BDT in progress. * * Revision 1.4 87/04/16 15:30:29 ed * Fixed lingering Subset bugs. * * Revision 1.3 87/03/31 14:22:53 ed * Initialize got_matches in get_filter. * * Revision 1.2 87/03/31 09:05:15 ed * New procedures: Create, ChangeAttributes(name only), Copy, Move, * Replace, Serialize, Deserialize. * Added conditional disabling of root logins. * Support for GetAttributes (allAttributeTypes). * Support for filter of type all. * * Revision 1.1 87/01/14 11:25:59 ed * Initial revision * */#include <stdio.h>#include <sys/types.h>#include <netns/ns.h>#include <netns/sp.h>#ifdef FILING4#include "filingV4.h"#include "clearinghouseV2.h"#include "authenticationV2.h"#endif FILING4#ifdef FILING5#include "filingV5.h"#include "clearinghouseV2.h"#include "authenticationV2.h"#endif FILING5#ifdef FILING6#include "filingV6.h"#include "clearinghouseV3.h"#include "authenticationV3.h"#endif FILING6#ifdef FILINGSUBSET1#include "filingsubsetV1.h"#include "clearinghouseV3.h"#include "authenticationV3.h"#endif FILINGSUBSET1#include <xnscourier/filing_server.h>#include <xnscourier/CH.h>#include <xnscourier/filetypes.h>#define SERVICE_ROOT "/" /* root directory for service */#ifdef DEBUGFILE *msgs= 0;#endif DEBUGsession_handle SessionHandle= 0;file_handle RootHandle= { FILE_OPEN, SERVICE_ROOT, 0, 0, 0, TRUE, 0, 0, NULL };extern CourierConnection *_serverConnection; /* current connection */ /* * The continuance value is slightly lower than the 90 second * value in lookahead.c. This should insure that the client will * send a Continue before this service stops looking for the next * procedure call. */Cardinal continuance= 80; /* continuance value in seconds */Boolean BDTabort_expected= FALSE; /* should BDT attn be sent */#ifdef FILETOOLCOMPATIBILITYfile_handle *cur_dir_handle= &RootHandle;#endif FILETOOLCOMPATIBILITYFILING_LogonResultsFILING_Logon(ServerConnection, BDTProc, service_name, user_credentials, user_verifier)CourierConnection *ServerConnection;int (*BDTProc)();CLEARINGHOUSE_ObjectName service_name;FILING_Credentials user_credentials;FILING_Verifier user_verifier;{ FILING_LogonResults result; AUTHENTICATION_ThreePartName chs_name; session_handle *session_ptr; Unspecified *bp, buffer[SPPMAXDATA]; char user[40]; char pass[40]; Cardinal credentials_type; Cardinal len; char *lowercase();#if FILING4 | FILING5 char *rindex(); char *ptr;#endif FILING4 | FILING5 BDTabort_expected= FALSE;#ifdef DEBUG if (msgs == 0) { char logfile[50]; sprintf(logfile, "/tmp/filing%ld.msgs", getpid()); msgs= fopen(logfile,"w"); } fprintf(msgs,"Logon\n");#endif DEBUG#if FILING4 | FILING5 if (user_credentials.type != AUTHENTICATION_simpleCredentials) { ReturnAuthenticationError(AUTHENTICATION_inappropriateCredentials); /* NOT REACHED */ } else { CLEARINGHOUSE_externalize_Item(&user_credentials.value, buffer); bp= buffer; bp += internalize_Cardinal(&len, bp); AUTHENTICATION_internalize_SimpleCredentials(&chs_name, bp);#ifdef DEBUG fprintf(msgs,"chs_name= %s:%s:%s\n",chs_name.object,chs_name.domain,chs_name.organization);#endif DEBUG }#ifdef ROOTNOTALLOWED /* * We don't allow root access from the file server */ if ( strcmp(lowercase(chs_name.object), "root") == 0 ) { ReturnAuthenticationError(AUTHENTICATION_credentialsInvalid); /* NOT REACHED */ }#endif ROOTNOTALLOWED /* * Assumption (for Filing4/Filing5 implementation): * may receive fully specified Clearinghouse name, so we should try * to strip off last name (look for last space) assuming there is a * similary named account on this service. If the user credentials * pass network authentiction, then we will not check passwords on * this service (in fact, we can't since the verifier is hashed). * It is assumed that the name will be found in /etc/passwd and * everything will work regardless of password checking. */ if ( (ptr= rindex(chs_name.object, ' ')) == 0 ) { strcpy(user, chs_name.object); } else { ptr++; strcpy(user, ptr); } if ( !Auth_CredCheck(user_credentials, user_verifier) ) { ReturnAuthenticationError(AUTHENTICATION_credentialsInvalid); /* NOT REACHED */ }#else FILING4 | FILING5 /* * assumption (for FILING6 and FILINGSUBSET1): * no primary credentials are ok * simple primary credentials will be validated with Authentication * strong credentials will be ignored * * secondary credentials must contain userName and userPassword * which are assumed to be Unix name and password */ if (user_credentials.primary.type == AUTHENTICATION_simpleCredentials) { if ( !Auth_CredCheck(user_credentials.primary, user_verifier) ) { ReturnAuthenticationError(FILING_primaryCredentialsInvalid); /* NOT REACHED */ } } if ( get_name_and_pwd(&user_credentials.secondary, user, pass) != -1 ) { ReturnAuthenticationError(FILING_secondaryCredentialsRequired); /* NOT REACHED */ }#ifdef ROOTNOTALLOWED /* * We don't allow root access from the file server */ if ( strcmp(lowercase(user), "root") == 0 ) { ReturnAuthenticationError(AUTHENTICATION_credentialsInvalid); /* NOT REACHED */ }#endif ROOTNOTALLOWED#endif FILING4 | FILING5#ifdef DEBUG fprintf(msgs, "user= %s\n", user);#endif DEBUG if ( verifyandposition_user(user, pass) != -1 ) { /* NOT REACHED */ } session_ptr= &SessionHandle; SessionHandle.state= SESSION_OPEN; SessionHandle.verifier= user_verifier.sequence[0];#ifdef DEBUG/* fprintf(msgs,"handle= %x, ver= %x\n",session_ptr,session_ptr->verifier);*/#endif DEBUG copyhandle(result.session.token, &session_ptr); result.session.verifier.length= sizeof(AUTHENTICATION_SimpleVerifier) / sizeof(Cardinal); result.session.verifier.sequence= Allocate(sizeof(AUTHENTICATION_SimpleVerifier)); result.session.verifier.sequence[0]= user_verifier.sequence[0]; set_continuance_timer();#ifdef DEBUG fprintf(msgs, "out of logon\n");#endif DEBUG return(result);}copyhandle(dest, src)Unspecified *dest, *src;{ if ( dest == (Unspecified *)0 ) {#ifdef DEBUG fprintf(msgs, "Oops, dest is null in copyhandle\n");#else DEBUG fprintf(stderr, "Oops, dest is null in copyhandle\n");#endif DEBUG exit(1); } dest[0]= src[0]; dest[1]= src[1];}void FILING_Logoff(ServerConnection, BDTProc, session)CourierConnection *ServerConnection;int (*BDTProc)();FILING_Session session;{ session_handle *session_ptr; BDTabort_expected= FALSE; if ( verify_session(session) != -1 ) { /* NOT REACHED */ } copyhandle(&session_ptr,session.token);#ifdef SOMEDAY if ( session_ptr->state == SESSION_IN_USE ) { ReturnServiceError(FILING_sessionInUse); } #endif SOMEDAY session_ptr->state= SESSION_CLOSED; reset_continuance_timer(); return;}FILING_OpenResults FILING_Open(ServerConnection, BDTProc, attributes, directory, controls, session)CourierConnection *ServerConnection;int ( *BDTProc)();FILING_AttributeSequence attributes;FILING_Handle directory;FILING_ControlSequence controls;FILING_Session session;{ FILING_OpenResults results; file_handle *handle;#ifdef FILETOOLCOMPATIBILITY file_handle *dir_handle;#endif FILETOOLCOMPATIBILITY BDTabort_expected= FALSE;#ifdef DEBUG if (msgs == 0) { char logfile[50]; sprintf(logfile, "/tmp/filing%ld.msgs", getpid()); msgs= fopen(logfile,"w"); } fprintf(msgs,"Open\n"); fflush(msgs);#endif DEBUG if ( verify_session(session) != -1 ) { /* NOT REACHED */ }#ifndef FILETOOLCOMPATIBILITY if ( is_nullControls(controls) != -1 ) { ReturnControlTypeError(FILING_disallowed,0); /* NOT REACHED */ } if ( is_nullHandle(directory) != -1 ) { ReturnHandleError(FILING_invalid); /* NOT REACHED */ }#endif FILETOOLCOMPATIBILITY if ( (handle= (file_handle *)malloc(sizeof(file_handle))) == NULL ) { ReturnUndefinedError(0); /* NOT REACHED */ }#ifdef DEBUG fprintf(msgs,"Open-- file handle= %x\n",handle); fflush(msgs);#endif DEBUG if ( (handle->pathname= (char *)malloc(MAX_FILE_NAME_LENGTH)) == NULL ) { ReturnUndefinedError(0); /* NOT REACHED */ }#ifdef FILETOOLCOMPATIBILITY copyhandle(&dir_handle,directory); if ( dir_handle != 0 ) { if ( dir_handle->state != FILE_OPEN ) { ReturnHandleError(FILING_invalid); /* NOT REACHED */ } if ( dir_handle->isdirectory != TRUE ) { ReturnHandleError(FILING_directoryRequired); /* NOT REACHED */ } if ( access_file(dir_handle) != -1 ) { /* NOT REACHED */ } strcpy(handle->pathname,dir_handle->pathname); if ( strcmp(handle->pathname, "/") != 0 ) strcat(handle->pathname,"/"); } else { strcpy(handle->pathname, SERVICE_ROOT); }#else FILETOOLCOMPATIBILITY strcpy(handle->pathname, SERVICE_ROOT);#endif FILETOOLCOMPATIBILITY if ( verify_open_attributes(attributes, handle) != -1 ) { /* NOT REACHED */ } if ( stat_file(handle) != -1 ) { /* NOT REACHED */ } handle->state= FILE_OPEN; handle->file_desc= NULL; handle->createdon= handle->modifiedon= 0; copyhandle(results.file,&handle);#ifdef FILETOOLCOMPATIBILITY if ( handle->isdirectory == TRUE ) cur_dir_handle= handle;#endif FILETOOLCOMPATIBILITY reset_continuance_timer(); return(results);}verify_session(session)FILING_Session session;{ session_handle *session_ptr; copyhandle(&session_ptr, session.token); if ( session_ptr == 0 || (session_ptr->state != SESSION_OPEN) ) { ReturnSessionError(FILING_tokenInvalid); /* NOT REACHED */ } if ( session_ptr->verifier != *(session.verifier.sequence) ) { ReturnAuthenticationError(AUTHENTICATION_verifierInvalid); /* NOT REACHED */ } return(-1);}is_nullControls(controls)FILING_ControlSequence controls;{ if ( controls.length != 0 && controls.sequence != 0 ) { return(0); } return(-1);}is_nullHandle(handle)FILING_Handle handle;{ if ( handle[0] != 0 && handle[1] != 0 ) { return(0); } return(-1);}verify_open_attributes(attr, handle)FILING_AttributeSequence attr;file_handle *handle;{ int i; FILING_AttributeType t; int got_parentID, got_pathname, got_type, got_version; char *pathname; Unspecified *parentid; FILING_Version version; char *AttrToString(); Unspecified *AttrToFileID(); LongCardinal AttrToLongCardinal();#ifdef FILETOOLCOMPATIBILITY int got_name, got_fileID; char *name; Unspecified *fileid;#endif FILETOOLCOMPATIBILITY#ifdef DEBUG fprintf(msgs,"verify_open_attribute %d attributes ",attr.length);#endif DEBUG got_parentID= got_pathname= got_type= got_version= 0;#ifdef FILETOOLCOMPATIBILITY got_name= got_fileID= 0;#endif FILETOOLCOMPATIBILITY#ifdef FILETOOLCOMPATIBILITY if ( attr.length == 0 ) { return; }#endif FILETOOLCOMPATIBILITY for ( i= 0 ; i < attr.length ; i++ ) { t= attr.sequence[i].type; if ( t == FILING_parentID ) {#ifdef DEBUG fprintf(msgs,"parentID ");#endif DEBUG if ( got_parentID ) { ReturnAttributeTypeError(FILING_duplicated, t); /* NOT REACHED */ } got_parentID++; parentid= AttrToFileID(&attr.sequence[i]); if ( !is_nullID(parentid) ) { ReturnAttributeValueError(FILING_unimplemented, t); /* NOT REACHED */ } continue; } if ( t == FILING_pathname ) {#ifdef DEBUG fprintf(msgs,"pathname ");#endif DEBUG if ( got_pathname ) { ReturnAttributeTypeError(FILING_duplicated, t); /* NOT REACHED */ } got_pathname++; pathname= AttrToString(&attr.sequence[i]); if ( check_pathname(pathname) != -1 ) { /* NOT REACHED */ } continue; } if ( t == FILING_type ) {#ifdef DEBUG fprintf(msgs,"type ");#endif DEBUG if ( got_type ) { ReturnAttributeTypeError(FILING_duplicated, t); /* NOT REACHED */ } got_type++; handle->type= AttrToLongCardinal(&attr.sequence[i]);#ifndef EXTENSIONS if ( (handle->type != FILING_tText) && (handle->type != FILING_tUnspecified) ) { ReturnAttributeValueError(FILING_unimplemented, t); /* NOT REACHED */ }#endif EXTENSIONS continue; } if ( t == FILING_version ) {#ifdef DEBUG fprintf(msgs,"version ");#endif DEBUG if ( got_version ) { ReturnAttributeTypeError(FILING_duplicated, t); /* NOT REACHED */ } got_version++; version= AttrToCardinal(&attr.sequence[i]); if ( version != FILING_highestVersion && version != FILING_lowestVersion ) { ReturnAttributeValueError(FILING_unimplemented, t); /* NOT REACHED */ } continue; }#ifdef FILETOOLCOMPATIBILITY if ( t == FILING_name ) {#ifdef DEBUG fprintf(msgs, "name ");#endif DEBUG if ( got_name ) { ReturnAttributeTypeError(FILING_duplicated, t); /* NOT REACHED */ } got_name++; name= AttrToString(&attr.sequence[i]); continue; } if ( t == FILING_fileID ) {#ifdef DEBUG fprintf(msgs, "fileID ");#endif DEBUG if ( got_fileID ) { ReturnAttributeTypeError(FILING_duplicated, t); /* NOT REACHED */ } got_fileID++; fileid= AttrToFileID(&attr.sequence[i]); if ( is_nullID(fileid) == -1 ) { ReturnAttributeValueError(FILING_disallowed, t); /* NOT REACHED */ } strcpy(handle->pathname, cur_dir_handle->pathname); if ( get_name_from_fileID(handle, fileid) != -1 ) { /* NOT REACHED */ } continue; }#else FILETOOLCOMPATIBILITY if ( t == FILING_fileID ) { ReturnAttributeTypeError(FILING_unimplemented, t); /* NOT REACHED */ } if ( t == FILING_name ) { ReturnAttributeTypeError(FILING_unimplemented, t); /* NOT REACHED */ }#endif FILETOOLCOMPATIBILITY if ( ( t < 0 ) || (t > FILING_subtreeSizeLimit) ) { ReturnAttributeTypeError(FILING_illegal, t); /* NOT REACHED */ } ReturnAttributeTypeError(FILING_disallowed, t);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -