Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
View | Details | Raw Unified | Return to bug 77414 | Differences between
and this patch

Collapse All | Expand All

(-)1.93/lib/ncplib.c (-1 / +5 lines)
Lines 2259-2264 Link Here
2259
	if (stat(path, &st) != 0) {
2259
	if (stat(path, &st) != 0) {
2260
		return errno;
2260
		return errno;
2261
	}
2261
	}
2262
        if (st.st_uid != getuid()) {
2263
                *err = EACCES;
2264
                return NULL;
2265
        }
2262
	if ((st.st_mode & (S_IRWXO | S_IRWXG)) != 0) {
2266
	if ((st.st_mode & (S_IRWXO | S_IRWXG)) != 0) {
2263
		return NCPLIB_INVALID_MODE;
2267
		return NCPLIB_INVALID_MODE;
2264
	}
2268
	}
Lines 2367-2373 Link Here
2367
		       spec->server, spec->user);
2371
		       spec->server, spec->user);
2368
2372
2369
		pwd = getpass(_("Password: "));
2373
		pwd = getpass(_("Password: "));
2370
		if (strlen(pwd) > sizeof(spec->password)) {
2374
		if (strlen(pwd) >= sizeof(spec->password)) {
2371
			return ENAMETOOLONG;
2375
			return ENAMETOOLONG;
2372
		}
2376
		}
2373
		strcpy(spec->password, pwd);
2377
		strcpy(spec->password, pwd);
(-)1.6/lib/nwclient.c (-67 / +51 lines)
Lines 477-482 Link Here
477
                *err = errno;
477
                *err = errno;
478
                return NULL;
478
                return NULL;
479
        }
479
        }
480
        if (st.st_uid != getuid()) {
481
                *err = EACCES;
482
                return NULL;
483
        }
