Ignore:
Timestamp:
Oct 18, 2002, 1:02:37 AM (16 years ago)
Author:
eric
Message:

Add functionality to create users and groups.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/base/src/port1.0/portutil.tcl

    r1047 r1085  
    11571157    }
    11581158}
     1159
     1160proc adduser {name args} {
     1161    global os.platform
     1162    set passwd {\*}
     1163    set uid [nextuid]
     1164    set gid [nextgid]
     1165    set realname ${name}
     1166    set home /dev/null
     1167    set shell /dev/null
     1168
     1169    foreach arg $args {
     1170        if {[regexp {([a-z]*)=(.*)} $arg match key val]} {
     1171            regsub -all " " ${val} "\\ " val
     1172            set $key $val
     1173        }
     1174    }
     1175
     1176    if {[existsuser ${name}] != 0 || [existsuser ${uid}] != 0} {
     1177        return
     1178    }
     1179
     1180    if {${os.platform} == "darwin"} {
     1181        system "niutil -create . /users/${name}"
     1182        system "niutil -createprop . /users/${name} name ${name}"
     1183        system "niutil -createprop . /users/${name} passwd ${passwd}"
     1184        system "niutil -createprop . /users/${name} uid ${uid}"
     1185        system "niutil -createprop . /users/${name} gid ${gid}"
     1186        system "niutil -createprop . /users/${name} realname ${realname}"
     1187        system "niutil -createprop . /users/${name} home ${home}"
     1188        system "niutil -createprop . /users/${name} shell ${shell}"
     1189    } else {
     1190        # XXX adduser is only available for darwin, add more support here
     1191        ui_warning "WARNING: adduser is not implemented on ${os.platform}."
     1192        ui_warning "The requested user was not created."
     1193    }
     1194}
     1195
     1196proc addgroup {name args} {
     1197    global os.platform
     1198    set gid [nextgid]
     1199    set passwd {\*}
     1200    set users ""
     1201
     1202    foreach arg $args {
     1203        if {[regexp {([a-z]*)=(.*)} $arg match key val]} {
     1204            regsub -all " " ${val} "\\ " val
     1205            set $key $val
     1206        }
     1207    }
     1208
     1209    if {[existsgroup ${name}] != 0 || [existsgroup ${gid}] != 0} {
     1210        return
     1211    }
     1212
     1213    if {${os.platform} == "darwin"} {
     1214        system "niutil -create . /groups/${name}"
     1215        system "niutil -createprop . /groups/${name} name ${name}"
     1216        system "niutil -createprop . /groups/${name} gid ${gid}"
     1217        system "niutil -createprop . /groups/${name} passwd ${passwd}"
     1218        system "niutil -createprop . /groups/${name} users ${users}"
     1219    } else {
     1220        # XXX addgroup is only available for darwin, add more support here
     1221        ui_warning "WARNING: addgroup is not implemented on ${os.platform}."
     1222        ui_warning "The requested group was not created."
     1223    }
     1224}
Note: See TracChangeset for help on using the changeset viewer.