@@ -73,7 +73,7 @@ func parseNetRC(path string) *netrc.Netrc {
7373}
7474
7575// Mount do the mounting
76- func (c CifsDriver ) Mount (r volume.MountRequest ) volume.Response {
76+ func (c CifsDriver ) Mount (r * volume.MountRequest ) ( * volume.MountResponse , error ) {
7777 c .m .Lock ()
7878 defer c .m .Unlock ()
7979 hostdir := mountpoint (c .root , r .Name )
@@ -98,34 +98,34 @@ func (c CifsDriver) Mount(r volume.MountRequest) volume.Response {
9898 if err := run (fmt .Sprintf ("mountpoint -q %s" , hostdir )); err != nil {
9999 log .Infof ("Existing CIFS volume not mounted, force remount." )
100100 } else {
101- return volume.Response {Mountpoint : hostdir }
101+ return & volume.MountResponse {Mountpoint : hostdir }, nil
102102 }
103103 }
104104
105105 log .Infof ("Mounting CIFS volume %s on %s" , source , hostdir )
106106
107107 if err := createDest (hostdir ); err != nil {
108- return volume. Response { Err : err . Error ()}
108+ return nil , err
109109 }
110110
111111 if err := c .mountVolume (r .Name , source , hostdir , c .getCreds (host )); err != nil {
112- return volume. Response { Err : err . Error ()}
112+ return nil , err
113113 }
114114 c .mountm .Add (r .Name , hostdir )
115115
116116 if c .mountm .GetOption (resolvedName , ShareOpt ) != "" && c .mountm .GetOptionAsBool (resolvedName , CreateOpt ) {
117117 log .Infof ("Mount: Share and Create options enabled - using %s as sub-dir mount" , resolvedName )
118118 datavol := filepath .Join (hostdir , resolvedName )
119119 if err := createDest (filepath .Join (hostdir , resolvedName )); err != nil {
120- return volume. Response { Err : err . Error ()}
120+ return nil , err
121121 }
122122 hostdir = datavol
123123 }
124- return volume.Response {Mountpoint : hostdir }
124+ return & volume.MountResponse {Mountpoint : hostdir }, nil
125125}
126126
127127// Unmount do the unmounting
128- func (c CifsDriver ) Unmount (r volume.UnmountRequest ) volume. Response {
128+ func (c CifsDriver ) Unmount (r * volume.UnmountRequest ) error {
129129 c .m .Lock ()
130130 defer c .m .Unlock ()
131131 hostdir := mountpoint (c .root , r .Name )
@@ -135,15 +135,15 @@ func (c CifsDriver) Unmount(r volume.UnmountRequest) volume.Response {
135135 if c .mountm .Count (r .Name ) > 1 {
136136 log .Infof ("Skipping unmount for %s - in use by other containers" , r .Name )
137137 c .mountm .Decrement (r .Name )
138- return volume. Response {}
138+ return nil
139139 }
140140 c .mountm .Decrement (r .Name )
141141 }
142142
143143 log .Infof ("Unmounting volume %s from %s" , source , hostdir )
144144
145145 if err := run (fmt .Sprintf ("umount %s" , hostdir )); err != nil {
146- return volume. Response { Err : err . Error ()}
146+ return err
147147 }
148148
149149 c .mountm .DeleteIfNotManaged (r .Name )
@@ -157,7 +157,7 @@ func (c CifsDriver) Unmount(r volume.UnmountRequest) volume.Response {
157157 // return volume.Response{Err: err.Error()}
158158 // }
159159
160- return volume. Response {}
160+ return nil
161161}
162162
163163func (c CifsDriver ) fixSource (name string ) string {
@@ -217,9 +217,10 @@ func (c CifsDriver) mountVolume(name, source, dest string, creds *CifsCreds) err
217217 }
218218
219219 if user != "" {
220- opts .WriteString (fmt .Sprintf ("username=%s," , user ))
220+ // escape single quotes in password character as it will be quoted in command line
221+ opts .WriteString (fmt .Sprintf ("username='%s'," , strings .Replace (user , "'" , "\\ '" , - 1 )))
221222 if pass != "" {
222- opts .WriteString (fmt .Sprintf ("password=%s ," , pass ))
223+ opts .WriteString (fmt .Sprintf ("password='%s' ," , strings . Replace ( pass , "'" , " \\ '" , - 1 ) ))
223224 }
224225 } else {
225226 opts .WriteString ("guest," )
@@ -245,7 +246,7 @@ func (c CifsDriver) mountVolume(name, source, dest string, creds *CifsCreds) err
245246
246247 opts .WriteString (fmt .Sprintf ("%s %s" , source , dest ))
247248 cmd := fmt .Sprintf ("mount -t cifs -o %s" , opts .String ())
248- log .Debugf ("Executing: %s\n " , strings .Replace (cmd , "password=" + pass , "password=****" , 1 ))
249+ log .Debugf ("Executing: %s\n " , strings .Replace (cmd , "password=' " + pass + "'" , "password=' ****' " , 1 ))
249250 return run (cmd )
250251}
251252
0 commit comments