480
        if ((st.st_mode & (S_IRWXO | S_IRWXG)) != 0) {
484
        if ((st.st_mode & (S_IRWXO | S_IRWXG)) != 0) {
481
                *err = NCPLIB_INVALID_MODE;
485
                *err = NCPLIB_INVALID_MODE;
482
                return NULL;
486
                return NULL;
Lines 816-822 Link Here
816
static NWDSCCODE __docopy_string (UNUSED(NWDSContextHandle ctx), const void* val,
820
static NWDSCCODE __docopy_string (UNUSED(NWDSContextHandle ctx), const void* val,
817
                                   const enum SYNTAX synt, size_t currentSize,
821
                                   const enum SYNTAX synt, size_t currentSize,
818
                                   char* result, size_t maxSize){
822
                                   char* result, size_t maxSize){
819
823
  int l;
820
#ifdef DEBUG_PRINT
824
#ifdef DEBUG_PRINT
821
  printf ("__docopy_string got :%s synt = %d cursize=%d maxsize= %d\n",(char *)val,synt,currentSize,maxSize );
825
  printf ("__docopy_string got :%s synt = %d cursize=%d maxsize= %d\n",(char *)val,synt,currentSize,maxSize );
822
#endif
826
#endif
Lines 825-914 Link Here
825
  if (!result) return ERR_NULL_POINTER;
829
  if (!result) return ERR_NULL_POINTER;
826
  switch (synt) {
830
  switch (synt) {
827
	case SYN_DIST_NAME:
831
	case SYN_DIST_NAME:
828
#if 0
829
		{
830
			NWDSCCODE err;
831
			char tmpBuf [MAX_DN_BYTES+1];
832
833
			err = NWDSAbbreviateName(ctx, val, tmpBuf);
834
			if (err)
835
				return err;
836
			strcpy (result,tmpBuf);
837
		}
838
#else
839
		strcpy(result,val);
840
#endif
841
		break;
842
	case SYN_CI_STRING:
832
	case SYN_CI_STRING:
843
	case SYN_CE_STRING:
833
	case SYN_CE_STRING:
844
        case SYN_PR_STRING:
834
        case SYN_PR_STRING:
845
	case SYN_NU_STRING:
835
	case SYN_NU_STRING:
846
	case SYN_TEL_NUMBER:
836
	case SYN_TEL_NUMBER:
847
	case SYN_CLASS_NAME:
837
	case SYN_CLASS_NAME:
848
		strcpy(result,val);
838
		l = snprintf(result, maxSize, "%s", (const char *)val);
849
	        break;
839
		break;
850
	case SYN_PATH:{
840
	case SYN_PATH:{
851
	        const Path_T* p = (const Path_T*)val;
841
	        const Path_T* p = (const Path_T*)val;
852
                if (strlen(p->volumeName)+strlen(p->path)+2+2+1>=maxSize)
842
853
                        return NWE_BUFFER_OVERFLOW;
843
		l = snprintf(result, maxSize, "%u,%s,%s", p->nameSpaceType, p->volumeName, p->path);
854
		sprintf(result,"%u,%s,%s", p->nameSpaceType,p->volumeName, p->path);
855
                }
844
                }
856
		break;
845
		break;
857
	case SYN_TYPED_NAME:{
846
	case SYN_TYPED_NAME:{
858
		const Typed_Name_T* tn = (const Typed_Name_T*)val;
847
		const Typed_Name_T* tn = (const Typed_Name_T*)val;
859
                if (strlen(tn->objectName)+8+8+2+1>=maxSize)
848
860
                        return NWE_BUFFER_OVERFLOW;
849
		l = snprintf(result, maxSize, "%u,%u,%s", tn->interval, tn->level, tn->objectName);
861
		sprintf(result,"%u,%u,%s", tn->interval,tn->level,tn->objectName);
862
		}
850
		}
863
		break;
851
		break;
864
	case SYN_FAX_NUMBER:{
852
	case SYN_FAX_NUMBER:{
865
	        const Fax_Number_T* fn = (const Fax_Number_T*)val;
853
	        const Fax_Number_T* fn = (const Fax_Number_T*)val;
866
                if (strlen(fn->telephoneNumber)+2+1+1>=maxSize)
854
		
867
                        return NWE_BUFFER_OVERFLOW;
855
		l = snprintf(result, maxSize, "%s,%u", fn->telephoneNumber, fn->parameters.numOfBits);
868
		sprintf(result,"%s,%u", fn->telephoneNumber,fn->parameters.numOfBits);
869
		}
856
		}
870
		break;
857
		break;
871
	case SYN_EMAIL_ADDRESS:{
858
	case SYN_EMAIL_ADDRESS:{
872
		const EMail_Address_T* ea = (const EMail_Address_T*)val;
859
		const EMail_Address_T* ea = (const EMail_Address_T*)val;
873
                /*change the SMTP:aaa@bbbb to SMTP,aaa@bbbb */
860
                /*change the SMTP:aaa@bbbb to SMTP,aaa@bbbb */
874
                char* p=strchr(ea->address,':');
861
                char* p=strchr(ea->address,':');
875
                if (strlen(ea->address)+2+1+1>=maxSize)
876
                        return NWE_BUFFER_OVERFLOW;
877
862
878
                if (p) *p=',';
863
                if (p) *p=',';
879
		sprintf(result,"%u,%s", ea->type,ea->address);
864
		l = snprintf(result, maxSize, "%u,%s", ea->type, ea->address);
880
		}
865
		}
881
		break;
866
		break;
882
	case SYN_PO_ADDRESS:{
867
	case SYN_PO_ADDRESS:{
883
	        const NWDSChar* const* pa = (const NWDSChar* const*)val;
868
	        const NWDSChar* const* pa = (const NWDSChar* const*)val;
884
                int n;
869
885
                size_t len=1;
870
		l = snprintf(result, maxSize, "%s,%s,%s,%s,%s,%s", pa[0], pa[1], pa[2], pa[3], pa[4], pa[5]);
886
                for (n=0;n <5;n++)
887
                  len +=strlen(pa[n]+1);
888
                if (len >=maxSize)
889
                        return NWE_BUFFER_OVERFLOW;
890
		sprintf(result,"%s,%s,%s,%s,%s,%s",pa[0],pa[1],pa[2],pa[3],pa[4],pa[5]);
891
		}
871
		}
892
		break;
872
		break;
893
	case SYN_HOLD:{
873
	case SYN_HOLD:{
894
	        const Hold_T* h = (const Hold_T*)val;
874
	        const Hold_T* h = (const Hold_T*)val;
895
                if (strlen(h->objectName)+8+1+1>=maxSize)
875
896
                        return NWE_BUFFER_OVERFLOW;
876
		l = snprintf(result, maxSize, "%u,%s", h->amount, h->objectName);
897
		sprintf(result,"%u,%s", h->amount, h->objectName);
898
		}
877
		}
899
		break;
878
		break;
900
         case SYN_TIMESTAMP:{
879
         case SYN_TIMESTAMP:{
901
                const TimeStamp_T* stamp = (const TimeStamp_T*)val;
880
                const TimeStamp_T* stamp = (const TimeStamp_T*)val;
902
                if (maxSize <=3*9)
881
                
903
                        return NWE_BUFFER_OVERFLOW;
882
		l = snprintf(result, maxSize, "%u,%u,%u", stamp->wholeSeconds, stamp->replicaNum, stamp->eventID);
904
                sprintf(result,"%u,%u,%u",stamp->wholeSeconds, stamp->replicaNum,stamp->eventID);
905
                }
883
                }
906
                break;
884
                break;
907
         case SYN_BACK_LINK:{
885
         case SYN_BACK_LINK:{
908
                const Back_Link_T* bl = (const Back_Link_T*)val;
886
                const Back_Link_T* bl = (const Back_Link_T*)val;
909
                if (strlen(bl->objectName)+8+1+1 >=maxSize)
887
910
                        return NWE_BUFFER_OVERFLOW;
888
		l = snprintf(result, maxSize, "%08X,%s", bl->remoteID, bl->objectName);
911
                sprintf(result,"%08X,%s", bl->remoteID, bl->objectName);
912
                }
889
                }
913
                break;
890
                break;
914
        case SYN_CI_LIST:{
891
        case SYN_CI_LIST:{
Lines 933-992 Link Here
933
                }
910
                }
934
                *(--aux)=0;
911
                *(--aux)=0;
935
                }
912
                }
936
		break;
913
		return 0;
937
914
938
         case SYN_OCTET_LIST:{
915
         case SYN_OCTET_LIST:{
939
                const Octet_List_T* ol = (const Octet_List_T*)val;
916
                const Octet_List_T* ol = (const Octet_List_T*)val;
940
                size_t i;
917
                size_t i;
941
                char aux [4];
918
                char *aux;
942
                if ((ol->length+1)*3+1 >=maxSize)
919
920
                if (20 + (ol->length+1)*3+1 >=maxSize)
943
                        return NWE_BUFFER_OVERFLOW;
921
                        return NWE_BUFFER_OVERFLOW;
944
                sprintf(result,"%u", ol->length);
922
                sprintf(result, "%u", ol->length);
923
		aux = result + strlen(result);
945
                for (i = 0; i < ol->length; i++) {
924
                for (i = 0; i < ol->length; i++) {
946
                        sprintf(aux,",%02X", ol->data[i]);
925
                        sprintf(aux, ",%02X", ol->data[i]);
947
                        strcat(result,aux);
926
                        aux += 3;
948
                }
927
                }
949
                }
928
                }
950
                break;
929
                return 0;
951
        case SYN_OCTET_STRING:{
930
        case SYN_OCTET_STRING:{
952
                const Octet_String_T* os = (const Octet_String_T*)val;
931
                const Octet_String_T* os = (const Octet_String_T*)val;
953
                char aux [4];
954
                size_t i;
932
                size_t i;
933
		char *aux;
955
#ifdef DEBUG_PRINT
934
#ifdef DEBUG_PRINT
956
                printf ("len %d\n",os->length);
935
                printf ("len %d\n",os->length);
957
#endif
936
#endif
958
                if ((os->length+1)*3+1 >=maxSize)
937
                if (20 + (os->length+1)*3+1 >=maxSize)
959
                        return NWE_BUFFER_OVERFLOW;
938
                        return NWE_BUFFER_OVERFLOW;
960
                sprintf(result,"%u", os->length);
939
                sprintf(result, "%u", os->length);
940
		aux = result + strlen(result);
961
                for (i = 0; i < os->length; i++) {
941
                for (i = 0; i < os->length; i++) {
962
                        sprintf(aux,",%02X", os->data[i]);
942
                        sprintf(aux, ",%02X", os->data[i]);
963
                        strcat(result,aux);
943
                        aux += 3;
964
                }
944
                }
965
                }
945
                }
966
                break;
946
                return 0;
967
        case SYN_NET_ADDRESS:{
947
        case SYN_NET_ADDRESS:{
968
                const Net_Address_T* na = (const Net_Address_T*)val;
948
                const Net_Address_T* na = (const Net_Address_T*)val;
969
                size_t z;
949
                size_t z;
970
                char aux[4];
950
                char *aux;
951
971
                z=na->addressLength;
952
                z=na->addressLength;
972
                if (3*(z+2)+1  >=maxSize)
953
                if (40 + 3*(z+2)+1  >=maxSize)
973
                        return NWE_BUFFER_OVERFLOW;
954
                        return NWE_BUFFER_OVERFLOW;
974
                sprintf(result,"%u,%u", na->addressType,na->addressLength);
955
                sprintf(result, "%u,%u", na->addressType, na->addressLength);
956
		aux = result + strlen(result);
975
                for (z = 0; z < na->addressLength; z++) {
957
                for (z = 0; z < na->addressLength; z++) {
976
                        sprintf(aux,",%02X", na->address[z]);
958
                        sprintf(aux, ",%02X", na->address[z]);
977
                        strcat(result,aux);
959
			aux += 3;
978
                }
960
                }
979
                }
961
                }
980
                break;
962
                return 0;
981
        case SYN_OBJECT_ACL:{
963
        case SYN_OBJECT_ACL:{
982
                const Object_ACL_T* oacl = (const Object_ACL_T*)val;
964
                const Object_ACL_T* oacl = (const Object_ACL_T*)val;
983
                if (strlen(oacl->protectedAttrName)+strlen(oacl->subjectName)+8+2+1 >=maxSize)
965
984
                        return NWE_BUFFER_OVERFLOW;
966
		l = snprintf(result, maxSize, "%s,%s,%08X", oacl->protectedAttrName, oacl->subjectName, oacl->privileges);
985
                sprintf(result,"%s,%s,%08X",oacl->protectedAttrName,oacl->subjectName,oacl->privileges);
986
                }
967
                }
987
                break;
968
                break;
988
	default:
969
	default:
989
		return EINVAL;
970
		return EINVAL;
971
	}
972
	if (l < 0 || (size_t)l >= maxSize) {
973
		return NWE_BUFFER_OVERFLOW;
990
	}
974
	}
991
        return 0;
975
        return 0;
992
}
976
}
(-)1.18/sutil/ncplogin.c (-60 / +58 lines)
Lines 162-191 Link Here
162
#endif
162
#endif
163
163
164
        static int opt_set_volume_after_parsing_all_options(struct ncp_mount_info* info) {
164
        static int opt_set_volume_after_parsing_all_options(struct ncp_mount_info* info) {
165
                char tmpNWPath[1024];
165
                char *path;
166
		int e;
166
		int e;
167
167
168
                /* we DID check in main that -V has been specified !*/
168
		if (info->root_path) {
169
                strcpy(tmpNWPath,info->remote_path);
169
			e = asprintf(&path, "%s/%s", info->remote_path, info->root_path);
170
                if (info->root_path) {
170
		} else {
171
                        strcat(tmpNWPath,"/");
171
			e = asprintf(&path, "%s", info->remote_path);
172
                        strcat(tmpNWPath,info->root_path);
172
		}
173
                }
173
		if (e == -1) {
174
			errexit(84, _("Cannot allocate memory for path\n"));
175
		}
174
                /* I keep forgeting typing it in uppercase so let's do it here */
176
                /* I keep forgeting typing it in uppercase so let's do it here */
175
                str_upper(tmpNWPath);
177
                str_upper(path);
176
                info->pathlen = e = ncp_path_to_NW_format(tmpNWPath, info->NWpath, sizeof(info->NWpath));
178
                info->pathlen = e = ncp_path_to_NW_format(path, info->NWpath, sizeof(info->NWpath));
177
	        if (e < 0) {
179
	        if (e < 0) {
178
		        errexit(18, _("Volume path `%s' is invalid: `%s'\n"), tmpNWPath, strerror(-e));
180
		        errexit(18, _("Volume path `%s' is invalid: `%s'\n"), path, strerror(-e));
179
	        };
181
	        };
180
	        if (info->pathlen == 1) {
182
	        if (info->pathlen == 1) {
181
		        info->mdata.mounted_vol = "";
183
		        info->mdata.mounted_vol = "";
182
		        info->remote_path = "/";
184
		        info->remote_path = "/";
185
			free(path);
183
	        } else if (info->NWpath[0] != 1) {
186
	        } else if (info->NWpath[0] != 1) {
184
		        info->mdata.mounted_vol = "dummy";
187
		        info->mdata.mounted_vol = "dummy";
185
	        } else if (strlen(tmpNWPath) > NCP_VOLNAME_LEN) {
188
			free(path);
186
		        errexit(19, _("Volume name `%s' is too long\n"), tmpNWPath);
189
	        } else if (strlen(path) > NCP_VOLNAME_LEN) {
190
		        errexit(19, _("Volume name `%s' is too long\n"), path);
187
	        } else {
191
	        } else {
188
		        info->mdata.mounted_vol=info->remote_path;
192
		        info->mdata.mounted_vol = path;
189
	        }
193
	        }
190
                return 0;
194
                return 0;
191
        }
195
        }
Lines 201-208 Link Here
201
        }
205
        }
202
206
203
        static void opt_set_name_context(struct ncp_mount_info* info, const char* param) {
207
        static void opt_set_name_context(struct ncp_mount_info* info, const char* param) {
204
                if (strlen(param)< sizeof(info->context))
208
                if (strlen(param) < sizeof(info->context))
205
	                strcpy(info->context,param);
209
	                strcpy(info->context, param);
206
                else{
210
                else{
207
	                errexit(19, _("Context name `%s' is too long\n"), param);
211
	                errexit(19, _("Context name `%s' is too long\n"), param);
208
                }
212
                }
Lines 307-313 Link Here
307
{
311
{
308
	struct ncp_mount_info info;
312
	struct ncp_mount_info info;
309
	struct stat st;
313
	struct stat st;
310
	char mount_name[256];
314
	char *mount_name;
311
315
312
	int result;
316
	int result;
313
317
Lines 340-346 Link Here
340
344
341
	init_mount_info(&info);
345
	init_mount_info(&info);
342
346
343
	if (geteuid() != 0)
347
	if (myeuid != 0)
344
	{
348
	{
345
		errexit(26, _("%s must be installed suid root\n"), progname);
349
		errexit(26, _("%s must be installed suid root\n"), progname);
346
	}
350
	}
Lines 807-848 Link Here
807
811
808
	info.mdata.mount_point = mount_point;
812
	info.mdata.mount_point = mount_point;
809
#ifndef NCPMAP
813
#ifndef NCPMAP
810
	strcpy(mount_name, spec.server);
814
	if (asprintf(&mount_name, "%s/%s", spec.server, spec.user) < 0) {
811
	strcat(mount_name, "/");
815
		NWDSFreeContext(ctx);
812
	strcat(mount_name, spec.user);
816
		errexit(85, _("Cannot allocate memory for mtab entry: %s\n"), strerror(ENOMEM));
813
#else
817
	}
814
	{
818
#else
815
/* v 1.05 test for no multiple mount */
819
	{
816
		char nwuser[256]="";
820
		NWDSChar user[MAX_DN_BYTES];
817
/*		struct ncp_conn_spec tmpSpec; */
821
818
822
		err = NWDSWhoAmI(ctx, user);
819
		strcpy(mount_name, info.server);
823
		if (err) {
820
		strcat(mount_name, "/");
824
			NWDSFreeContext(ctx);
821
		if ((err = NWDSWhoAmI(ctx,nwuser))==0) {
825
			errexit(51, _("Cannot retrieve user identity: %s\n"), strnwerror(err));
822
		/* v 1.05 remove context in /etc/mtab entry */
823
			NWCXSplitNameAndContext(ctx,nwuser,nwuser,NULL);
824
			str_upper(nwuser);
825
			strcat(mount_name,nwuser);
826
/* does not work
827
    if current user has another connexion to that server, even to another volume:path
828
    ncp_find_permanent does not care about volume name nor "root path"
829
                        memset(&tmpSpec, 0, sizeof(tmpSpec));
830
                        strcpy(tmpSpec.user,nwuser);
831
                        strcpy(tmpSpec.server,info.serverName);
832
                        tmpSpec.uid=info.mdata.uid;
833
                        if ((!info.allow_multiple_connections)&&
834
		    ((tmp_mount = ncp_find_permanent(&tmpSpec)) != NULL))
835
		{
836
			fprintf(stderr,
837
				_("You already have mounted server %s\nas user "
838
				"%s\non mount point %s\n"), tmpSpec.server, tmpSpec.user,
839
				tmp_mount);
840
			exit(35);
841
		}
826
		}
842
***************/
827
		err = NWCXSplitNameAndContext(ctx, user, user, NULL);
843
		} else {
828
		if (err) {
829
			NWDSFreeContext(ctx);
830
			errexit(86, _("Cannot parse user name: %s\n"), strnwerror(err));
831
		}
832
		/* FIXME: str_upper is unwanted! NWCXSplitNameAndContext too, BTW... Just retrieve name from server and do 'NWDSAbbreviateName' on it */
833
		str_upper(user);
834
		if (asprintf(&mount_name, "%s/%s", info.server, user) < 0) {
844
			NWDSFreeContext(ctx);
835
			NWDSFreeContext(ctx);
845
			errexit(51, _("NWDSWhoAmi returned %s\n"), strnwerror(err));
836
			errexit(85, _("Cannot allocate memory for mtab entry: %s\n"), strerror(ENOMEM));
846
		}
837
		}
847
	}
838
	}
848
#endif
839
#endif
Lines 855-868 Link Here
855
		} else {
846
		} else {
856
			mycom_err(result, _("failed in mount(2)"));
847
			mycom_err(result, _("failed in mount(2)"));
857
		}
848
		}
849
		free(mount_name);
858
		NWDSFreeContext(ctx);
850
		NWDSFreeContext(ctx);
859
		/*exit code stays 0 for TCL/tk to be fixed...*/
851
		/*exit code stays 0 for TCL/tk to be fixed...*/
860
		exit(0);
852
		exit(0);
861
	}
853
	}
862
	err = proc_aftermount(&info, &conn);
854
	err = proc_aftermount(&info, &conn);
863
	if (err) {
855
	if (err) {
856
		free(mount_name);
864
		NWDSFreeContext(ctx);
857
		NWDSFreeContext(ctx);
865
		umount(mount_point);
858
		proc_ncpm_umount(mount_point);
866
		exit(err);
859
		exit(err);
867
	}
860
	}
868
#ifndef NCPMAP
861
#ifndef NCPMAP
Lines 875-881 Link Here
875
				mycom_err(err, _("failed in nds login"));
868
				mycom_err(err, _("failed in nds login"));
876
				fprintf(stderr, _("Login denied.\n"));
869
				fprintf(stderr, _("Login denied.\n"));
877
				ncp_close(conn);
870
				ncp_close(conn);
878
				umount(mount_point);
871
				proc_ncpm_umount(mount_point);
872
				free(mount_name);
879
				NWDSFreeContext(ctx);
873
				NWDSFreeContext(ctx);
880
				exit(55);
874
				exit(55);
881
			}
875
			}
Lines 893-899 Link Here
893
				mycom_err(err, _("in login"));
887
				mycom_err(err, _("in login"));
894
				fprintf(stderr, _("Login denied\n"));
888
				fprintf(stderr, _("Login denied\n"));
895
				ncp_close(conn);
889
				ncp_close(conn);
896
				umount(mount_point);
890
				proc_ncpm_umount(mount_point);
891
				free(mount_name);
897
				NWDSFreeContext(ctx);
892
				NWDSFreeContext(ctx);
898
				exit(56);
893
				exit(56);
899
			}
894
			}
Lines 911-944 Link Here
911
	err = NWDSAddConnection(ctx, conn);
906
	err = NWDSAddConnection(ctx, conn);
912
	if (err) {
907
	if (err) {
913
		ncp_close(conn);
908
		ncp_close(conn);
914
		umount(mount_point);
909
		proc_ncpm_umount(mount_point);
910
		free(mount_name);
915
		NWDSFreeContext(ctx);
911
		NWDSFreeContext(ctx);
916
		errexit(110, _("Cannot attach connection to context: %s\n"), strnwerror(err));
912
		errexit(110, _("Cannot attach connection to context: %s\n"), strnwerror(err));
917
	}
913
	}
918
	err = NWDSAuthenticateConn(ctx, conn);
914
	err = NWDSAuthenticateConn(ctx, conn);
919
	if (err) {
915
	if (err) {
920
		ncp_close(conn);
916
		ncp_close(conn);
921
		umount(mount_point);
917
		proc_ncpm_umount(mount_point);
922
/*one day I will be in trouble here, when NWDSFreeContext() will free all added connections */
918
		free(mount_name);
923
		NWDSFreeContext(ctx);
919
		NWDSFreeContext(ctx);
924
		errexit(112, _("Cannot authenticate connection: %s\n"), strnwerror(err));
920
		errexit(112, _("Cannot authenticate connection: %s\n"), strnwerror(err));
925
	}
921
	}
926
#endif
922
#endif
927
923
928
	err = NWSetBroadcastMode(conn,info.bcastmode); /*ignore error for now */
924
	err = NWSetBroadcastMode(conn,info.bcastmode); /*ignore error for now */
929
	NWDSFreeContext(ctx); /*free at last no more ifndef NCPMOUNT below */
930
925
931
	if ((err = ncp_mount_specific(conn, -1, info.NWpath, info.pathlen)) != 0)
926
	if ((err = ncp_mount_specific(conn, -1, info.NWpath, info.pathlen)) != 0)
932
	{
927
	{
933
		ncp_close(conn);
928
		ncp_close(conn);
934
		umount(mount_point);
929
		proc_ncpm_umount(mount_point);
930
		NWDSFreeContext(ctx);
935
		errexit(57, _("Cannot access path \"%s\": %s\n"), info.remote_path, strerror(-err));
931
		errexit(57, _("Cannot access path \"%s\": %s\n"), info.remote_path, strerror(-err));
936
	}
932
	}
937
	NWCCCloseConn(conn);
933
	NWCCCloseConn(conn);
938
	/*ncpmap, ncplogin must write in /etc/mtab*/
934
	NWDSFreeContext(ctx);
935
	/* ncpmap, ncplogin must write in /etc/mtab */
939
	{
936
	{
940
		add_mnt_entry(mount_name, mount_point, info.flags);
937
		add_mnt_entry(mount_name, mount_point, info.flags);
941
	}
938
	}
939
	free(mount_name);
942
	if (info.echo_mnt_pnt) {
940
	if (info.echo_mnt_pnt) {
943
		printf(_("mounted on:%s\n"),mount_point);
941
		printf(_("mounted on:%s\n"),mount_point);
944
	}
942
	}
(-)1.15/sutil/ncpm_common.c (-9 / +100 lines)
Lines 219-226 Link Here
219
		return 1;
219
		return 1;
220
	} else if (pid == 0)
220
	} else if (pid == 0)
221
	{
221
	{
222
		char *myenv[] = {
223
			"PATH=/sbin:/usr/sbin:/bin:/usr/bin",
224
			NULL
225
		};
222
		/* child */
226
		/* child */
223
		execl("/sbin/modprobe", "modprobe", "ncpfs", NULL);
227
		execle("/sbin/modprobe", "modprobe", "ncpfs", NULL, myenv);
224
		_exit(127);	/* execl error */
228
		_exit(127);	/* execl error */
225
	} else
229
	} else
226
	{
230
	{
Lines 355-360 Link Here
355
359
356
#endif 
360
#endif 
357
361
362
static inline int ncpm_suser(void) {
363
	return setreuid(-1, 0);
364
}
365
366
static int ncpm_normal(void) {
367
	int e;
368
	int v;
369
370
	e = errno;
371
	v = setreuid(-1, myuid);
372
	errno = e;
373
	return v;
374
}
375
376
static int proc_ncpm_mount(const char* source, const char* target, const char* filesystem, unsigned long mountflags, const void* data) {
377
	int v;
378
	int e;
379
380
	if (ncpm_suser()) {
381
		return errno;
382
	}
383
	v = mount(source, target, filesystem, mountflags, data);
384
	if (ncpm_normal()) {
385
		/* We cannot handle this situation gracefully, so do what we can */
386
387
		e = errno;
388
		/* If mount suceeded, undo it */
389
		if (v) {
390
			umount(target);
391
		}
392
		errexit(88, _("Cannot relinquish superuser rights: %s\n"), strerror(e));
393
	}
394
	return v;
395
}
396
397
int proc_ncpm_umount(const char* target) {
398
	int v;
399
400
	if (ncpm_suser()) {
401
		return errno;
402
	}
403
	v = umount(target);
404
	if (ncpm_normal()) {
405
		errexit(89, _("Cannot relinquish superuser rights: %s\n"), strerror(errno));
406
	}
407
	return v;
408
}
409
358
#ifdef MOUNT2
410
#ifdef MOUNT2
359
static int ncp_mount_v2(const char* mount_name, unsigned long flags, const struct ncp_mount_data_independent* data) {
411
static int ncp_mount_v2(const char* mount_name, unsigned long flags, const struct ncp_mount_data_independent* data) {
360
	struct ncp_mount_data_v2 datav2;
412
	struct ncp_mount_data_v2 datav2;
Lines 392-398 Link Here
392
	}
444
	}
393
        datav2.file_mode   = data->file_mode;
445
        datav2.file_mode   = data->file_mode;
394
        datav2.dir_mode    = data->dir_mode;
446
        datav2.dir_mode    = data->dir_mode;
395
	err = mount(mount_name, data->mount_point, "ncpfs", flags, (void*) &datav2);
447
	err = proc_ncpm_mount(mount_name, data->mount_point, "ncpfs", flags, (void*) &datav2);
396
	if (err)
448
	if (err)
397
		return errno;
449
		return errno;
398
	return 0;
450
	return 0;
Lines 456-462 Link Here
456
		exit(0);	/* Should not return from process_connection */
508
		exit(0);	/* Should not return from process_connection */
457
	}
509
	}
458
	close(pp[0]);
510
	close(pp[0]);
459
	err=mount(mount_name, data->mount_point, "ncpfs", flags, (void*) &datav3);
511
	err=proc_ncpm_mount(mount_name, data->mount_point, "ncpfs", flags, (void*) &datav3);
460
	if (err) {
512
	if (err) {
461
		err = errno;
513
		err = errno;
462
		/* Mount unsuccesful so we have to kill daemon */
514
		/* Mount unsuccesful so we have to kill daemon */
Lines 507-513 Link Here
507
		sprintf(mountopts, "version=%u,flags=%u,owner=%u,uid=%u,gid=%u,mode=%u,dirmode=%u,timeout=%u,retry=%u,wdogpid=%u,ncpfd=%u,infofd=%u",
559
		sprintf(mountopts, "version=%u,flags=%u,owner=%u,uid=%u,gid=%u,mode=%u,dirmode=%u,timeout=%u,retry=%u,wdogpid=%u,ncpfd=%u,infofd=%u",
508
			NCP_MOUNT_VERSION_V5, ncpflags, data->mounted_uid, data->uid, data->gid, data->file_mode,
560
			NCP_MOUNT_VERSION_V5, ncpflags, data->mounted_uid, data->uid, data->gid, data->file_mode,
509
			data->dir_mode, data->time_out, data->retry_count, wdog_pid, data->ncp_fd, pp[1]);
561
			data->dir_mode, data->time_out, data->retry_count, wdog_pid, data->ncp_fd, pp[1]);
510
		err=mount(mount_name, data->mount_point, "ncpfs", flags, mountopts);
562
		err=proc_ncpm_mount(mount_name, data->mount_point, "ncpfs", flags, mountopts);
511
	} else {
563
	} else {
512
		err=-1;
564
		err=-1;
513
	}
565
	}
Lines 525-531 Link Here
525
	        datav4.file_mode   = data->file_mode;
577
	        datav4.file_mode   = data->file_mode;
526
        	datav4.dir_mode    = data->dir_mode;
578
        	datav4.dir_mode    = data->dir_mode;
527
		datav4.wdog_pid	   = wdog_pid;
579
		datav4.wdog_pid	   = wdog_pid;
528
		err = mount(mount_name, data->mount_point, "ncpfs", flags, (void*)&datav4);
580
		err = proc_ncpm_mount(mount_name, data->mount_point, "ncpfs", flags, (void*)&datav4);
529
		if (err) {
581
		if (err) {
530
			err = errno;
582
			err = errno;
531
			/* Mount unsuccesful so we have to kill daemon */
583
			/* Mount unsuccesful so we have to kill daemon */
Lines 546-554 Link Here
546
void init_mount_info(struct ncp_mount_info *info) {
598
void init_mount_info(struct ncp_mount_info *info) {
547
	mode_t um;
599
	mode_t um;
548
600
549
	memset(info, 0, sizeof(*info));
550
551
	myuid = getuid();
601
	myuid = getuid();
602
	myeuid = geteuid();
603
604
	if (myeuid == 0) {
605
		if (setreuid(-1, myuid)) {
606
			errexit(87, _("Cannot relinquish superuser rights: %s\n"), strerror(errno));
607
		}
608
	}
609
610
	memset(info, 0, sizeof(*info));
552
611
553
	info->version = -1;
612
	info->version = -1;
554
	info->flags = MS_MGC_VAL;
613
	info->flags = MS_MGC_VAL;
Lines 649-655 Link Here
649
			sr.name_space = NW_NS_DOS;
708
			sr.name_space = NW_NS_DOS;
650
			sr.dirEntNum = DVAL_LH(&dirinfo.Directory.dirEntNum, 0);
709
			sr.dirEntNum = DVAL_LH(&dirinfo.Directory.dirEntNum, 0);
651
		}
710
		}
711
		if (ncpm_suser()) {
712
			return -errno;
713
		}
652
		result = ioctl(ncp_get_fid(conn), NCP_IOC_SETROOT, &sr);
714
		result = ioctl(ncp_get_fid(conn), NCP_IOC_SETROOT, &sr);
715
		if (ncpm_normal()) {
716
			/* Just continue, otherwise we cannot unmount directory */
717
			return result ? -errno : -EPERM;
718
		}
653
		if (!result) {
719
		if (!result) {
654
			return 0;
720
			return 0;
655
		}
721
		}
Lines 665-671 Link Here
665
#endif
731
#endif
666
		return -ENOPKG;
732
		return -ENOPKG;
667
	}
733
	}
668
	if (ioctl(ncp_get_fid(conn), NCP_IOC_CONN_LOGGED_IN, NULL) != 0) {
734
	if (ncpm_suser()) {
735
		return -errno;
736
	}
737
	result = ioctl(ncp_get_fid(conn), NCP_IOC_CONN_LOGGED_IN, NULL);
738
	if (ncpm_normal()) {
739
		/* Just continue, otherwise we cannot umount directory */
740
		return result ? -errno : -EPERM;
741
	}
742
	if (result != 0) {
669
		return -errno;
743
		return -errno;
670
	}
744
	}
671
	return 0;
745
	return 0;
Lines 798-808 Link Here
798
			return;
872
			return;
799
	}
873
	}
800
	{
874
	{
801
		char xxx[1024];
875
		char xxx[1024]; /* "cmd=XXXXXXXXXXX, len=XXXXXXXXX, data:" + 3x300 chars */
802
		char* p;
876
		char* p;
803
877
804
		sprintf(xxx, "cmd=%u, len=%u, data:", cmd, datalen);
878
		sprintf(xxx, "cmd=%u, len=%u, data:", cmd, datalen);
805
		p = xxx + strlen(xxx);
879
		p = xxx + strlen(xxx);
880
		if (datalen > 300) {
881
			datalen = 300;
882
		}
806
		while (datalen--) {
883
		while (datalen--) {
807
			sprintf(p, " %02X", *data++);
884
			sprintf(p, " %02X", *data++);
808
			p += 3;
885
			p += 3;
Lines 1358-1363 Link Here
1358
	}
1435
	}
1359
	*p = 0;
1436
	*p = 0;
1360
1437
1438
	if (ncpm_suser()) {
1439
		errexit(91, _("Cannot switch to superuser: %s\n"), strerror(errno));
1440
	}
1361
	if ((fd = open(MOUNTED "~", O_RDWR | O_CREAT | O_EXCL, 0600)) == -1)
1441
	if ((fd = open(MOUNTED "~", O_RDWR | O_CREAT | O_EXCL, 0600)) == -1)
1362
	{
1442
	{
1363
		errexit(58, _("Can't get %s~ lock file\n"), MOUNTED);
1443
		errexit(58, _("Can't get %s~ lock file\n"), MOUNTED);
Lines 1382-1387 Link Here
1382
	{
1462
	{
1383
		errexit(62, _("Can't remove %s~\n"), MOUNTED);
1463
		errexit(62, _("Can't remove %s~\n"), MOUNTED);
1384
	}
1464
	}
1465
	if (ncpm_normal()) {
1466
		errexit(90, _("Cannot relinquish superuser rights: %s\n"), strerror(EPERM));
1467
	}
1385
}
1468
}
1386
1469
1387
static int __proc_option(const struct optinfo* opts, struct ncp_mount_info* info, const char* opt, const char* param) {
1470
static int __proc_option(const struct optinfo* opts, struct ncp_mount_info* info, const char* opt, const char* param) {
Lines 1635-1640 Link Here
1635
	if ((info->nls_cs.codepage[0] != 0) || (info->nls_cs.iocharset[0] != 0)) {
1718
	if ((info->nls_cs.codepage[0] != 0) || (info->nls_cs.iocharset[0] != 0)) {
1636
		int i;
1719
		int i;
1637
		
1720
		
1721
		if (ncpm_suser()) {
1722
			fprintf(stderr, _("Cannot switch to superuser: %s\n"), strerror(errno));
1723
			return 90;
1724
		}
1638
		i = ioctl(ncp_get_fid(conn), NCP_IOC_SETCHARSETS,  &info->nls_cs);
1725
		i = ioctl(ncp_get_fid(conn), NCP_IOC_SETCHARSETS,  &info->nls_cs);
1639
		if (i && (errno == EINVAL)) {
1726
		if (i && (errno == EINVAL)) {
1640
			struct ncp_nls_ioctl_old old_nls;
1727
			struct ncp_nls_ioctl_old old_nls;
Lines 1645-1650 Link Here
1645
			old_nls.codepage = strtoul(p, NULL, 0);
1732
			old_nls.codepage = strtoul(p, NULL, 0);
1646
			strcpy(old_nls.iocharset, info->nls_cs.iocharset);
1733
			strcpy(old_nls.iocharset, info->nls_cs.iocharset);
1647
			i = ioctl(ncp_get_fid(conn), NCP_IOC_SETCHARSETS_OLD, &old_nls);
1734
			i = ioctl(ncp_get_fid(conn), NCP_IOC_SETCHARSETS_OLD, &old_nls);
1735
		}
1736
		if (ncpm_normal()) {
1737
			fprintf(stderr, _("Cannot relinquish superuser rights: %s\n"), strerror(-errno));
1738
			return 91;
1648
		}
1739
		}
1649
		if (i) {
1740
		if (i) {
1650
			if (errno == EINVAL || errno == ENOTTY) {
1741
			if (errno == EINVAL || errno == ENOTTY) {
(-)1.10/sutil/ncpm_common.h (+2 lines)
Lines 16-21 Link Here
16
#include "ncpmount.h"       
16
#include "ncpmount.h"       
17
17
18
uid_t myuid;
18
uid_t myuid;
19
uid_t myeuid;
19
char *progname;
20
char *progname;
20
char mount_point[MAXPATHLEN + 1];
21
char mount_point[MAXPATHLEN + 1];
21
22
Lines 118-123 Link Here
118
void proc_option(const struct optinfo* opts, struct ncp_mount_info* info, const char* opt, const char* param);
119
void proc_option(const struct optinfo* opts, struct ncp_mount_info* info, const char* opt, const char* param);
119
int proc_buildconn(struct ncp_mount_info* info);
120
int proc_buildconn(struct ncp_mount_info* info);
120
int proc_aftermount(const struct ncp_mount_info* info, NWCONN_HANDLE* conn);
121
int proc_aftermount(const struct ncp_mount_info* info, NWCONN_HANDLE* conn);
122
int proc_ncpm_umount(const char* dir);
121
123
122
#define UNUSED(x)	x __attribute__((unused))
124
#define UNUSED(x)	x __attribute__((unused))
123
125
(-)1.68/sutil/ncpmount.c (-9 / +23 lines)
Lines 171-177 Link Here
171
{
171
{
172
	struct ncp_mount_info info;
172
	struct ncp_mount_info info;
173
	struct stat st;
173
	struct stat st;
174
	char mount_name[256];
174
	char *mount_name;
175
#ifdef NDS_SUPPORT
175
#ifdef NDS_SUPPORT
176
	NWDSContextHandle ctx;
176
	NWDSContextHandle ctx;
177
	NWCONN_HANDLE auth_conn;
177
	NWCONN_HANDLE auth_conn;
Lines 350-356 Link Here
350
	if (info.server && info.tree) {
350
	if (info.server && info.tree) {
351
		errexit(66, _("Both tree and server name were specified. It is not allowed.\n"));
351
		errexit(66, _("Both tree and server name were specified. It is not allowed.\n"));
352
	}
352
	}
353
	if (geteuid() != 0)
353
	if (myeuid != 0)
354
	{
354
	{
355
		errexit(26, _("%s must be installed suid root\n"), progname);
355
		errexit(26, _("%s must be installed suid root\n"), progname);
356
	}
356
	}
Lines 594-606 Link Here
594
594
595
	info.mdata.mount_point = mount_point;
595
	info.mdata.mount_point = mount_point;
596
596
597
	strcpy(mount_name, spec.server);
597
	if (asprintf(&mount_name, "%s/%s", spec.server, spec.user) < 0) {
598
	strcat(mount_name, "/");
598
		NWDSFreeContext(ctx);
599
	strcat(mount_name, spec.user);
599
		if (auth_conn) {
600
			NWCCCloseConn(auth_conn);
601
		}
602
		errexit(85, _("Cannot allocate memory for mtab entry: %s\n"), strerror(ENOMEM));
603
	}
600
604
601
	result = ncp_mount(mount_name, &info);
605
	result = ncp_mount(mount_name, &info);
602
	if (result)
606
	if (result)
603
	{
607
	{
608
		free(mount_name);
604
		NWDSFreeContext(ctx);
609
		NWDSFreeContext(ctx);
605
		if (auth_conn) {
610
		if (auth_conn) {
606
			NWCCCloseConn(auth_conn);
611
			NWCCCloseConn(auth_conn);
Lines 610-616 Link Here
610
	}
615
	}
611
	err = proc_aftermount(&info, &conn);
616
	err = proc_aftermount(&info, &conn);
612
	if (err) {
617
	if (err) {
613
		umount(info.mdata.mount_point);
618
		proc_ncpm_umount(info.mdata.mount_point);
619
		free(mount_name);
614
		NWDSFreeContext(ctx);
620
		NWDSFreeContext(ctx);
615
		if (auth_conn) {
621
		if (auth_conn) {
616
			NWCCCloseConn(auth_conn);
622
			NWCCCloseConn(auth_conn);
Lines 621-626 Link Here
621
	if (info.auth_src != NULL) {
627
	if (info.auth_src != NULL) {
622
		err = NWDSAuthenticateConn(ctx, conn);
628
		err = NWDSAuthenticateConn(ctx, conn);
623
		if (err) {
629
		if (err) {
630
			proc_ncpm_umount(info.mdata.mount_point);
631
			free(mount_name);
624
			NWDSFreeContext(ctx);
632
			NWDSFreeContext(ctx);
625
			if (auth_conn) {
633
			if (auth_conn) {
626
				NWCCCloseConn(auth_conn);
634
				NWCCCloseConn(auth_conn);
Lines 636-642 Link Here
636
				mycom_err(err, _("in nds login"));
644
				mycom_err(err, _("in nds login"));
637
				fprintf(stderr, _("Login denied.\n"));
645
				fprintf(stderr, _("Login denied.\n"));
638
				ncp_close(conn);
646
				ncp_close(conn);
639
				umount(mount_point);
647
				proc_ncpm_umount(mount_point);
648
				free(mount_name);
640
				NWDSFreeContext(ctx);
649
				NWDSFreeContext(ctx);
641
				if (auth_conn) {
650
				if (auth_conn) {
642
					NWCCCloseConn(auth_conn);
651
					NWCCCloseConn(auth_conn);
Lines 660-666 Link Here
660
			mycom_err(err, _("in login"));
669
			mycom_err(err, _("in login"));
661
			fprintf(stderr, _("Login denied\n"));
670
			fprintf(stderr, _("Login denied\n"));
662
			ncp_close(conn);
671
			ncp_close(conn);
663
			umount(mount_point);
672
			proc_ncpm_umount(mount_point);
673
			free(mount_name);
664
			NWDSFreeContext(ctx);
674
			NWDSFreeContext(ctx);
665
			if (auth_conn) {
675
			if (auth_conn) {
666
				NWCCCloseConn(auth_conn);
676
				NWCCCloseConn(auth_conn);
Lines 682-687 Link Here
682
#endif
692
#endif
683
	err = NWDSFreeContext(ctx);
693
	err = NWDSFreeContext(ctx);
684
	if (err) {
694
	if (err) {
695
		ncp_close(conn);
696
		proc_ncpm_umount(mount_point);
697
		free(mount_name);
685
		if (auth_conn) {
698
		if (auth_conn) {
686
			NWCCCloseConn(auth_conn);
699
			NWCCCloseConn(auth_conn);
687
		}
700
		}
Lines 694-700 Link Here
694
	if ((err = ncp_mount_specific(conn, -1, info.NWpath, info.pathlen)) != 0) 
707
	if ((err = ncp_mount_specific(conn, -1, info.NWpath, info.pathlen)) != 0) 
695
	{
708
	{
696
		ncp_close(conn);
709
		ncp_close(conn);
697
		umount(mount_point);
710
		proc_ncpm_umount(mount_point);
711
		free(mount_name);
698
		errexit(57, _("Cannot access path \"%s\": %s\n"), info.remote_path, strerror(-err));
712
		errexit(57, _("Cannot access path \"%s\": %s\n"), info.remote_path, strerror(-err));
699
	}
713
	}
700
	ncp_close(conn);
714
	ncp_close(conn);

Return to bug 77414